Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Swap i3 displays / workspaces between displays
#!/usr/bin/env bash
# requires jq
DISPLAY_CONFIG=($(i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"'))
for ROW in "${DISPLAY_CONFIG[@]}"
do
IFS=':'
read -ra CONFIG <<< "${ROW}"
if [ "${CONFIG[0]}" != "null" ] && [ "${CONFIG[1]}" != "null" ]; then
echo "moving ${CONFIG[1]} right..."
i3-msg -- workspace --no-auto-back-and-forth "${CONFIG[1]}"
i3-msg -- move workspace to output right
fi
done
@fbrinker

This comment has been minimized.

Copy link
Owner Author

fbrinker commented Apr 6, 2018

Dependencies

  • jq (if not already available)

Usage

To use this script, I recommend binding it to a keyboard shortcut in your i3 config:
bindsym $mod+Shift+s exec /home/fbrinker/i3-display-swap.sh

More than 2 outputs

The script rotates the workspaces technically to the right, so you may need another solution, depending on your configuration

@giuseppe-dandrea

This comment has been minimized.

Copy link

giuseppe-dandrea commented Oct 14, 2018

This script is not working if there is a space in the workspace name or back-and-forth is set to true in the config.
The second problem is simply solved changing line 12 in:
i3-msg workspace --no-auto-back-and-forth "${CONFIG[1]}"

@fbrinker

This comment has been minimized.

Copy link
Owner Author

fbrinker commented Dec 19, 2018

Ty, added --no-auto-back-and-forth :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.
You signed in with another tab or window. Reload to refresh your session. You signed out in another tab or window. Reload to refresh your session.