forked from xbot/shell
-
Notifications
You must be signed in to change notification settings - Fork 0
/
wm.sh
executable file
·47 lines (42 loc) · 1.39 KB
/
wm.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#!/bin/bash
# A wrapper of wmctrl which handles common window-manager's tasks.
# Author: Donie Leigh <donie.leigh@gmail.com>
current_desktop=`wmctrl -d|grep '*'|awk '{ print $1 }'`
desktop_amount=`wmctrl -d|wc -l`
next_desktop=$(((current_desktop+1)%desktop_amount))
prev_desktop=$(((current_desktop-1+desktop_amount)%desktop_amount))
tmp_title=current_window_`date +"%s"`
wm_help()
{
cat <<"HELP"
Format: wm.sh [ARG [VAL]]
Actions:
-h: Print this message.
-q: Close the current window.
-s <L_R>: Switch to the left or right desktop.
-t <L_R>: Move the current window to the left or right desktop and then switch to it.
Arguments:
<L_R>: left or right.
HELP
}
if [ $# -eq 0 ]; then wm_help; fi
while getopts 'hqs:t:' opt; do
case $opt in
q)
wmctrl -c :ACTIVE:
;;
s)
if [ "$OPTARG" = "left" ]; then wmctrl -s $prev_desktop;
elif [ "$OPTARG" = "right" ]; then wmctrl -s $next_desktop;
else wm_help; fi
;;
t)
if [ "$OPTARG" = "left" ]; then wmctrl -r :ACTIVE: -N $tmp_title;wmctrl -r :ACTIVE: -t $prev_desktop;wmctrl -a $tmp_title;
elif [ "$OPTARG" = "right" ]; then wmctrl -r :ACTIVE: -N $tmp_title;wmctrl -r :ACTIVE: -t $next_desktop;wmctrl -a $tmp_title;
else wm_help; fi
;;
*)
wm_help
;;
esac
done