Skip to content

refactor: more util/xfunc primary command convention adjustments #988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 23, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions completions/add_members
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ _comp_cmd_add_members()
_comp_compgen -- -W '--regular-members-file --digest-members-file
--welcome-msg --admin-notify --help'
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
24 changes: 18 additions & 6 deletions completions/apt-cache
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,36 @@
# @since 2.12
_comp_xfunc_apt_cache_packages()
{
apt-cache --no-generate pkgnames "$cur" 2>/dev/null || :
_comp_cmd_apt_cache__packages apt-cache
}

# TODO:API: rework to use vars rather than outputting
_comp_cmd_apt_cache__packages()
{
"$1" --no-generate pkgnames "$cur" 2>/dev/null || :
}

# List APT source packages
# TODO:API: rework to use vars rather than outputting
# @since 2.12
_comp_xfunc_apt_cache_sources()
{
compgen -W "$(apt-cache dumpavail |
awk '$1 == "Source:" { print $2 }' | sort -u)" -- "$1"
_comp_cmd_apt_cache__sources apt-cache "$1"
}

# TODO:API: rework to use vars rather than outputting
_comp_cmd_apt_cache__sources()
{
compgen -W "$("$1" dumpavail |
awk '$1 == "Source:" { print $2 }' | sort -u)" -- "$2"
}

# List APT source packages
# TODO:API: rework to use vars rather than outputting
# @since 2.12
_comp_xfunc_apt_cache_src_packages()
{
compgen -W '$(_comp_xfunc_apt_cache_sources "$cur")' -- "$cur"
compgen -W '$(_comp_cmd_apt_cache__sources apt-cache "$cur")' -- "$cur"
}

_comp_deprecate_func 2.12 _apt_cache_packages _comp_xfunc_apt_cache_packages
Expand Down Expand Up @@ -52,11 +64,11 @@ _comp_cmd_apt_cache()
;;

showsrc)
COMPREPLY=($(_comp_xfunc_apt_cache_sources "$cur"))
COMPREPLY=($(_comp_cmd_apt_cache__sources "$1" "$cur"))
;;

*)
COMPREPLY=($(_comp_xfunc_apt_cache_packages))
COMPREPLY=($(_comp_cmd_apt_cache__packages "$1"))
;;

esac
Expand Down
6 changes: 6 additions & 0 deletions completions/apt-get
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,9 @@ _comp_cmd_apt_get()
_comp_xfunc_apt_get_installed_packages
;;
source)
# Prefer `apt-cache` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
COMPREPLY=($(_comp_xfunc apt-cache packages)
$(compgen -W "$(apt-cache dumpavail |
awk '$1 == "Source:" { print $2 }' | sort -u)" -- "$cur"))
Expand Down Expand Up @@ -78,6 +81,9 @@ _comp_cmd_apt_get()
return
;;
--target-release | --default-release | -${noargopts}t)
# Prefer `apt-cache` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
COMPREPLY=($(compgen -W "$(apt-cache policy | command sed -ne \
's/^ *release.*[ ,]o=\(Debian\|Ubuntu\),a=\(\w*\).*/\2/p')" \
-- "$cur"))
Expand Down
3 changes: 3 additions & 0 deletions completions/arch
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ _comp_have_command mailmanctl &&
done
case $args in
1)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
;;
2)
Expand Down
3 changes: 3 additions & 0 deletions completions/change_pw
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ _comp_cmd_change_pw()

case $prev in
-l | --listname)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
return
;;
Expand Down
3 changes: 3 additions & 0 deletions completions/check_db
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ _comp_cmd_check_db()
if [[ $cur == -* ]]; then
_comp_compgen -- -W '--all --verbose --help'
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
3 changes: 3 additions & 0 deletions completions/clone_member
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ _comp_cmd_clone_member()

case $prev in
-l | --listname)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
return
;;
Expand Down
3 changes: 3 additions & 0 deletions completions/config_list
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ _comp_cmd_config_list()
COMPREPLY=($(compgen -W '--inputfile --outputfile --checkonly
--verbose --help' -- "$cur"))
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
3 changes: 3 additions & 0 deletions completions/find_member
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ _comp_cmd_find_member()

case $prev in
-l | -x | --listname | --exclude)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
return
;;
Expand Down
3 changes: 3 additions & 0 deletions completions/inject
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,9 @@ _comp_cmd_inject()

case $prev in
-l | --listname)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
return
;;
Expand Down
3 changes: 3 additions & 0 deletions completions/list_admins
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ _comp_cmd_list_admins()
if [[ $cur == -* ]]; then
_comp_compgen -- -W '--all-vhost --all --help'
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
3 changes: 3 additions & 0 deletions completions/list_members
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,9 @@ _comp_cmd_list_members()
COMPREPLY=($(compgen -W '--output --regular --digest --nomail
--fullnames --preserve --help' -- "$cur"))
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
3 changes: 3 additions & 0 deletions completions/list_owners
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ _comp_cmd_list_owners()
if [[ $cur == -* ]]; then
_comp_compgen -- -W '--with-listnames --moderators --help'
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
3 changes: 3 additions & 0 deletions completions/newlist
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,9 @@ _comp_cmd_newlist()
_comp_compgen_help
[[ ${COMPREPLY-} == *= ]] && compopt -o nospace
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi
} &&
Expand Down
2 changes: 1 addition & 1 deletion completions/perl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ _comp_cmd_perl__helper()
COMPREPLY=($(compgen -P "$prefix" -W \
"$("${1:-perl}" "${BASH_SOURCE[0]%/*}/../helpers/perl" "$2" "$cur")" \
-- "$cur"))
[[ $1 == functions ]] || _comp_ltrim_colon_completions "$prefix$cur"
[[ $2 == functions ]] || _comp_ltrim_colon_completions "$prefix$cur"
}

_comp_cmd_perl()
Expand Down
3 changes: 3 additions & 0 deletions completions/remove_members
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ _comp_cmd_remove_members()
_comp_compgen -- -W '--file --all --fromall --nouserack --noadminack
--help'
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
3 changes: 3 additions & 0 deletions completions/rmlist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ _comp_cmd_rmlist()
if [[ $cur == -* ]]; then
_comp_compgen -- -W '--archives --help'
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/ssh
Original file line number Diff line number Diff line change
Expand Up @@ -538,7 +538,7 @@ _comp_cmd_scp()
local configfile
_comp_cmd_ssh__configfile

# Prefer `ssh` from same dir for resolving options, etc
# Prefer `ssh` from same dir for resolving options, remote files, etc
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH

Expand Down
3 changes: 3 additions & 0 deletions completions/sync_members
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ _comp_cmd_sync_members()
_comp_compgen -- -W '--no-change --welcome-msg --goodbye-msg --digest
--notifyadmin --file --help'
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
3 changes: 3 additions & 0 deletions completions/withlist
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@ _comp_cmd_withlist()
if [[ $cur == -* ]]; then
_comp_compgen -- -W '--lock --interactive --run --all --quiet --help'
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down