Skip to content

Instantly share code, notes, and snippets.

@jpentland
Last active July 11, 2024 04:36
Show Gist options
  • Select an option

  • Save jpentland/468a42c172eb607bb950f5d00606312c to your computer and use it in GitHub Desktop.

Select an option

Save jpentland/468a42c172eb607bb950f5d00606312c to your computer and use it in GitHub Desktop.

Revisions

  1. jpentland revised this gist Jan 24, 2020. 1 changed file with 1 addition and 1 deletion.
    2 changes: 1 addition & 1 deletion tabc.sh
    Original file line number Diff line number Diff line change
    @@ -1,7 +1,7 @@
    #!/bin/sh

    # Usage:
    # tab-desktop <tabbed-id> <command>
    # tabc.sh <tabbed-id> <command>
    # Commands:
    # add <window-id> - Add window to tabbed
    # remove <window-id> - Remove window from tabbed
  2. jpentland created this gist Jan 24, 2020.
    54 changes: 54 additions & 0 deletions tabc.sh
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,54 @@
    #!/bin/sh

    # Usage:
    # tab-desktop <tabbed-id> <command>
    # Commands:
    # add <window-id> - Add window to tabbed
    # remove <window-id> - Remove window from tabbed
    # list - 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
    xprop -id $id | sed -n '/WM_CLASS/s/.*, "\(.*\)"/\1/p'
    }

    #
    # Main Program
    #

    tabbed=$1; shift
    if [ "$(get_class $tabbed)" != "tabbed" ]; then
    echo "Not an instance of tabbed" 2>&1
    fi

    cmd=$1; shift

    case $cmd in
    add)
    wid=$1; shift
    xdotool windowreparent $wid $tabbed
    ;;
    remove)
    wid=$1; shift
    xdotool windowreparent $wid $(get_root_wid)
    ;;
    list)
    get_clients $tabbed
    ;;
    esac