hyprctl: add shell completions

This commit is contained in:
Lennard Hofmann 2023-10-09 14:16:15 +02:00
parent 499df49f7b
commit e0b0070fcb
9 changed files with 648 additions and 0 deletions

1
.gitignore vendored
View file

@ -23,6 +23,7 @@ result*
*.so *.so
hyprctl/hyprctl hyprctl/hyprctl
completions/generated/*.usage
gmon.out gmon.out
*.out *.out

View file

@ -55,6 +55,10 @@ install:
mkdir -p ${PREFIX}/share/hyprland mkdir -p ${PREFIX}/share/hyprland
cp ./assets/wall_* ${PREFIX}/share/hyprland cp ./assets/wall_* ${PREFIX}/share/hyprland
install -m644 -D ./completions/generated/hyprctl.bash ${PREFIX}/share/bash-completion/completions/hyprctl
install -m644 -D ./completions/generated/hyprctl.fish ${PREFIX}/share/fish/vendor_completions.d/
install -m644 -D ./completions/generated/hyprctl.zsh ${PREFIX}/share/zsh/site-functions/_hyprctl
mkdir -p ${PREFIX}/share/man/man1 mkdir -p ${PREFIX}/share/man/man1
install -m644 ./docs/*.1 ${PREFIX}/share/man/man1 install -m644 ./docs/*.1 ${PREFIX}/share/man/man1
@ -84,6 +88,9 @@ uninstall:
rm -rf ${PREFIX}/share/hyprland rm -rf ${PREFIX}/share/hyprland
rm -f ${PREFIX}/share/man/man1/Hyprland.1 rm -f ${PREFIX}/share/man/man1/Hyprland.1
rm -f ${PREFIX}/share/man/man1/hyprctl.1 rm -f ${PREFIX}/share/man/man1/hyprctl.1
rm -f ${PREFIX}/share/bash-completion/completions/hyprctl
rm -f ${PREFIX}/share/fish/vendor_completions.d/hyprctl.fish
rm -f ${PREFIX}/share/zsh/site-functions/_hyprctl
fixwlr: fixwlr:
sed -E -i -e 's/(soversion = 12)([^032]|$$)/soversion = 12032/g' subprojects/wlroots/meson.build sed -E -i -e 's/(soversion = 12)([^032]|$$)/soversion = 12032/g' subprojects/wlroots/meson.build

View file

@ -0,0 +1,17 @@
#!/bin/sh
generate_grammar() {
cat hyprctl.usage
echo
printf '<CONFIG_OPTION> ::= '
sed -n 's/.*configValues\["\(.*\)"\].*/ | \1/p' ../src/config/ConfigManager.cpp |
sort | uniq | sed 's/\./\\./g' | tail -c +7
echo ';'
}
generate_grammar > generated/hyprctl.usage
cd generated || exit 1
complgen compile --bash-script hyprctl.bash hyprctl.usage
complgen compile --zsh-script hyprctl.zsh hyprctl.usage
complgen compile --fish-script hyprctl.fish hyprctl.usage

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

File diff suppressed because one or more lines are too long

138
completions/hyprctl.usage Normal file
View file

