diff options
author | Urbain Vaes <urbain@vaes.uk> | 2016-01-05 00:19:22 +0000 |
---|---|---|
committer | Urbain Vaes <urbain@vaes.uk> | 2016-01-05 00:19:22 +0000 |
commit | 3645a24c53159ddced6d390ed754766e7e7887da (patch) | |
tree | e59cd9ad45b4a53be1d8c1b22cbae11976ec4a39 | |
parent | c7d8141ba1e62b3bfeba8a43c220cce8332a72a2 (diff) |
[i3] Clean workspace script
-rw-r--r-- | .i3/config | 40 | ||||
-rwxr-xr-x | bin/workspace | 25 |
2 files changed, 37 insertions, 28 deletions
@@ -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 |