suckless-utils/scripts/tabb

73 lines
1.9 KiB
Bash
Executable file

#!/bin/bash
# tabb for tabbed by Alexis.
main() {
tabbed_id=$(tabbed -d -c)
while true; do
if [[ ! $(pgrep -x "tabbed") ]]; then
echo "No Tabbed process found. Exiting..."
exit 1
fi
if [[ $(pgrep -x "tabbed" | wc -l) -gt 1 ]]; then
tabbed_id=$(xdotool search --class "tabbed" | tail -n 1)
fi
deskid=$(xdotool get_desktop)
window=$(wmctrl -x -l | grep -E " $deskid " | grep -v $(printf '0x0%x' "$tabbed_id") | grep -v 'tabbed' | cut -d ' ' -f 1,4)
IFS=':'
for win in $(printf '%s' "$window" | tr '\n' ':'); do
unset IFS
wid=$(printf '%s' "$win" | cut -d ' ' -f 1)
wname=$(printf '%s' "$win" | cut -d ' ' -f 2)
if [ "$wname" = "(has no name)" ]; then
cwid=$(xwininfo -children -id "$wid" | grep '^ 0x' | sed -e 's@^ *\\(0x[0-9a-f]*\\) "\\([^"]*\\)".*@\\1@')
for id in $(printf '%s' "$cwid"); do
xdotool windowreparent "$id" "$tabbed_id"
done
else
xdotool windowreparent "$wid" "$tabbed_id"
fi
done
if [[ $automode = "false" ]]; then
break
# exit
fi
done
}
helpfunct(){
echo "tabb - Handler script for suckless tabbed"
echo ""
echo "by Alexis Jhon Gaspar (lucss21a) (c) 2023-2024"
echo ""
echo "Options:"
echo ""
echo "-e: Turn on auto-reparenting on all windows (default)"
echo "-d: Turn on auto-reprenting only on existing windows"
echo "-h: Show this message"
}
while getopts "edh" opt; do
case $opt in
e )
automode=true
main
;;
d )
automode=false
main
;;
h )
helpfunct
;;
esac
done
if [ $OPTIND -eq 1 ]; then
shift $((OPTIND-1))
echo "No arguments passed, turning auto-reparenting on ALL windows..."
automode=true
main
fi