Skip to content

Instantly share code, notes, and snippets.

@enisozgen
Last active April 5, 2016 11:08
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enisozgen/e743beb566e4e10294e0877536bfb5ef to your computer and use it in GitHub Desktop.
Save enisozgen/e743beb566e4e10294e0877536bfb5ef to your computer and use it in GitHub Desktop.
SwitchBetweenSpesificBuffers.sh
#!/bin/bash
# Copied from http://askubuntu.com/questions/269574/wmctrl-focus-most-recent-window-of-an-app
# Usage
# Download wmctrl by using apt-get or yum
# Bound shortcut that sh code from your environment
# If you press more than one it will change windows
app_name=APPNAME
workspace_number=`wmctrl -d | grep '\*' | cut -d' ' -f 1`
win_list=`wmctrl -lx | grep $app_name | grep " $workspace_number " | awk '{print $1}'`
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
# If you open new windows for you all new work that will help to you to start from last tab to see your app
# It is convenient while using Firefox
#If you want to start from beggining just comment that line
win_list=$(echo $win_list | awk 'BEGIN{FS="[ ]*"; OFS=" "} { for (i=NF; i>0; i--) { printf "%s", $i;11 ; if (i>1) { printf "%s", OFS; } } printf "\n" }')
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