TL;DR Download: [nexttermwin.sh] [prevtermwin.sh] script ,set custom global hotkey (e.g. F9,F10 )
Now, pressing F10 and F9 should cycle forward and backwards all terminals windows without popup.
But even then title substring cant help us and if we have multiple terminal windows open of same directory, we cannot navigate to specific window in it.
ALT+~ can help us here but requires specific application to be selected. Same goes for other applications with multiple windows open.
ALT+ESC does the job for this and cycles through next windows+instantly navigates to target window without a popup, but it draws a distracting rectangle arround the windows and requires holding these keys pressed until target window reached.
ALT+TAB lets you immediately switch to previous window and switch back which is useful feature. But yet it shows you a popup and requires you to browse through all window popup and select target window.
So, for a more faster and focused window switching we can use xdotool. It can focus any and every window of any desktop by window id provided by window manager of desktop environment. The key here in this script is xdotool gets current window id. wmctrl gets all window ids calculates next window id and activates window:
curWinDec=`xdotool getactivewindow`
curWinId=`printf 0x0%x "$curWinDec"`
pcName=`hostname`
echo "Current window Id: $curWinId"
echo "Getting a list of all terminal windows..."
echo "Assuming shell windows titles would contain ~ and /"
winIds=`wmctrl -lp|grep -v " $pcName Desktop"|grep "~\|/\|VIM"|grep -v " - Google Chrome"|grep -v " - Mozilla Firefox"|cut -d' ' -f 1`
echo "Window list: $winIds"
winCount=`wmctrl -lp|grep -v " $pcName Desktop"|grep "~\|/\|VIM"|grep -v " - Google Chrome"|grep -v " - Mozilla Firefox"|cut -d' ' -f 1|wc -l`
echo "Window count: $winCount"
readarray -t <<<$winIds
for i in {0..100};do if [ "${MAPFILE[$i]}" = "$curWinId" ]; then abc="$i" && break;fi;done
((abc=abc+1))
if [ "$winCount" = "$abc" ]; then echo "Cycling to first window..." && abc=0;fi
echo "Next window index: $abc"
echo "Navigating to... ${MAPFILE[$abc]}"
xdotool windowactivate ${MAPFILE[$abc]}
Cycling backwards:
curWinDec=`xdotool getactivewindow`
curWinId=`printf 0x0%x "$curWinDec"`
echo "Current window Id: $curWinId"
echo "Getting a list of all terminal windows..."
echo "Assuming shell windows titles would contain ~ and /"
winIds=`wmctrl -lp|grep -v " $pcName Desktop"|grep "~\|/\|VIM"|grep -v " - Google Chrome"|grep -v " - Mozilla Firefox"|cut -d' ' -f 1`
echo "Window list: $winIds"
winCount=`echo $winIds|tr -cd ' \t' | wc -c`
((winCount=winCount+1))
echo "Window count: $winCount"
readarray -t <<<$winIds
for i in {0..100};do if [ "${MAPFILE[$i]}" = "$curWinId" ]; then abc="$i" && break;fi;done
((abc=abc-1))
lastWindow="$winCount"
((lastWindow=lastWindow-1))
if [ "-1" = "$abc" ]; then echo "Cycling to last window..." && abc="$lastWindow";fi
echo "Prev window index: $abc"
echo "Navigating to... ${MAPFILE[$abc]}"
xdotool windowactivate ${MAPFILE[$abc]}
Cycling through all Windows:
[nexwin.sh] [prevwin.sh]
For navigating through all windows winIds
need to be:
Mapping custom global hotkeys to specific script from linux terminal:
#install xbindkeys if not installed
sudo apt install xbindkeys -y
#generate default configs
xbindkeys --defaults > ~/.xbindkeysrc
#set F10 key for script ~/nexttermwin.sh
echo '"bash ~/nexttermwin.sh"' >> ~/.xbindkeysrc
echo ' F10' >> ~/.xbindkeysrc
echo ' ' >> ~/.xbindkeysrc
#set F9 key for script ~/nexttermwin.sh
echo '"bash ~/nexttermwin.sh"' >> ~/.xbindkeysrc
echo ' F9' >> ~/.xbindkeysrc
#reload key configs...
killall -HUP xbindkeys
Now, pressing F10 and F9 should call ~/nexttermwin.sh and ~/prevtermwin.sh and cycle window forward and backwards.
No comments:
Post a Comment