1
0
mirror of https://github.com/balkian/dotfiles.git synced 2024-11-24 21:22:29 +00:00
dotfiles/bin/dmenu.sh
J.Fernando Sánchez d8f23e0276 Removed personal-scripts submodule
To make my life a bit easier
2013-06-20 17:54:47 +02:00

28 lines
775 B
Bash
Executable File

#!/bin/sh
#http://unix.stackexchange.com/questions/50539/inconsistent-behaviour-of-wmctrl-i-a-win
# source dmenu config file if it exists
if [ -f $HOME/.dmenurc ]; then
. $HOME/.dmenurc
else
DMENU='dmenu -i'
fi
# get list of all windows, and their count
wmctrl_output=$(wmctrl -lx)
win_count=$(echo "$wmctrl_output" | wc -l)
# get rid of the hostname and the number in the 2nd column
hostname=$(uname -n)
win_list=$(echo "$wmctrl_output" | \
sed -r -e 's/[^@]'$hostname'//' | \
sed -r -e 's/ [0-9][0-9]? / /')
# select a window ($target) and extract its id ($target_id)
target=$(echo "$win_list" | $DMENU -l $win_count -p "Switch to: ")
target_id=$(echo "$target" | cut -d' ' -f1)
# switch to target window
cmd="wmctrl -i -a \"$target_id\""
eval "$cmd"