From 911063fce40b1c6201528734de4defc11531fc09 Mon Sep 17 00:00:00 2001 From: Robby Workman Date: Mon, 31 May 2021 20:26:57 -0500 Subject: Import bash-completion file from upstream project MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Thanks to Igor Murzov for the initial contribution of this file to the upstream bash-completion project, and thanks to Ville Skyttä and Koichi Murase for various changes and fixes since then. Co-authored-by: Igor Murzov Co-authored-by: Ville Skyttä Co-authored-by: Koichi Murase --- files/shell-completion/slackpkg.bash | 113 +++++++++++++++++++++++++++++++++++ slackpkg.SlackBuild | 4 ++ 2 files changed, 117 insertions(+) create mode 100644 files/shell-completion/slackpkg.bash diff --git a/files/shell-completion/slackpkg.bash b/files/shell-completion/slackpkg.bash new file mode 100644 index 0000000..90abc8e --- /dev/null +++ b/files/shell-completion/slackpkg.bash @@ -0,0 +1,113 @@ +# bash completion for slackpkg(8) -*- shell-script -*- +# options list is based on `grep '\-.*\=.*)' /usr/sbin/slackpkg | cut -f1 -d\)` + +_slackpkg() +{ + local cur prev words cword + _init_completion -n = || return + + local split=false + if [[ $cur == -?*=* ]]; then + prev="${cur%%?(\\)=*}" + cur="${cur#*=}" + split=true + fi + + case "$prev" in + -delall | -checkmd5 | -checkgpg | -checksize | -postinst | -onoff | \ + -download_all | -dialog | -batch | -only_new_dotnew | \ + -use_includes | -spinning) + COMPREPLY=($(compgen -W 'on off' -- "$cur")) + return + ;; + -default_answer) + COMPREPLY=($(compgen -W 'yes no' -- "$cur")) + return + ;; + -dialog_maxargs | -mirror) + # argument required but no completions available + return + ;; + esac + + $split && return + + if [[ $cur == -* ]]; then + compopt -o nospace + COMPREPLY=($(compgen -W '-delall= -checkmd5= -checkgpg= + -checksize= -postinst= -onoff= -download_all= -dialog= + -dialog_maxargs= -batch= -only_new_dotnew= -use_includes= + -spinning= -default_answer= -mirror=' -- "$cur")) + return + fi + + local confdir="/etc/slackpkg" + local config="$confdir/slackpkg.conf" + + [[ -r $config ]] || return + . "$config" + + local i action + for ((i = 1; i < ${#words[@]}; i++)); do + if [[ ${words[i]} != -* ]]; then + action="${words[i]}" + break + fi + done + + case "$action" in + generate-template | search | file-search) + # argument required but no completions available + return + ;; + install-template | remove-template) + if [[ -e $confdir/templates ]]; then + COMPREPLY=($( + cd "$confdir/templates" + compgen -f -X "!*.template" -- "$cur" + )) + COMPREPLY=(${COMPREPLY[@]%.template}) + fi + return + ;; + remove) + _filedir + COMPREPLY+=($(compgen -W 'a ap d e f k kde kdei l n t tcl x + xap xfce y' -- "$cur")) + COMPREPLY+=($( + cd /var/log/packages + compgen -f -- "$cur" + )) + return + ;; + install | reinstall | upgrade | blacklist | download) + _filedir + COMPREPLY+=($(compgen -W 'a ap d e f k kde kdei l n t tcl x + xap xfce y' -- "$cur")) + COMPREPLY+=($(cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null | + command grep "^$cur")) + return + ;; + info) + COMPREPLY=($(cut -f 6 -d\ "${WORKDIR}/pkglist" 2>/dev/null | + command grep "^$cur")) + return + ;; + update) + # we should complete the same as the next `list` + "gpg" + COMPREPLY=($(compgen -W 'gpg' -- "$cur")) + ;& + *) + COMPREPLY+=($(compgen -W 'install reinstall upgrade remove + blacklist download update install-new upgrade-all + clean-system new-config check-updates help generate-template + install-template remove-template search file-search info' -- \ + "$cur")) + return + ;; + esac + +} && + complete -F _slackpkg slackpkg + +# ex: filetype=sh diff --git a/slackpkg.SlackBuild b/slackpkg.SlackBuild index f4f7553..443e96b 100755 --- a/slackpkg.SlackBuild +++ b/slackpkg.SlackBuild @@ -100,6 +100,10 @@ chown -R root:root $PKG/usr/man # Compress manual pages find $PKG/usr/man -type f -exec gzip -9 {} \; +# Install bash-completion file +mkdir -p $PKG/usr/share/bash-completion/completions +cat $CWD/shell-completion/slackpkg.bash > $PKG/usr/share/bash-completion/completions/slackpkg + # Update version number: sed -i "s/@VERSION@/$VERSION/g" $PKG/usr/sbin/slackpkg -- cgit v1.2.3