@ -0,0 +1,138 @@
# https://github.com/adaszko/complgen#syntax
hyprctl [<OPTION>]... <COMMAND>;
<OPTION> ::= -j "JSON output"
| (-i | --instance) "use specified Hyprland instance" <INSTANCE>
;
<COMMAND> ::= monitors "list all outputs with their properties"
| workspaces "list all workspaces with their properties"
| activeworkspace "show info about active workspace"
| clients "list all windows with their properties"
| activewindow "print active window name"
| layers "list all layers"
| devices "list all connected input devices"
| binds "list all keybindings"
| dispatch "run a dispatcher" <DISPATCHER>
| keyword "execute a keyword" <KEYWORD>
| version "print Hyprland version"
| kill "kill an app by clicking on it"
| splash "print current random splash"
| hyprpaper <PAPERCOMMAND>
| reload "reload config file"
| setcursor "set cursor theme" <CURSORTHEME>
| getoption "print value of config option" <CONFIG_OPTION>
| cursorpos "print cursor position"
| switchxkblayout "switch keyboard layout" <DEVICE> (next | prev)
| seterror "show text in error bar" disable
| setprop "set windowrule properties"
| plugin ((load | unload) <PATH> | list)
| notify "send notification" <ICON>
| globalshortcuts "list all global shortcuts"
| output "creates/destroys a fake output" (create (wayland | x11 | headless | auto) | remove <MONITOR>)
| animations "list animations and beziers"
| instances "list running Hyprland instances"
| --batch "execute multiple commands, separated by ';'"
;
# see KeybindManager.cpp
<DISPATCHER> ::= alterzorder (top | bottom)
| bringactivetotop
| centerwindow
| changegroupactive
| closewindow
| cyclenext
| dpms
| exec
| execr
| exit
| fakefullscreen
| focuscurrentorlast
| focusmonitor
| focusurgentorlast
| focuswindow
| focuswindowbyclass
| forcerendererreload
| fullscreen
| global
| killactive
| layoutmsg
| lockactivegroup
| lockgroups
| mfact
| mouse
| moveactive
| movecurrentworkspacetomonitor
| movecursor
| movecursortocorner
| movefocus
| moveintogroup
| moveoutofgroup
| movetoworkspace
| movetoworkspacesilent
| movewindow
| movewindoworgroup
| movewindowpixel
| moveworkspacetomonitor
| pass
| pin
| pseudo
| renameworkspace
| resizeactive
| resizewindowpixel
| splitratio
| submap
| swapactiveworkspaces
| swapnext
| swapwindow
| togglefloating
| togglegroup
| toggleopaque
| togglespecialworkspace
| togglesplit
| workspace
| workspaceopt
;
<ICON> ::= -1 "no icon"
| 0 "warning"
| 1 "info"
| 2 "hint"
| 3 "error"
| 4 "confused"
| 5 "ok"
;
<PAPERCOMMAND> ::= preload <PATH>
| unload (<PATH> | all)
| wallpaper
;
# See parseKeyword in ConfigManager.cpp
<KEYWORD> ::= monitor
| exec
| exec-once
| monitor
| bind
| unbind
| workspace
| windowrule
| windowrulev2
| layerrule
| bezier
| animation
| source <PATH>
| submap
| blurls
| wsbind
| env
| plugin
;
<DEVICE> ::= {{{ hyprctl devices -j | awk '/^"keyboards"/,/^\],$/' | sed -n 's/.*"name": "\(.*\)".*/\1/p' }}};
<CURSORTHEME> ::= {{{ printf '%s\n' /usr/share/icons/*/cursors | cut -d/ -f5 }}};
<MONITOR> ::= {{{ hyprctl monitors | sed -n 's/^Monitor \(.*\) (ID .*/\1/p' }}};
<INSTANCE> ::= {{{ hyprctl instances -j | sed -n 's/.*"instance": "\(.*\)".*/\1/p' }}};

6
completions/meson.build Normal file
View file

@ -0,0 +1,6 @@
zsh_install_dir = join_paths(get_option('datadir'), 'zsh', 'site-functions')
fish_install_dir = join_paths(get_option('datadir'), 'fish', 'vendor_completions.d')
bash_install_dir = join_paths(get_option('datadir'), 'bash-completion', 'completions')
install_data('generated/hyprctl.zsh', rename: '_hyprctl', install_dir: zsh_install_dir, install_tag: 'runtime')
install_data('generated/hyprctl.fish', install_dir: fish_install_dir, install_tag: 'runtime')
install_data('generated/hyprctl.bash', rename: 'hyprctl', install_dir: bash_install_dir, install_tag: 'runtime')

View file

@ -87,6 +87,7 @@ subdir('hyprctl')
subdir('assets') subdir('assets')
subdir('example') subdir('example')
subdir('docs') subdir('docs')
subdir('completions')
pkg_install_dir = join_paths(get_option('datadir'), 'pkgconfig') pkg_install_dir = join_paths(get_option('datadir'), 'pkgconfig')