i3 Window Manager
Move to the next / previous workspace
This Bash script allows you to move the focused window to the next or previous i3 workspace. This is very useful, as it allows you to get a tiled window off the current workspace whilst moving to the desired workspace at the same time. It really is quite handy.
In your i3 configuration file, put the following two lines:
- bindsym $super+period exec ~/scripts/i3/window.sh
- bindsym $super+comma exec ~/scripts/i3/window.sh back
#!/bin/bash
move=1
max=7
next_max=-1
if [ "$1" == 'back' ]
then
move=-1
max=0
next_max=8
fi
OLD_IFS="$IFS"
IFS=$'\n' win_array=($(i3-msg -t get_config | grep 'set $workspace' | sed 's/^.\+ .\+\(".\+\)$/\1/'))
IFS="$OLD_IFS"
win_length=${#win_array[@]}
#echo $win_array
#echo $win_length
wsCurrent=$( i3-msg -t get_workspaces | jq '.[] | select(.focused).name' )
#echo $wsCurrent
for i in "${!win_array[@]}"; do
if [[ "${win_array[$i]}" = "${wsCurrent}" ]]; then
myWin=${i};
fi
done
#echo $myWin
if [ $myWin -eq $max ]
then
myWin=$next_max
fi
newWin_index=$(($myWin + $move))
newWin=${win_array[$newWin_index]}
i3-msg move container workspace $newWin, workspace $newWin
exit 0