Skip to content

Instantly share code, notes, and snippets.

@ffwff
Last active March 5, 2020 22:06
Show Gist options
  • Save ffwff/190d0758005812589c9e1770134425fd to your computer and use it in GitHub Desktop.
Save ffwff/190d0758005812589c9e1770134425fd to your computer and use it in GitHub Desktop.
Changes layout of current i3 workspace
#!/bin/bash
if [[ "$1" = "fourbox" ]]; then
(i3-save-tree |sed -e's/^\s*\/\/\s[^\"].*//g' -e's/^\s*\/\///g' | \
jq '..|objects|select(.type=="con")|select(has("nodes")|not)'| \
jq -s '{layout:"splith","type":"con",nodes:[{"layout":"splitv",nodes:[.[0],.[1]]},{"layout":"splitv",nodes:[.[2],.[3]]}]}') > /tmp/layout
else
(i3-save-tree |sed -e's/^\s*\/\/\s[^\"].*//g' -e's/^\s*\/\///g' | \
jq '..|objects|select(.type=="con")|select(has("nodes")|not)'| \
jq -s '{layout:"'$1'","type":"con",nodes:.}') > /tmp/layout
fi
windows="$(wmctrl -l|awk '{ if ($2 == "'$(wmctrl -d | awk '{ if ($2 == "'*'") print $1 }')'") print $1}')"
i3-msg append_layout /tmp/layout
for window in $windows; do
xdotool windowunmap $window
xdotool windowmap $window
done
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment