From d8e18d81ec602e9eb851c319762477b38b23cece Mon Sep 17 00:00:00 2001 From: Robin Candau <53110319+Antiz96@users.noreply.github.com> Date: Sat, 13 Apr 2024 11:59:39 +0000 Subject: [PATCH] Add shell completions for bash, zsh and fish (#50) This PR aims to introduce basic shell completions for bash, zsh and fish for the zaman command. --- Makefile | 5 +++++ res/completions/zaman.bash | 13 +++++++++++++ res/completions/zaman.fish | 7 +++++++ res/completions/zaman.zsh | 12 ++++++++++++ 4 files changed, 37 insertions(+) create mode 100644 res/completions/zaman.bash create mode 100644 res/completions/zaman.fish create mode 100644 res/completions/zaman.zsh diff --git a/Makefile b/Makefile index cd3df6c..5629970 100644 --- a/Makefile +++ b/Makefile @@ -10,6 +10,11 @@ install: # Install the main script install -Dm 755 "src/script/${pkgname}.sh" "${DESTDIR}${PREFIX}/bin/${pkgname}" + # Install shell completions + install -Dm 644 "res/completions/${pkgname}.bash" "${DESTDIR}${PREFIX}/share/bash-completion/completions/${pkgname}" + install -Dm 644 "res/completions/${pkgname}.zsh" "${DESTDIR}${PREFIX}/share/zsh/site-functions/_${pkgname}" + install -Dm 644 "res/completions/${pkgname}.fish" "${DESTDIR}${PREFIX}/share/fish/vendor_completions.d/${pkgname}.fish" + # Archive and install man pages gzip -c "doc/man/${pkgname}.1" > "${pkgname}.1.gz" install -Dm 644 "${pkgname}.1.gz" "${DESTDIR}${PREFIX}/share/man/man1/${pkgname}.1.gz" diff --git a/res/completions/zaman.bash b/res/completions/zaman.bash new file mode 100644 index 0000000..2b2828e --- /dev/null +++ b/res/completions/zaman.bash @@ -0,0 +1,13 @@ +_zaman() { + local arg="${2}" + local -a opts + opts=('-m --menu + -o --output + -O --save + -h --help + -V --version') + + COMPREPLY=( $(compgen -W "${opts[*]}" -- "${arg}") ) +} + +complete -F _zaman zaman diff --git a/res/completions/zaman.fish b/res/completions/zaman.fish new file mode 100644 index 0000000..cfebe1d --- /dev/null +++ b/res/completions/zaman.fish @@ -0,0 +1,7 @@ +complete -c zaman -f + +complete -c zaman -s m -l menu -d 'Print a menu via rofi or dmenu that lists every man pages to choose from (default operation)' +complete -c zaman -s o -l output -d '(Args ) Save into the PDF file' +complete -c zaman -s O -l save -d '(Arg ) Save into the "man_.pdf" file in the current directory' +complete -c zaman -s h -l help -d 'Display the help message' +complete -c zaman -s V -l version -d 'Display version information' diff --git a/res/completions/zaman.zsh b/res/completions/zaman.zsh new file mode 100644 index 0000000..09e2255 --- /dev/null +++ b/res/completions/zaman.zsh @@ -0,0 +1,12 @@ +#compdef zaman + +local -a opts +opts=( + {-m,--menu}'[Print a menu via rofi or dmenu that lists every man pages to choose from (default operation)]' + {-o,--output}'[(Args ) Save into the PDF file]' + {-O,--save}'[(Arg ) Save into the "man_.pdf" file in the current directory]' + {-h,--help}'[Display the help message]' + {-V,--version}'[Display version information]' +) + +_arguments $opts