From: tgaz <44317335+tgaz@users.noreply.github.com> Date: Sat, 20 Oct 2018 11:39:56 +0000 (+0100) Subject: Fix swapping workspaces script colon issue X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=fdef3b8c2be922a6f53614888a37e42328d5194d;p=i3%2Fi3.github.io Fix swapping workspaces script colon issue From https://www.reddit.com/r/i3wm/comments/9o218m/found_a_bug_in_swapping_workspaces/e7rtorl/ Using `read -a` means a workspace name with a colon breaks (because colon is used as separator in `jq`). A cleaner way is to use `read` into separate variables, which will write the entire tail in the last variable. Also simplifies the if-statement with a `grep` invocation. --- diff --git a/docs/user-contributed/swapping-workspaces.html b/docs/user-contributed/swapping-workspaces.html index 75747f9..e91fd7c 100644 --- a/docs/user-contributed/swapping-workspaces.html +++ b/docs/user-contributed/swapping-workspaces.html @@ -23,17 +23,12 @@ workspace to the other monitor.
#!/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 "${CONFIG[1]}"
-        i3-msg move workspace to output right	
-    fi
+IFS=:
+i3-msg -t get_outputs | jq -r '.[]|"\(.name):\(.current_workspace)"' | grep -v '^null:null$' | \
+while read -r name current_workspace; do
+    echo "moving ${current_workspace} right..."
+    i3-msg workspace "${current_workspace}"
+    i3-msg move workspace to output right   
 done