94 lines
1.4 KiB
Bash
Executable file
94 lines
1.4 KiB
Bash
Executable file
#!/bin/sh
|
|
|
|
## sort windows by herds/flock ##
|
|
# wms_shepperd.sh by @root_informatica.
|
|
|
|
. /tmp/wms_var
|
|
|
|
FLAG=$1
|
|
# focused window.
|
|
FW=$(pfw)
|
|
|
|
usage() {
|
|
cat<<EOF
|
|
usage:
|
|
wms_shepperd.sh [ -a, -A, -d, -D, -t ]
|
|
-a) add
|
|
-A) add all
|
|
-d) delete
|
|
-D) delete all
|
|
-t) togle
|
|
EOF
|
|
}
|
|
|
|
# create atom in focused window
|
|
add_focused() {
|
|
# chose herd name.
|
|
h_name="$($XM < $NM)"
|
|
if [ -n "$h_name" ]; then
|
|
atomx WM_HERD="$h_name $FW" $FW
|
|
else
|
|
exit 0
|
|
fi
|
|
}
|
|
|
|
# create atom in all maped windows
|
|
add_all() {
|
|
# chose herd name.
|
|
h_name="$($XM < $NM)"
|
|
for wid in $AMW; do
|
|
if [ -n "$h_name" ]; then
|
|
atomx WM_HERD="$h_name $wid" $wid
|
|
else
|
|
exit 0
|
|
fi
|
|
done
|
|
}
|
|
|
|
# delete atom from focused window
|
|
del_focused() {
|
|
atomx -d WM_HERD $FW
|
|
}
|
|
|
|
del_all() {
|
|
atomx -d WM_HERD $AMW
|
|
}
|
|
|
|
# togle groups
|
|
togle() {
|
|
# herds.
|
|
herds=$(atomx WM_HERD $(lsw -a) | cut -d ' ' -f1 | sort -u)
|
|
# check if any herd exist.
|
|
if [ -n "$herds" ]; then
|
|
# select herd target.
|
|
h_target=$(printf "$herds" | $XM)
|
|
# windwos to map.
|
|
wind_to_map=$(atomx WM_HERD $(lsw -u) | grep $h_target | cut -d ' ' -f2)
|
|
# windows to unmap.
|
|
wind_to_unmap=$(atomx WM_HERD $(lsw) | grep -v $h_target | cut -d ' ' -f2)
|
|
# do it.
|
|
mapw -m $wind_to_map & mapw -u $wind_to_unmap
|
|
fi
|
|
}
|
|
|
|
case $FLAG in
|
|
-a)
|
|
add_focused
|
|
;;
|
|
-A)
|
|
add_all
|
|
;;
|
|
-d)
|
|
del_focused
|
|
;;
|
|
-D)
|
|
del_all
|
|
;;
|
|
-t)
|
|
togle
|
|
;;
|
|
*)
|
|
usage # self-explained
|
|
;;
|
|
esac
|
|
|