diff options
author | Urbain Vaes <urbain@vaes.uk> | 2015-12-17 01:02:28 +0000 |
---|---|---|
committer | Urbain Vaes <urbain@vaes.uk> | 2015-12-17 01:02:28 +0000 |
commit | dbd02c933b541559a9513d8cae24ff6f3f40c398 (patch) | |
tree | 1766a6c0811cc0de6a2dca9c850c421532149a21 /bin/workspace | |
parent | 9e9ff053904aec6303c025041cd469d05dd82dcf (diff) |
Improve workspace script
Diffstat (limited to 'bin/workspace')
-rwxr-xr-x | bin/workspace | 11 |
1 files changed, 9 insertions, 2 deletions
diff --git a/bin/workspace b/bin/workspace index 9082f39..f735014 100755 --- a/bin/workspace +++ b/bin/workspace @@ -1,5 +1,12 @@ #!/bin/zsh -workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([0-9a-zA-Z]\+\)"/\1/g') -target=$(echo $workspaces | dmenu -i -p "Go to workspace:") +workspaces=$(i3-msg -t get_workspaces | grep -Po '"name":.*?[^\\]"' | sed 's/"name":"\([^"]\+\)"/\1/g') +used_numbers=$(echo $workspaces | awk 'BEGIN { FS = ":" } ; { print $1 }') +max_number=$(echo $used_numbers | tail -1) +largest_gap=$(echo $used_numbers | awk '$1!=p+1{print p+1}{p=$1}') +[[ -z $largest_gap ]] && new_number=$(($max_number + 1)) || new_number=$largest_gap + +target=$(echo $workspaces | dmenu -i -sf green -p "Go to workspace:") +[[ ! $target = [0-9]:* ]] && target=$new_number:$target + exec i3-msg workspace $target |