summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorUrbain Vaes <urbain@vaes.uk>2017-09-07 12:28:43 +0100
committerUrbain Vaes <urbain@vaes.uk>2017-09-07 12:28:43 +0100
commit481bb2c26f2d9aa52e5c8dec8dfc64af7bbff049 (patch)
tree5824c61f0f242b0e8513cedc1397249881c400f4 /bin
parent68ecfa236f23620f5a3d453000fd6c19380d6567 (diff)
[i3] Add script to move workspace
Diffstat (limited to 'bin')
-rwxr-xr-xbin/bin/move_workspace21
1 files changed, 21 insertions, 0 deletions
diff --git a/bin/bin/move_workspace b/bin/bin/move_workspace
new file mode 100755
index 0000000..d7944de
--- /dev/null
+++ b/bin/bin/move_workspace
@@ -0,0 +1,21 @@
+#!/usr/bin/env bash
+
+wkspces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g')
+focused=$(i3-msg -t get_workspaces | grep -Po '{[^}]*"focused":true[^}]*}' | sed 's/.*"name":"\([^"]*\)".*$/\1/g')
+
+focused_number=${focused%%:*}
+focused_name=${focused#*:}
+
+[[ $1 = 'n' ]] && new_number=$((focused_number + 1))
+[[ $1 = 'p' ]] && new_number=$((focused_number - 1))
+
+next=$(echo "${wkspces}" | grep "^${new_number}")
+
+i3-msg rename workspace to ${new_number}:${focused_name}
+
+if [[ ! -z "${next// }" ]]; then
+ name_next=${next#*:}
+ i3-msg workspace "${next}"
+ i3-msg rename workspace to ${focused_number}:${name_next}
+ i3-msg workspace "${new_number}:${focused_name}"
+fi