]> git.lizzy.rs Git - bspwm.git/blob - contrib/zsh_completion
Add setting: ignore_ewmh_fullscreen
[bspwm.git] / contrib / zsh_completion
1 #compdef bspc
2
3 _bspc_selector() {
4         [[ ${@[(r)--]} = '--' ]] && shift ${@[(i)--]}
5         local -a completions=() completions_display=()
6         local index=0 name id sel_type="$1"
7         shift 1
8         case $sel_type in
9                 (node) compset -P '*[#.:/@]' ;;
10                 (desktop) compset -P '*[#.:]' ;;
11                 (monitor) compset -P '*[#.]' ;;
12                 (*) return 1 ;;
13         esac
14         case "$sel_type $IPREFIX" in
15                 (desktop*:)
16                         local ipfx=${${IPREFIX##*@}%:}
17                         while do
18                                 if completions=("${(@f)$(bspc query --names -D -m ${ipfx} 2> /dev/null)}") ;then
19                                         until ((++index > $#completions)) do
20                                                 completions[index]="^${index}:${completions[index]}"
21                                         done
22                                         completions+='focused'
23                                         _describe "${sel_type} selector" completions $@ -S '' -J ${sel_type}
24                                         break
25                                 else
26                                         completions=()
27                                         [ -n "$ipfx[(r)#]" ] &&
28                                                 ipfx="${ipfx#*#}" ||
29                                                 break
30                                 fi
31                         done
32                         ;|
33                 (node*[^@/:.])
34                         bspc query -N -n .window 2> /dev/null |
35                                 while read id ;do
36                                         id=${id//:/\\:}
37                                         if which xdotool &> /dev/null ;then
38                                                 name=$(xdotool getwindowname $id 2> /dev/null)
39                                         elif which xprop &> /dev/null ;then
40                                                 name=$(xprop -id $id -notype WM_NAME 2> /dev/null) &&
41                                                         [[ "$name" = 'WM_NAME ='* ]] &&
42                                                         name="${${name#*\"}%\"*}" ||
43                                                         name=""
44                                         else
45                                                 name="install xdotool or xprop to see window titles here"
46                                         fi
47                                         completions+="$id:$name"
48                                 done
49                         ;|
50                 ((desktop|monitor)*[^:.])
51                         local max_name_len=0 max_index_len i
52                         local -a snames names ids
53                         bspc query -${(U)sel_type[1]} 2> /dev/null |
54                                 while read id ;do
55                                         ((index++))
56                                         name=$(bspc query --names -${(U)sel_type[1]} -${sel_type[1]} $id 2> /dev/null)
57                                         [[ "$name" == *[:.!]* ]] &&
58                                                 sel_name="%${name//:/\\:}" ||
59                                                 sel_name="$name"
60                                         ((max_name_len = $#sel_name > max_name_len ? $#sel_name : max_name_len))
61                                         ids+="${id}"
62                                         snames+="${sel_name}"
63                                         names+="${name}"
64                                 done
65                                 max_index_len=$(($#index + 1))
66                                 ((max_name_len >= max_name_len)) && ((max_name_len=max_name_len + 1))
67                                 for ((i = 1 ; i <= $#ids ; i++)) ;do
68                                         (($#ids[i] <= max_name_len)) &&
69                                                 completions_display+="${(r($max_name_len+1))ids[i]}:${names[i]}" ||
70                                                 completions_display+="${ids[i]}:${names[i]}"
71                                         completions+="${ids[i]}:${names[i]}"
72                                 done
73                                 for ((i = 1 ; i <= $#ids ; i++)) ;do
74                                         completions+="${snames[i]}:${names[i]}"
75                                         completions_display+="${(r($max_name_len))snames[i]}:${names[i]}"
76                                 done
77                                 for ((i = 1 ; i <= $#ids ; i++)) ;do
78                                         completions+="^${i}:${names[i]}"
79                                         completions_display+="^${i}:${names[i]}"
80                                 done
81                         ;|
82                 (node*('@'(*':'|*'/'|)))
83                         _describe 'node path' jump -S '/' -r "#. ${quote}" -J nodes
84                         ;|
85                 (node*'/')
86                         ;;
87                 (*'.')
88                         _bspc_prefix '!' "${sel_type} modifiers" ${sel_type}_mod $@ -J ${sel_type}_mod
89                         ;|
90                 ((desktop|monitor)*@)
91                         ;&
92                 (*[^:.@/])
93                         if (( $#completions_display)) ;then
94                         _describe "${sel_type} selector" ${sel_type}_desc $@ -S '.' -r ". \n:#${quote}\-" -J ${sel_type} \
95                                 -- completions_display completions $@ -S '.' -r ". \n:#${quote}\-" -J ${sel_type}
96                         else
97                         _describe "${sel_type} selector" ${sel_type}_desc $@ -S '.' -r ". \n:#${quote}\-" -J ${sel_type} \
98                                 -- completions $@ -S '.' -r ". \n:#${quote}\-" -J ${sel_type}
99                         fi
100                         ;|
101                 (node*@*)
102                         _bspc_selector desktop -S ':' -qr ".#\-\n ${quote}"
103                         ;;
104                 (desktop*)
105                         _bspc_selector monitor -S ':' -r ".#\-\n ${quote}"
106                         ;;
107         esac
108 }
109
110 _bspc_prefix(){
111         [[ ${@[(r)--]} = '--' ]] && shift ${@[(i)--]}
112         [[ "$PREFIX[1]" == "$1" ]] &&
113                 local a="-n" b ||
114                 local b="-n" a
115         _describe $@[2,-1] $a -- $@[3,-1] $b -p "$1"
116 }
117
118 _bspc_query_names() {
119         [[ ${@[(r)--]} = '--' ]] && shift ${@[(i)--]}
120         local -a items=("${(@f)$(bspc query $2 --names 2> /dev/null)}") ||
121                 return
122         local c
123         for c in '\' ':' '[' '(' '*'
124                 items=("${(@)items//$c/\\$c}")
125         _values -w  "$1" "${items[@]}"
126 }
127
128 _bspc() {
129         local -a commands=(node desktop monitor query rule wm subscribe config quit) \
130                 resize_handle=(top bottom top_left top_right bottom_left bottom_right left right) \
131                 node_state=(tiled pseudo_tiled floating fullscreen) \
132                 flag=(hidden sticky private locked marked urgent) \
133                 layer=(below normal above) \
134                 dir=(north west south east) \
135                 cycle_dir=(next prev)
136         local -a jump=($dir first second brother parent 1 2) \
137                 node_desc=($dir $cycle_dir any last newest older newer focused pointed biggest) \
138                 node_mod=($node_state $flag $layer focused automatic local \
139                 active leaf window same_class descendant_of ancestor_of) \
140                 desktop_desc=($cycle_dir any last newest older newer focused) \
141                 desktop_mod=(focused occupied local urgent) \
142                 monitor_desc=($dir $cycle_dir any last newest older newer focused pointed primary) \
143                 monitor_mod=(focused occupied) \
144                 presel_dir=($dir cancel)
145         local quote="${compstate[quote]}" context state state_descr line
146         typeset -A opt_args
147
148         compset -n 2
149         compset -S "${quote}"
150
151         if ((CURRENT==1)) ;then
152                 _describe 'command or domain' commands
153                 return
154         fi
155
156         case $words[1] in
157                 (node)
158                         ((CURRENT==2)) && _bspc_selector node
159                         ((CURRENT>2)) && [[ "$words[2]" != '-'* ]] && compset -n 2
160                         ((CURRENT>2)) && [[ "$words[CURRENT-2]" =~ "^-(m|d|n|s|-to-(monitor|desktop|node)|-swap)$" ]] &&
161                                 _values 'option' '--follow[If passed, the focused node will stay focused]'
162                         _arguments -C \
163                                 '*'{-a,--activate}'[Activate the selected or given node]::node selector:_bspc_selector -- node'\
164                                 '*'{-B,--balance}'[Adjust the split ratios of the tree rooted at the selected node so that all windows occupy the same area]'\
165                                 '*'{-C,--circulate}'[Circulate the windows of the tree rooted at the selected node]:direction:(forward backward)'\
166                                 '*'{-c,--close}'[Close the windows rooted at the selected node]'\
167                                 '*'{-d,--to-desktop}'[Send the selected node to the given desktop]:desktop selector:_bspc_selector -- desktop'\
168                                 '*'{-E,--equalize}'[Reset the split ratios of the tree rooted at the selected node to their default value]'\
169                                 '*'{-F,--flip}'[Flip the the tree rooted at selected node]: :(horizontal vertical)'\
170                                 '*'{-f,--focus}'[Focus the selected or given node]::node selector:_bspc_selector -- node'\
171                                 '*'{-g,--flag}'[Set or toggle the given flag for the selected node]: :-> flag'\
172                                 '*'{-i,--insert-receptacle}'[Insert a receptacle node at the selected node]'\
173                                 '*'{-k,--kill}'[Kill the windows rooted at the selected node]'\
174                                 '*'{-l,--layer}"[Set the stacking layer of the selected window]:stacking layer:($layer)"\
175                                 '*'{-m,--to-monitor}'[Send the selected node to the given monitor]:monitor selector:_bspc_selector -- monitor'\
176                                 '*'{-n,--to-node}'[Transplant the selected node to the given node]:node selector:_bspc_selector -- node'\
177                                 '*'{-o,--presel-ratio}'[Set the splitting ratio of the preselection area]:preselect ratio: ( )'\
178                                 '*'{-p,--presel-dir}'[Preselect the splitting area of the selected node or cancel the preselection]: :_bspc_prefix -- "~" preselect presel_dir'\
179                                 '*'{-r,--ratio}'[Set the splitting ratio of the selected node (0 < ratio < 1)]: :( )'\
180                                 '*'{-R,--rotate}'[Rotate the tree rooted at the selected node]:angle:(90 270 180)'\
181                                 '*'{-s,--swap}'[Swap the selected node with the given node]:node selector:_bspc_selector -- node'\
182                                 '*'{-t,--state}'[Set the state of the selected window]: :_bspc_prefix -- "~" "node state" node_state '\
183                                 '*'{-v,--move}'[Move the selected window by dx pixels horizontally and dy pixels vertically]:dx:( ):dy:( )'\
184                                 '*'{-z,--resize}"[Resize the selected window by moving the given handle by dx pixels horizontally and dy pixels vertically]:handle:($resize_handle):dx:( ):dy:( )"
185                         [ "$state" = flag ] && _values 'flag' "${flag[@]:#urgent}::set flag:(on off)"
186                         ;;
187                 (desktop)
188                         ((CURRENT==2)) && _bspc_selector desktop
189                         ((CURRENT>2)) && [[ "$words[2]" != '-'* ]] && compset -n 2
190                         ((CURRENT>2)) && [[ "$words[CURRENT-2]" =~ "^-m|-s|--monitor|--swap$" ]] &&
191                                 _values 'option' '--follow[If passed, the focused desktop will stay focused]'
192                         _arguments \
193                                 '*'{-a,--activate}'[Activate the selected or given desktop]:: :_bspc_selector -- desktop'\
194                                 '*'{-b,--bubble}"[Bubble the selected desktop in the given direction]:direction:($cycle_dir)"\
195                                 '*'{-f,--focus}'[Focus the selected or given desktop]:: :_bspc_selector -- desktop'\
196                                 '*'{-l,--layout}"[Set or cycle the layout of the selected desktop]:desktop layout:($cycle_dir monocle tiled)"\
197                                 '*'{-m,--to-monitor}'[Send the selected desktop to the given monitor]: :_bspc_selector -- monitor'\
198                                 '*'{-n,--rename}'[Rename the selected desktop]:desktop name:( )'\
199                                 '*'{-r,--remove}'[Remove the selected desktop]'\
200                                 '*'{-s,--swap}'[Swap the selected desktop with the given desktop]: :_bspc_selector -- desktop'
201                         ;;
202                 (monitor)
203                         ((CURRENT==2)) && _bspc_selector monitor
204                         ((CURRENT>2)) && [[ "$words[2]" != '-'* ]] && compset -n 2
205                         _arguments \
206                                 '*'{-a,--add-desktops}'[Create desktops with the given names in the selected monitor]:*:add desktops:( )'\
207                                 '*'{-d,--reset-desktops}'[Rename, add or remove desktops]:*: :->desktops'\
208                                 '*'{-f,--focus}'[Focus the selected or given monitor]:: :_bspc_selector -- monitor'\
209                                 '*'{-g,--rectangle}'[Set the rectangle of the selected monitor]:WxH+X+Y:( )'\
210                                 '*'{-n,--rename}'[Rename the selected monitor]: :( )'\
211                                 '*'{-o,--reorder-desktops}'[Reorder the desktops of the selected monitor]:*:reorder desktops:_bspc_query_names -- desktops -D'\
212                                 '*'{-r,--remove}'[Remove the selected monitor]'\
213                                 '*'{-s,--swap}'[Swap the selected monitor with the given monitor]: :_bspc_selector -- monitor'
214                         ;;
215                 (query)
216                         local -a cmds_no_names=('-T' '--tree' '-N' '--nodes')
217                         local -a cmds=($cmds_no_names '-D' '--desktops' '-M' '--monitors')
218                         _arguments \
219                                 '*'{-d,--desktop}'[Constrain matches to the selected desktop]: :_bspc_selector -- desktop'\
220                                 '*'{-m,--monitor}'[Constrain matches to the selected monitor]: :_bspc_selector -- monitor'\
221                                 '*'{-n,--node}'[Constrain matches to the selected node]: :_bspc_selector -- node'\
222                                 "($cmds_no_names --names)--names[Print names instead of IDs. Can only be used with -M and -D]"\
223                                 "($cmds --names)"{-N,--nodes}'[List the IDs of the matching nodes]'\
224                                 "($cmds --names)"{-T,--tree}'[Print a JSON representation of the matching item]'\
225                                 "($cmds)"{-D,--desktops}'[List the IDs (or names) of the matching desktops]'\
226                                 "($cmds)"{-M,--monitors}'[List the IDs (or names) of the matching monitors]'
227                         ;;
228                 (wm)
229                         _arguments \
230                                 '*'{-d,--dump-state}'[Dump the current world state on standard output]'\
231                                 '*'{-l,--load-state}'[Load a world state from the given file]:load state from file:_files'\
232                                 '*'{-a,--add-monitor}'[Add a monitor for the given name and rectangle]:add monitor:( )'\
233                                 '*'{-O,--reorder-monitors}'[Reorder the list of monitors to match the given order]:*: :_bspc_query_names -- monitors -M'\
234                                 '*'{-o,--adopt-orphans}'[Manage all the unmanaged windows remaining from a previous session]'\
235                                 '*'{-h,--record-history}'[Enable or disable the recording of node focus history]:history:(on off)'\
236                                 '*'{-g,--get-status}'[Print the current status information]'
237                         ;;
238                 (subscribe)
239                         if [[ "$words[CURRENT-1]" != (-c|--count) ]] ;then
240                                 _values -w "options" \
241                                         '(-f --fifo)'{-f,--fifo}'[Print a path to a FIFO from which events can be read and return]'\
242                                         '(-c --count)'{-c,--count}'[Stop the corresponding bspc process after having received specified count of events]'
243                                 _values -w -S "_" events all report pointer_action \
244                                         "monitor:: :(add rename remove swap focus geometry)"\
245                                         "desktop:: :(add rename remove swap transfer focus activate layout)"\
246                                         "node:: :(add remove swap transfer focus activate presel stack geometry state flag layer)"
247                         fi
248                         ;;
249                 (rule)
250                         local -a completions by_index
251                         local index=0 target settings class id instance json
252                         _arguments -C \
253                                 {-a,--add}'[Create a new rule]:*: :->add'\
254                                 {-r,--remove}'[Remove the given rules]:*: :->remove'\
255                                 '(-l --list)'{-l,--list}'[List the rules]'
256                         compset -N "-([ar]|-add|-remove)"
257                         case $state$CURRENT in
258                                 (add1)
259                                         compset -P '*:'
260                                         bspc query -N -n '.window' 2> /dev/null |
261                                                 while read id ; do
262                                                         json=$(bspc query -T -n $id 2>/dev/null) || continue
263                                                         [[ "$json[1]" = '{' ]] || continue
264                                                         class=${${json##*\"className\":\"}%%\",\"*}
265                                                         instance=${${json##*\"instanceName\":\"}%%\",\"*}
266                                                         [[ "$class[1]" != '{' && "$instance[1]" != '{'  ]] || continue
267                                                         if [ -n "$IPREFIX" ] ;then
268                                                                 [[ "$IPREFIX" == ("${class}:"|('\'|)'*:') ]] &&
269                                                                         completions[(r)$instance]=$instance
270                                                         else
271                                                                 class=${class%%:/\\:}
272                                                                 completions[(r)$class]="$class"
273                                                         fi
274                                                 done
275                                         ;;
276                                 (add*)
277                                         _values -w 'add rule' {border,focus,follow,manage,center}': :(on off)'\
278                                                 '(--one-shot)-o'\
279                                                 '(-o)--one-shot'\
280                                                 'monitor: :_bspc_selector -- monitor'\
281                                                 'desktop: :_bspc_selector -- desktop'\
282                                                 'node: :_bspc_selector -- node'\
283                                                 'rectangle: :( )'\
284                                                 'split_ratio:split ratio:( )'\
285                                                 "split_dir:split direction:(${dir})"\
286                                                 "state:state:(${node_state})"\
287                                                 "${flag[@]:#urgent}:set flag:(on off)"\
288                                                 "layer:layer:(${layer})"
289                                         return
290                                         ;;
291                                 (remove*)
292                                         compset -P '*:'
293                                         bspc rule -l 2> /dev/null |
294                                                 while IFS=" " read target settings ;do
295                                                         by_index+="^$((index++)):${target} ${settings}"
296                                                         if [ -n "$IPREFIX" ] ;then
297                                                                 completions+="${target#*:}"
298                                                         else
299                                                                 completions+="${target%:*}"
300                                                         fi
301                                                 done
302                                         [[ -z "$IPREFIX" ]] &&
303                                                 _describe 'remove rule by position' '(head tail)' -J by_index -- by_index -J by_index
304                                         ;;
305                                 (*)
306                                         return
307                                         ;;
308                         esac
309                         completions[(r)\*]=*
310                         [ -n "$IPREFIX" ] &&
311                                 _describe 'match window instance' completions ||
312                                 _describe 'match window class' completions -q -S ':'
313                         ;;
314                 (config)
315                         local -a look behaviour input
316                         # Boolean settings are identified by index!
317                         look=(borderless_monocle gapless_monocle {normal,active,focused}_border_color {top,right,bottom,left}_padding presel_feedback_color border_width window_gap)
318                         behaviour=(single_monocle mapping_events_count ignore_ewmh_focus ignore_ewmh_fullscreen center_pseudo_tiled honor_size_hints remove_disabled_monitors remove_unplugged_monitors merge_overlapping_monitors status_prefix external_rules_command split_ratio initial_polarity directional_focus_tightness status_prefix)
319                         input=({swallow_first_click,focus_follows_pointer,pointer_follows_{focus,monitor}} click_to_focus pointer_motion_interval pointer_modifier pointer_action{1,2,3} )
320                         if [[ "$CURRENT" == (2|3) ]];then
321                                 _arguments \
322                                         '-d[Set settings for the selected desktop]: :_bspc_selector -- desktop'\
323                                         '-m[Set settings for the selected monitor]: :_bspc_selector -- monitor'\
324                                         '-n[Set settings for the selected node]: :_bspc_selector -- node'
325                         fi
326                         if [[ "${words[2]}" == -* ]] ;then
327                                 (( CURRENT == 3 )) && return
328                                 if (( CURRENT > 3 )) ;then
329                                         ((CURRENT-=$#words))
330                                         words=('config' "${(@)words[4,-1]}")
331                                         ((CURRENT+=$#words))
332                                 fi
333                         fi
334                         if ((CURRENT==2)) ;then
335                                 _describe 'look' look -J look
336                                 _describe 'input' input -J input
337                                 _describe 'behaviour' behaviour -J behaviour
338                         elif ((CURRENT==3)) ;then
339                                 setting=$words[2]
340                                 case $setting in
341                                         (initial_polarity)
342                                                 _values "set $setting" first_child second_child
343                                                 ;;
344                                         (pointer_action(1|2|3))
345                                                 _values "set $setting" move resize_side resize_corner focus none
346                                                 ;;
347                                         (pointer_modifier)
348                                                 _values "set $setting" shift control lock mod1 mod2 mod3 mod4 mod5
349                                                 ;;
350                                         (directional_focus_tightness)
351                                                 _values "set $setting" low high
352                                                 ;;
353                                         (click_to_focus)
354                                                 _values "set $setting" any button1 button2 button3 none
355                                                 ;;
356                                         (*)
357                                                 ((look[(i)$setting] <= 2)) ||
358                                                         ((behaviour[(i)$setting] <= 7)) ||
359                                                         ((input[(i)$setting] <= 4)) &&
360                                                         _values "set $setting" true false
361                                                 ;;
362                                 esac
363                         fi
364                         ;;
365         esac
366 }
367
368 _bspc "$@"