diff options
author | Linus Groh <mail@linusgroh.de> | 2021-04-22 08:43:36 +0200 |
---|---|---|
committer | Linus Groh <mail@linusgroh.de> | 2021-04-22 09:55:48 +0200 |
commit | 696f23d7a0f57d9920ecfdbc86406fb553242777 (patch) | |
tree | 748fe41d7146d362ffc37f7d90c048ceba31bc2e | |
parent | a5625686cb54defba0e474942648cb41269763ab (diff) | |
download | serenity-696f23d7a0f57d9920ecfdbc86406fb553242777.zip |
Meta: Add basic Zsh completions for serenity.sh
This patch adds a basic Zsh completion script for the commands and
targets provided by Meta/serenity.sh. There's some room for improvement
here, e.g. we could provide completion for available CMake targets -
currently completion stops after serenity.sh <command> <target>.
You can enable it by adding this to your .zshrc before completions are
loaded:
fpath=($SERENITY_SOURCE_DIR/Meta/ShellCompletions/zsh $fpath)
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | Meta/ShellCompletions/zsh/_serenity | 63 |
2 files changed, 64 insertions, 0 deletions
diff --git a/.gitignore b/.gitignore index 078038e399..b5260309e1 100644 --- a/.gitignore +++ b/.gitignore @@ -4,6 +4,7 @@ !Makefile !LICENSE !Base/** +!Meta/ShellCompletions/** *.o *.ao diff --git a/Meta/ShellCompletions/zsh/_serenity b/Meta/ShellCompletions/zsh/_serenity new file mode 100644 index 0000000000..880fd29fb0 --- /dev/null +++ b/Meta/ShellCompletions/zsh/_serenity @@ -0,0 +1,63 @@ +#compdef serenity serenity.sh + +_serenity() { + local args + args=( + '1:command:->commands' + '2:target:->targets' + '*:: :->args' + ) + + local commands + commands=( + 'build' + 'install' + 'image' + 'run' + 'gdb' + 'test' + 'delete' + 'recreate' + 'rebuild' + 'kaddr2line' + 'addr2line' + 'rebuild-toolchain' + 'rebuild-world' + ) + + local targets + targets=( + 'i686:Target i686 (default)' + 'x86_64:Target x86_64' + 'lagom:Target host machine' + ) + + _arguments -C -S "$args[@]" + + local command + command="$line[1]" + + local target + target="$line[2]" + + case "$state" in + commands) + _describe 'command' commands + ;; + targets) + case "$command" in + install|image|kaddr2line|rebuild-toolchain|rebuild-world) + # lagom target is not supported for these, remove from targets + targets[$targets[(i)lagom]]=() + ;; + esac + _describe 'target' targets + ;; + args) + ;; + esac + + return 0 +} + +_serenity |