summaryrefslogtreecommitdiff
path: root/bin
diff options
context:
space:
mode:
authorUrbain Vaes <urbain@vaes.uk>2016-01-05 00:19:22 +0000
committerUrbain Vaes <urbain@vaes.uk>2016-01-05 00:19:22 +0000
commit3645a24c53159ddced6d390ed754766e7e7887da (patch)
treee59cd9ad45b4a53be1d8c1b22cbae11976ec4a39 /bin
parentc7d8141ba1e62b3bfeba8a43c220cce8332a72a2 (diff)
[i3] Clean workspace script
Diffstat (limited to 'bin')
-rwxr-xr-xbin/workspace25
1 files changed, 17 insertions, 8 deletions
diff --git a/bin/workspace b/bin/workspace
index a66e0b5..02c2b6f 100755
--- a/bin/workspace
+++ b/bin/workspace
@@ -1,20 +1,29 @@
#!/bin/zsh
+# Command to use
+[[ $1 = 'n' ]] && cmd="workspace" || cmd="move container to workspace"
+
+# List of workspaces
workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g')
-if [[ ! -z $2 ]]; then
- target=$(echo $workspaces | grep "$2")
- [[ -z $target ]] && target=$2
-else
+# Get desired workspace
+target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:")
+
+# Exit if empty
+[[ -z $target ]] && exit
+
+# If new workspace has to be created
+if [[ ! $target = [0-9]* ]]; then
+
+ # Calculate number for new workspace
used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }')
max_number=$(echo $used_numbers | tail -1)
lowest_gap=$(echo $used_numbers | awk '$1!=p+1{print p+1}{p=$1}' | head -1)
[[ -z $lowest_gap ]] && new_number=$(($max_number + 1)) || new_number=$lowest_gap
- target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:")
- [[ -z $target ]] && exit
- [[ ! $target = [0-9]* ]] && target=$new_number:$target
+ # Add number to workspace name
+ target=$new_number:$target
fi
-[[ $1 = 'n' ]] && cmd="workspace" || cmd="move container to workspace"
+# Execute command
exec i3-msg $cmd $target