-
-
Save BrodieRobertson/dd7e3d793a501066c50086ed795c0357 to your computer and use it in GitHub Desktop.
| #!/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 |
Hey Brodie,
I watched your video on adding tabbed to bspwm and I was following your gist but I found some errors in your current gist. I had to refer back to the gist that was in the video which seemed accurate.
I think the following line is supposed to be at line 58 which is under the remove block,
if [ -z $(tabc list $tabbedid) ]; then xdotool windowkill $tabbedid fi
I found that a variable is misspelled, xdotool windowreparent $wid $tabbed is supposed to be xdotool windowreparent $wid $tabbedid
Adding a focused window to west/east or left/right is not working is due to the target window not being a instance of tabbed.
Some hints:
- There's no need to sleep after calling
tabbed, callingtabbed -dwill return the wid of the created window (also I believexdos-mparameter causes it to wait until there's a window that matches). Nonetheless I don't get what you need$tabbedidfor, because you never use it?! - Using the syntax
name() {offers way better compability with older shells thanfunction name {. Especially because you specified/bin/shas interpreter, your script may not run in other people's environments. - Quoting variables prevents globbing and word splitting. I recommend
shellcheckfor linting your scripts :)
Instead of
tabbed &; sleep 0.1; tabbedid=$(xdotool search --class tabbed | tail -n1), you can just dotabbed &; tabbedid=$!($!is the process ID of the last run process)
You can actually just change tabbed to tabbed -c in the add cmd, which is a builtin param for tabbed that auto closes when the last tab is closed.
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.
Here is a solution to retrieve the window id without using sleep. Hope it helps: plmi/dotfiles@71d1fd5#diff-126a1e1993e27b2e10ae75f52c689bcacc01f9dc135d345f4f910975126e43d1
@BrodieRobertson i would love to have the scirpt working again! Can you please help?
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
I was just looking for (almost)this, clicked the top ddg result, HUGE fan of your stuff
too bad it require the use of bspwm as I never really used that one, I'm still on awesome and loving it to the point of being unable to move to Wayland (there are other reasons too, like no x over ssh stuff which is something I actually find quite useful at times)
Thank you that seems like exactly what I was looking for
Edit: I just tested this and it works assuming that the window is already open it works but if it hasn't it still puts more in a situation where I need to sleep until the window has opened.
Edit Edit: Actually I think I was just doing something else wrong