Skip to content

Instantly share code, notes, and snippets.

@tasinet
Last active February 8, 2018 16:26
Show Gist options
  • Save tasinet/f29ea941769692bd4cb133efcdce9447 to your computer and use it in GitHub Desktop.
Save tasinet/f29ea941769692bd4cb133efcdce9447 to your computer and use it in GitHub Desktop.
switch i3 workspace only if current workspace is empty
#!/bin/bash
set -e
new_workspace=$1
if [ "" == "$new_workspace" ]; then
echo expecting workspace name/number
exit 1
fi
active_workspace=$( i3-msg -t get_workspaces | jq '.[] | select(.focused).num' )
echo active $active_workspace
toplevel_containers=$( i3-msg -t get_tree | jq '(.nodes[].nodes[].nodes[] | select(.type=="workspace") | select(.num=='"$active_workspace"') | .nodes | length) // 0' )
echo windows $toplevel_containers
if [ "$toplevel_containers" -eq "0" ]; then
i3-msg workspace $new_workspace
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment