Skip to content

Commit

Permalink
Add shell completions for bash, zsh and fish (#50)
Browse files Browse the repository at this point in the history
This PR aims to introduce basic shell completions for bash, zsh and fish for the zaman command.
  • Loading branch information
Antiz96 authored Apr 13, 2024
1 parent 7f17cab commit d8e18d8
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
13 changes: 13 additions & 0 deletions res/completions/zaman.bash
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions res/completions/zaman.fish
Original file line number Diff line number Diff line change
@@ -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 <man page> <file>) Save <man page> into the <file> PDF file'
complete -c zaman -s O -l save -d '(Arg <man page>) Save <man page> into the "man_<man page>.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'
12 changes: 12 additions & 0 deletions res/completions/zaman.zsh
Original file line number Diff line number Diff line change
@@ -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 <man page> <file>) Save <man page> into the <file> PDF file]'
{-O,--save}'[(Arg <man page>) Save <man page> into the "man_<man page>.pdf" file in the current directory]'
{-h,--help}'[Display the help message]'
{-V,--version}'[Display version information]'
)

_arguments $opts

0 comments on commit d8e18d8

Please sign in to comment.