Skip to content

Commit

Permalink
fix: use pathcmd=$(type -P -- "$1") for arbitrary cmds
Browse files Browse the repository at this point in the history
If the command name starts with `-`, `type` is confused and tries to
parse it as an option to `type`.  In the current setup, the option
starting with `-` does not happen because we do not set up the
completion settings for such command names, but it is better to put
them on a safe side.
  • Loading branch information
akinomyoga committed Apr 4, 2024
1 parent 350b1b7 commit 8795ca9
Show file tree
Hide file tree
Showing 25 changed files with 27 additions and 27 deletions.
2 changes: 1 addition & 1 deletion completions/_nox
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This serves as a fallback in case the completion is not installed otherwise.

eval -- "$(
pathcmd=$(type -P "$1" 2>/dev/null | command sed 's,/[^/]*$,,')
pathcmd=$(type -P -- "$1" 2>/dev/null | command sed 's,/[^/]*$,,')
[[ $pathcmd ]] && PATH=$pathcmd${PATH:+:$PATH}
register-python-argcomplete --shell bash "$1" 2>/dev/null ||
register-python-argcomplete3 --shell bash "$1" 2>/dev/null
Expand Down
2 changes: 1 addition & 1 deletion completions/add_members
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _comp_cmd_add_members()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
4 changes: 2 additions & 2 deletions completions/apt-get
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ _comp_cmd_apt_get()
source)
# Prefer `apt-cache` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x apt-cache packages
_comp_compgen -a split -- "$(apt-cache dumpavail |
_comp_awk '$1 == "Source:" { print $2 }' | sort -u)"
Expand Down Expand Up @@ -79,7 +79,7 @@ _comp_cmd_apt_get()
--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
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen_split -- "$(apt-cache policy | command sed -ne \
's/^ *release.*[ ,]o=\(Debian\|Ubuntu\),a=\(\w*\).*/\2/p')"
return
Expand Down
2 changes: 1 addition & 1 deletion completions/arch
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ _comp_have_command mailmanctl &&
1)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
;;
2)
Expand Down
2 changes: 1 addition & 1 deletion completions/change_pw
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_change_pw()
-l | --listname)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
return
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/check_db
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _comp_cmd_check_db()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/clone_member
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_clone_member()
-l | --listname)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
return
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/config_list
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _comp_cmd_config_list()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_xfunc list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/find_member
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_find_member()
-l | -x | --listname | --exclude)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
return
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/inject
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ _comp_cmd_inject()
-l | --listname)
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
return
;;
Expand Down
2 changes: 1 addition & 1 deletion completions/list_admins
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _comp_cmd_list_admins()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/list_members
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ _comp_cmd_list_members()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/list_owners
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _comp_cmd_list_owners()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/mysql
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _comp_cmd_mysql()

# Prefer `mysqlshow` in the same dir as the command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH

local noargopts='!(-*|*[uDhSPeI]*)'
# shellcheck disable=SC2254
Expand Down
2 changes: 1 addition & 1 deletion completions/newlist
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ _comp_cmd_newlist()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x 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 @@ -107,7 +107,7 @@ _comp_cmd_perldoc()

# Prefer `perl` in the same dir in utility functions
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH

case $prev in
-*[hVnoMwL])
Expand Down
2 changes: 1 addition & 1 deletion completions/pydoc
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ _comp_cmd_pydoc()
if ! _comp_looks_like_path "$cur"; then
# Prefer python in the same dir for resolving modules
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -ax python modules
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/remove_members
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ _comp_cmd_remove_members()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/rmlist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _comp_cmd_rmlist()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/rpm
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ _comp_cmd_rpmbuild()
--target | --eval | -${noargopts}E | --buildpolicy)
# Prefer `rpm` in the same dir in utility functions
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
;;&
--target)
_comp_cmd_rpm__buildarchs
Expand Down
4 changes: 2 additions & 2 deletions completions/ssh
Original file line number Diff line number Diff line change
Expand Up @@ -404,7 +404,7 @@ _comp_cmd_sftp()

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

_comp_xfunc_ssh_compgen_suboption_check && return

Expand Down Expand Up @@ -556,7 +556,7 @@ _comp_cmd_scp()

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

_comp_xfunc_ssh_compgen_suboption_check && {
((${#COMPREPLY[@]})) && COMPREPLY=("${COMPREPLY[@]/%/ }")
Expand Down
2 changes: 1 addition & 1 deletion completions/ssh-copy-id
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ _comp_cmd_ssh_copy_id()

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

_comp_compgen -x ssh suboption_check && return

Expand Down
2 changes: 1 addition & 1 deletion completions/ssh-keygen
Original file line number Diff line number Diff line change
Expand Up @@ -101,7 +101,7 @@ _comp_cmd_ssh_keygen()
-*t)
# Prefer `ssh` from same dir for resolving options, etc
local pathcmd protocols
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -v protocols -x ssh query protocol-version
local types='dsa ecdsa ecdsa-sk ed25519 ed25519-sk rsa'
if [[ ${protocols[*]} == *1* ]]; then
Expand Down
2 changes: 1 addition & 1 deletion completions/sync_members
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ _comp_cmd_sync_members()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
fi

Expand Down
2 changes: 1 addition & 1 deletion completions/withlist
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ _comp_cmd_withlist()
else
# Prefer `list_lists` in the same dir as command
local pathcmd
pathcmd=$(type -P "$1") && local PATH=${pathcmd%/*}:$PATH
pathcmd=$(type -P -- "$1") && local PATH=${pathcmd%/*}:$PATH
_comp_compgen -x list_lists mailman_lists
fi

Expand Down

0 comments on commit 8795ca9

Please sign in to comment.