summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--.i3/config40
-rwxr-xr-xbin/workspace25
2 files changed, 37 insertions, 28 deletions
diff --git a/.i3/config b/.i3/config
index b150b4a..2a75b68 100644
--- a/.i3/config
+++ b/.i3/config
@@ -85,28 +85,28 @@ bindsym $mod+Shift+minus move scratchpad
bindsym $mod+minus scratchpad show
# switch to workspace
-bindsym $mod+ampersand exec workspace n 1
-bindsym $mod+bracketleft exec workspace n 2
-bindsym $mod+braceleft exec workspace n 3
-bindsym $mod+braceright exec workspace n 4
-bindsym $mod+parenleft exec workspace n 5
-bindsym $mod+equal exec workspace n 6
-bindsym $mod+asterisk exec workspace n 7
-bindsym $mod+parenright exec workspace n 8
-bindsym $mod+plus exec workspace n 9
-bindsym $mod+bracketright exec workspace n 10
+bindsym $mod+ampersand workspace number 1
+bindsym $mod+bracketleft workspace number 2
+bindsym $mod+braceleft workspace number 3
+bindsym $mod+braceright workspace number 4
+bindsym $mod+parenleft workspace number 5
+bindsym $mod+equal workspace number 6
+bindsym $mod+asterisk workspace number 7
+bindsym $mod+parenright workspace number 8
+bindsym $mod+plus workspace number 9
+bindsym $mod+bracketright workspace number 10
# move focused container to workspace
-bindsym $mod+Shift+ampersand exec workspace m 1
-bindsym $mod+Shift+bracketleft exec workspace m 2
-bindsym $mod+Shift+braceleft exec workspace m 3
-bindsym $mod+Shift+braceright exec workspace m 4
-bindsym $mod+Shift+1 exec workspace m 5
-bindsym $mod+Shift+equal exec workspace m 6
-bindsym $mod+Shift+asterisk exec workspace m 7
-bindsym $mod+Shift+2 exec workspace m 8
-bindsym $mod+Shift+plus exec workspace m 9
-bindsym $mod+Shift+bracketright exec workspace m 10
+bindsym $mod+Shift+ampersand move container to workspace number 1
+bindsym $mod+Shift+bracketleft move container to workspace number 2
+bindsym $mod+Shift+braceleft move container to workspace number 3
+bindsym $mod+Shift+braceright move container to workspace number 4
+bindsym $mod+Shift+1 move container to workspace number 5
+bindsym $mod+Shift+equal move container to workspace number 6
+bindsym $mod+Shift+asterisk move container to workspace number 7
+bindsym $mod+Shift+2 move container to workspace number 8
+bindsym $mod+Shift+plus move container to workspace number 9
+bindsym $mod+Shift+bracketright move container to workspace number 10
# Keybindings for create and move
bindsym $mod+n exec workspace n
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