Last active
December 7, 2018 19:03
-
-
Save jairovsky/b727d80272f8bb9e159400f220f7bdb0 to your computer and use it in GitHub Desktop.
bash: focus window (with support for cycling through multiple windows of the same program)
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 | |
# copied without shame with a little adaptation from https://stackoverflow.com/a/33607859 | |
active_win_id=`xprop -root | grep '^_NET_ACTIVE_W' | awk -F'# 0x' '{print $2}' | awk -F', ' '{print $1}'` | |
if [ "$active_win_id" == "0" ]; then | |
active_win_id="" | |
fi | |
app_name=$1 | |
workspace_number=`wmctrl -d | grep '\*' | cut -d' ' -f 1` | |
win_list=`wmctrl -lx | grep -r "$app_name" - | grep " $workspace_number " - | awk '{print $1}'` | |
# get next window to focus on, removing id active | |
switch_to=`echo $win_list | sed s/.*$active_win_id// | awk '{print $1}'` | |
# if the current window is the last in the list ... take the first one | |
if [ "$switch_to" == "" ];then | |
switch_to=`echo $win_list | awk '{print $1}'` | |
fi | |
if [[ -n "${switch_to}" ]] | |
then | |
(wmctrl -ia "$switch_to") & | |
else | |
if [[ -n "$2" ]] | |
then | |
($2) & | |
fi | |
fi | |
exit 0 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
download it:
use it: