Skip to content

Instantly share code, notes, and snippets.

@BrodieRobertson
Forked from jpentland/tabc.sh
Last active August 14, 2022 23:40
Show Gist options
  • Save BrodieRobertson/dd7e3d793a501066c50086ed795c0357 to your computer and use it in GitHub Desktop.
Save BrodieRobertson/dd7e3d793a501066c50086ed795c0357 to your computer and use it in GitHub Desktop.
Add or remove windows from suckless' tabbed
#!/bin/sh
# Usage:
# tabc.sh <command>
# Commands:
# add <direction-of-tabbed> <window-id> - Add window to tabbed
# remove <window-id> - Remove window from tabbed
# list <tabbed-id> - List all clients of tabbed
#
# Functions
#
# Get wid of root window
function get_root_wid {
xwininfo -root | awk '/Window id:/{print $4}'
}
# Get children of tabbed
function get_clients {
id=$1
xwininfo -id $id -children | sed -n '/[0-9]\+ \(child\|children\):/,$s/ \+\(0x[0-9a-z]\+\).*/\1/p'
}
# Get class of a wid
function get_class {
id=$1
if [ -z $id ]; then
echo ""
else
xprop -id $id | sed -n '/WM_CLASS/s/.*, "\(.*\)"/\1/p'
fi
}
#
# Main Program
#
cmd=$1
if [ $cmd = "add" ]; then
tabbedid=$(bspc query -N -n $2)
if [ -z $tabbedid ]; then
tabbed &
sleep 0.1
tabbedid=$(xdotool search --class tabbed | tail -n1)
fi
fi
case $cmd in
add)
wid=$3
xdotool windowreparent $wid $tabbed
;;
remove)
wid=$2
tabbedid=$(bspc query -N -n focused)
xdotool windowreparent $wid $(get_root_wid)
;;
list)
tabbedid=$2
get_clients $tabbed
;;
esac
@ivanmilov
Copy link

Hello!
To get win id without sleep I use:

tabbedid=$(tabbed -c -d)

-d detaches tabbed from the terminal and prints its XID to stdout.

@plmi
Copy link

plmi commented Feb 12, 2022

Here is a solution to retrieve the window id without using sleep. Hope it helps: plmi/dotfiles@71d1fd5#diff-126a1e1993e27b2e10ae75f52c689bcacc01f9dc135d345f4f910975126e43d1

@etherbiswas
Copy link

@BrodieRobertson i would love to have the scirpt working again! Can you please help?

@etherbiswas
Copy link

etherbiswas commented Mar 20, 2022

very annoying error! i think it has someting to do with being posix compliant.

.config/bspwm/tabc.sh: 15: function: not found
0x6bf
.config/bspwm/tabc.sh: 17: Syntax error: "}" unexpected

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment