wms/wms_shepperd.sh
rootniformaticaservice 9f97d8985e more fixes.
2023-04-01 00:27:27 -03:00

84 lines
1.5 KiB
Bash
Executable file

#!/bin/sh
## sort windows by herds/flock ##
. $HOME/.config/wms/wms_var
NAMES="$HOME/.config/wms/wms_names" # disponible names
FLAG=$1 # input
FW=$(pfw) # focused window id
AMW=$(lsw) # all maped windows
usage() {
echo "usage:
wms_shepperd.sh [ -a, -r, -t ]
-a) add
-A) add all
-d) delete
-D) delete all
-t) togle"
}
# create atom in focused window
add_focused() {
name=$(printf "$($XMENU < $NAMES)")
if [ -n "$ name " ]; then
atomx WM_HERD="$ name $FW" $FW
else
exit 0
fi
}
# create atom in all maped windows
add_all() {
name=$(printf "$($XMENU < $NAMES)")
for wid in $AMW; do
if [ -n "$name" ]; then
atomx WM_HERD="$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=$(atomx WM_HERD $(lsw -a) | cut -d ' ' -f1 | sort -u) # herds
if [ -n "$herds" ]; then # check if any herd exist
h_target=$(printf "$herds" | $XMENU) # select herd target
wind_to_map=$(atomx WM_HERD $(lsw -u) | grep $h_target | cut -d ' ' -f2) # windows to map
wind_to_unmap=$(atomx WM_HERD $(lsw) | grep -v $h_target | cut -d ' ' -f2) # windows to unmap
mapw -m $wind_to_map & mapw -u $wind_to_unmap
fi
}
case $FLAG in
-a)
add_focused
;;
-A)
add_all
;;
-d)
del_focused
;;
-D)
dell_all
;;
-t)
togle
;;
*)
usage # self-explained
;;
esac