Last active
March 21, 2025 12:46
-
-
Save blueforesticarus/b3dcb22cf3f46fcee4db26cfc090be79 to your computer and use it in GitHub Desktop.
A script to run commands in floating window on ie.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/bin/bash | |
| # alt shebang to autoload deps | |
| #!/usr/bin/env nix | |
| #! nix shell --file ``<nixpkgs>`` bash wmctrl ripgrep pstree --command bash | |
| # This is a script to run programs as floating windows in i3 window manager. | |
| # The passed command is run and any X windows it creates are moved to a | |
| # floating split container. (or you can pass a custom i3 mark) | |
| # | |
| # Deps: | |
| # requires wmctrl pstree ripgrep | |
| # Usage: | |
| # float <command> | |
| # | |
| # ex) open two terminals in a split floating container | |
| # float 'alacritty & alacritty' | |
| # | |
| # ex) open windows in a named mark (creating if not found) | |
| # MARK=mygroup float <command> | |
| # for some reason xprop subprocess doesn't die on it's own | |
| trap 'pkill --signal SIGTERM --parent $$' EXIT | |
| MARK="${MARK:-$$}" | |
| FOUND= | |
| FIRST= | |
| # listen for focus change | |
| xprop -spy -root _NET_ACTIVE_WINDOW | while read DUMMY; do | |
| TREE1=$(pstree $$) | |
| TREE=$(echo "$TREE1" | rg -o '^[^\d]+0?(\d+)' -r "\$1") | |
| WINDOWS=$(wmctrl -lp | awk '{print $1, $3}') | |
| while read wid pid; do | |
| if [[ " $FOUND " =~ " $pid " ]]; then | |
| continue | |
| fi | |
| FOUND="$FOUND $pid" # only catch once | |
| if grep -qx "$pid"; then | |
| ps --no-headers $pid | |
| wmctrl -lp | grep $wid | |
| wmctrl -i -a "$wid" # if args in wrong order, silently does nothing (dumb) | |
| #sleep 0.2 | |
| i3-msg move window to mark $MARK || ( | |
| i3-msg mark $MARK | |
| i3-msg split horizontal | |
| i3-msg focus parent | |
| i3-msg floating enable | |
| ) | |
| fi < <(echo "$TREE") | |
| done < <(echo "$WINDOWS") | |
| #^ can't use pipe because then FOUND doesn't persist (subshell) | |
| done & | |
| ( | |
| bash -c "$@" | |
| wait | |
| ) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment