Skip to content

Commit

Permalink
Merge pull request #967 from scop/refactor/api-work
Browse files Browse the repository at this point in the history
refactor: more API related work
  • Loading branch information
scop authored May 8, 2023
2 parents b87010c + 007e641 commit 8da5dfb
Show file tree
Hide file tree
Showing 20 changed files with 106 additions and 85 deletions.
82 changes: 41 additions & 41 deletions bash_completion
Original file line number Diff line number Diff line change
Expand Up @@ -927,7 +927,7 @@ _comp__split_longopt()
# Complete variables.
# @return True (0) if variables were completed,
# False (> 0) if not.
# TODO: rename per API conventions
# TODO:API: rename per conventions
_variables()
{
if [[ $cur =~ ^(\$(\{[!#]?)?)([A-Za-z0-9_]*)$ ]]; then
Expand Down Expand Up @@ -1347,7 +1347,7 @@ _comp_compgen_usage()

# This function completes on signal names (minus the SIG prefix)
# @param $1 prefix
# TODO: rename per API conventions
# TODO:API: rename per conventions
_signals()
{
local -a sigs
Expand All @@ -1357,7 +1357,7 @@ _signals()

# This function completes on known mac addresses
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_mac_addresses()
{
local re='\([A-Fa-f0-9]\{2\}:\)\{5\}[A-Fa-f0-9]\{2\}'
Expand Down Expand Up @@ -1397,7 +1397,7 @@ _mac_addresses()

# This function completes on configured network interfaces
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_configured_interfaces()
{
local -a files
Expand Down Expand Up @@ -1431,7 +1431,7 @@ _configured_interfaces()
# -6: IPv6 addresses only
# -a: All addresses
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_ip_addresses()
{
local n
Expand All @@ -1451,7 +1451,7 @@ _ip_addresses()

# This function completes on available kernels
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_kernel_versions()
{
_comp_compgen -- -W '$(command ls /lib/modules)'
Expand All @@ -1461,7 +1461,7 @@ _kernel_versions()
# -a: restrict to active interfaces only
# -w: restrict to wireless interfaces only
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_available_interfaces()
{
local PATH=$PATH:/sbin
Expand All @@ -1480,7 +1480,7 @@ _available_interfaces()
}

# Echo number of CPUs, falling back to 1 on failure.
# TODO: rename per API conventions, rework to use vars rather than outputting
# TODO:API: rename per conventions, rework to use vars rather than outputting
_ncpus()
{
local var=NPROCESSORS_ONLN
Expand Down Expand Up @@ -1529,7 +1529,7 @@ _comp_compgen_tilde()
# ~foo/* /home/foo/*
#
# @param $1 Name of variable (not the value of the variable) to expand
# TODO: rename per API conventions
# TODO:API: rename per conventions
__expand_tilde_by_ref()
{
if [[ ${!1-} == \~* ]]; then
Expand All @@ -1539,7 +1539,7 @@ __expand_tilde_by_ref()

# This function expands tildes in pathnames
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_expand()
{
# Expand ~username type directory specifications. We want to expand
Expand All @@ -1560,7 +1560,7 @@ _expand()

# Process ID related functions.
# for AIX and Solaris we use X/Open syntax, BSD for others.
# TODO: rename per API conventions
# TODO:API: rename per conventions
if [[ $OSTYPE == *@(solaris|aix)* ]]; then
# This function completes on process IDs.
_pids()
Expand Down Expand Up @@ -1639,7 +1639,7 @@ fi

# This function completes on user IDs
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_uids()
{
if type getent &>/dev/null; then
Expand All @@ -1654,7 +1654,7 @@ _uids()

# This function completes on group IDs
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_gids()
{
if type getent &>/dev/null; then
Expand All @@ -1673,7 +1673,7 @@ _comp_backup_glob='@(#*#|*@(~|.@(bak|orig|rej|swp|dpkg*|rpm@(orig|new|save))))'

# Complete on xinetd services
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_xinetd_services()
{
local xinetddir=${_comp__test_xinetd_dir:-/etc/xinetd.d}
Expand All @@ -1688,7 +1688,7 @@ _xinetd_services()

# This function completes on services
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_services()
{
local sysvdirs
Expand Down Expand Up @@ -1718,7 +1718,7 @@ _services()
# one, because we set it up eagerly as completer for scripts in sysv init dirs
# below.
#
# TODO: rename per API conventions, rework to use vars rather than outputting
# TODO:API: rename per conventions, rework to use vars rather than outputting
_service()
{
local cur prev words cword comp_args
Expand Down Expand Up @@ -1755,7 +1755,7 @@ _comp__init_set_up_service_completions

# This function completes on modules
#
# TODO: rename per API conventions (+ include "kernel" in the name)
# TODO:API: rename per conventions (+ include "kernel" in the name)
_modules()
{
local modpath
Expand All @@ -1767,7 +1767,7 @@ _modules()

# This function completes on installed modules
#
# TODO: rename per API conventions (+ include "kernel" in the name)
# TODO:API: rename per conventions (+ include "kernel" in the name)
_installed_modules()
{
_comp_compgen -c "$1" -- -W "$(PATH="$PATH:/sbin" lsmod |
Expand All @@ -1781,7 +1781,7 @@ _installed_modules()
#
# @param $1 If -u, only return users/groups the user has access to in
# context of current completion.
# TODO: rename per API conventions
# TODO:API: rename per conventions
_usergroup()
{
if [[ $cur == *\\\\* || $cur == *:*:* ]]; then
Expand Down Expand Up @@ -1826,7 +1826,7 @@ _usergroup()
fi
}

# TODO: rename per API conventions
# TODO:API: rename per conventions
_allowed_users()
{
if _complete_as_root; then
Expand All @@ -1837,7 +1837,7 @@ _allowed_users()
fi
}

# TODO: rename per API conventions
# TODO:API: rename per conventions
_allowed_groups()
{
if _complete_as_root; then
Expand All @@ -1858,7 +1858,7 @@ _comp_selinux_users()
# This function completes on valid shells
#
# @param $1 chroot to search from
# TODO: rename per API conventions
# TODO:API: rename per conventions
_shells()
{
local shell rest
Expand All @@ -1869,7 +1869,7 @@ _shells()

# This function completes on valid filesystem types
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_fstypes()
{
local fss
Expand Down Expand Up @@ -1935,7 +1935,7 @@ _comp_realcommand()
# This function returns the first argument, excluding options
# @param $1 chars Characters out of $COMP_WORDBREAKS which should
# NOT be considered word breaks. See _comp__reassemble_words.
# TODO: rename per API conventions
# TODO:API: rename per conventions
_get_first_arg()
{
local i
Expand All @@ -1954,7 +1954,7 @@ _get_first_arg()
# NOT be considered word breaks. See _comp__reassemble_words.
# @param $2 glob Options whose following argument should not be counted
# @param $3 glob Options that should be counted as args
# TODO: rename per API conventions
# TODO:API: rename per conventions
_count_args()
{
local i cword words
Expand All @@ -1972,36 +1972,36 @@ _count_args()

# This function completes on PCI IDs
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_pci_ids()
{
_comp_compgen -a -- -W "$(PATH="$PATH:/sbin" lspci -n | awk '{print $3}')"
}

# This function completes on USB IDs
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_usb_ids()
{
_comp_compgen -a -- -W "$(PATH="$PATH:/sbin" lsusb | awk '{print $6}')"
}

# CD device names
# TODO: rename per API conventions
# TODO:API: rename per conventions
_cd_devices()
{
_comp_compgen -ac "${cur:-/dev/}" -- -f -d -X "!*/?([amrs])cd*"
}

# DVD device names
# TODO: rename per API conventions
# TODO:API: rename per conventions
_dvd_devices()
{
_comp_compgen -ac "${cur:-/dev/}" -- -f -d -X "!*/?(r)dvd*"
}

# TERM environment variable values
# TODO: rename per API conventions
# TODO:API: rename per conventions
_terms()
{
_comp_compgen -a -- -W "$({
Expand All @@ -2016,7 +2016,7 @@ _terms()
} 2>/dev/null)"
}

# TODO: rename per API conventions
# TODO:API: rename per conventions
_bashcomp_try_faketty()
{
if type unbuffer &>/dev/null; then
Expand All @@ -2036,7 +2036,7 @@ _bashcomp_try_faketty()

# This function provides simple user@host completion
#
# TODO: rename per API conventions
# TODO:API: rename per conventions
_user_at_host()
{
local cur prev words cword comp_args
Expand All @@ -2053,7 +2053,7 @@ shopt -u hostcomplete && complete -F _user_at_host talk ytalk finger

# NOTE: Using this function as a helper function is deprecated. Use
# `_known_hosts_real' instead.
# TODO: rename per API conventions
# TODO:API: rename per conventions
_known_hosts()
{
local cur prev words cword comp_args
Expand All @@ -2071,7 +2071,7 @@ _known_hosts()
# Helper function to locate ssh included files in configs
# This function looks for the "Include" keyword in ssh config files and
# includes them recursively, adding each result to the config variable.
# TODO: rename per API conventions
# TODO:API: rename per conventions
_included_ssh_config_files()
{
(($# < 1)) &&
Expand Down Expand Up @@ -2124,7 +2124,7 @@ _included_ssh_config_files()
# -4 Filter IPv6 addresses from results
# -6 Filter IPv4 addresses from results
# @return Completions, starting with CWORD, are added to COMPREPLY[]
# TODO: rename per API conventions
# TODO:API: rename per conventions
_known_hosts_real()
{
local configfile="" flag prefix=""
Expand Down Expand Up @@ -2516,7 +2516,7 @@ _comp_root_command()
complete -F _comp_root_command fakeroot gksu gksudo kdesudo really

# Return true if the completion should be treated as running as root
# TODO: rename per API conventions
# TODO:API: rename per conventions
_complete_as_root()
{
[[ $EUID -eq 0 || ${root_command-} ]]
Expand Down Expand Up @@ -2582,7 +2582,7 @@ complete -F _comp_longopt \
declare -Ag _xspecs
# TODO: rename per API conventions
# TODO:API: rename per conventions
_filedir_xspec()
{
local cur prev words cword comp_args
Expand Down Expand Up @@ -2622,7 +2622,7 @@ _filedir_xspec()
fi
}
# TODO: rename per API conventions
# TODO:API: rename per conventions
_install_xspec()
{
local xspec=$1 cmd
Expand Down Expand Up @@ -2691,7 +2691,7 @@ _install_xspec '!*.@(mp[234c]|og[ag]|@(fl|a)ac|m4[abp]|spx|tta|w?(a)v|wma|aif?(f
unset -f _install_xspec
# Minimal completion to use as fallback in _completion_loader.
# TODO: rename per API conventions
# TODO:API: rename per conventions
_minimal()
{
local cur prev words cword comp_args
Expand All @@ -2702,7 +2702,7 @@ _minimal()
# https://lists.gnu.org/archive/html/bug-bash/2012-01/msg00045.html
complete -F _minimal ''
# TODO: rename per API conventions
# TODO:API: rename per conventions
__load_completion()
{
local cmd=$1 cmdname=${1##*/} dir compfile
Expand Down Expand Up @@ -2821,7 +2821,7 @@ __load_completion()
}
# set up dynamic completion loading
# TODO: rename per API conventions
# TODO:API: rename per conventions
_completion_loader()
{
# $1=_EmptycmD_ already for empty cmds in bash 4.3, set to it for earlier
Expand Down
6 changes: 3 additions & 3 deletions completions/_modules
Original file line number Diff line number Diff line change
Expand Up @@ -21,21 +21,21 @@
# being sourced before it and thus before the `module' alias has been defined.
[[ -f /etc/profile.d/modules.sh ]] || return 1

# TODO: rename per API conventions, rework to use vars rather than outputting
# TODO:API: rename per conventions, rework to use vars rather than outputting
_module_list()
{
local modules="$(command sed 's/:/ /g' <<<"$LOADEDMODULES" | sort)"
compgen -W "$modules" -- "$1"
}

# TODO: rename per API conventions, rework to use vars rather than outputting
# TODO:API: rename per conventions, rework to use vars rather than outputting
_module_path()
{
local modules="$(command sed 's/:/ /g' <<<"$MODULEPATH" | sort)"
compgen -W "$modules" -- "$1"
}

# TODO: rename per API conventions, rework to use vars rather than outputting
# TODO:API: rename per conventions, rework to use vars rather than outputting
_module_avail()
{
local modules="$(
Expand Down
Loading

0 comments on commit 8da5dfb

Please sign in to comment.