summaryrefslogtreecommitdiff
path: root/bin/workspace
blob: a66e0b5ddf04a0d87ae56dd04210e09e33892cd9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
#!/bin/zsh

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
    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
fi

[[ $1 = 'n' ]] && cmd="workspace" || cmd="move container to workspace"
exec i3-msg $cmd $target