# :vim set ts=4 sw=4 expandtab syntax=sh:
# IMH RADS bash autocomplete
# J. Hipps <jacobh@inmotionhosting.com>
# Check if the directory /usr/local/cpanel/bin exists.
# Exit the script if it does not.
[ ! -d "/usr/local/cpanel/bin" ] && return
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
complete -F __autocomplete_user account-review
complete -F __autocomplete_user check_cpu
complete -F __autocomplete_user unsuspend_user
complete -F __autocomplete_user fixperms
complete -F __autocomplete_user switch
complete -F __autocomplete_user send_pp_email
complete -F __autocomplete_user hostsfilemods
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
# auto-complete domain names
COMPREPLY=( $(compgen -W "$(sudo cat /etc/userdomains | awk -F: '{print $1}' | grep -v '^\*$')" -- $cur) )
complete -F _whoowns whoowns
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opListLong="--new-user --owner --password --domain --theme --cgi --no-cgi --shell --no-shell --ip --package --bandwidth --quota --reseller --no-reseller --acl --self --no-self --ns --custom-ns --allow --deny --force"
opListShort="-u -o -w -d -t -c -s -i -p -b -q -r -a -D -b -h -v"
opSysOps="--list-users --list-themes --list-ips --list-packages --list-resellers --list-acls --summary --info --debug --bleach --no-color --man --help --version"
if [[ $cword == 1 ]]; then
COMPREPLY=( $(compgen -W "$(\ls /var/cpanel/users/)" -- $cur) )
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort $opSysOps" -- $cur) )
COMPREPLY=( $(compgen -W "$(\ls -p /var/cpanel/packages/ | grep -v /)" -- $cur) )
COMPREPLY=( $(compgen -W "$(ip a s | grep inet | grep -v -E '(127.0.0.1|inet6| 192.168)' | awk '{print $2}' | sed 's/\/.*//')" -- $cur) )
COMPREPLY=( $(compgen -W "$(cat /var/cpanel/resellers | awk -F: '{print $1}')" -- $cur) )
complete -F _modify_account modify-account
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opListLong="--recent --full"
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
complete -F _check_user check_user
complete -F _check_user check_crons
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opListLong="--with-ptr --no-ptr"
opListShort="-n -w -p -P -h"
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
# auto-complete domlogs path
if [ -f /etc/cpanel/ea4/is_ea4 ]; then
DOMLOGS_PATH=/var/log/apache2/domlogs
DOMLOGS_PATH=/usr/local/apache/domlogs
if [[ "$cur" == /* ]]; then
COMPREPLY=( $(compgen -W "$(find $DOMLOGS_PATH/*)" -- $cur) )
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opListLong="--sched --moved --tos --ra --cancel --billing --orphan"
if [ $cword == 1 ] || [ "$prev" == "-u" ]; then
COMPREPLY=( $(compgen -W "$(\ls /var/cpanel/users/)" -- $cur) )
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
complete -F _suspend_user suspend_user
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opListLong="--dirtotals --listdirs --queuebysender --queuebybounceback --bouncesbydomain --recipientisp --recipienttest --fullmbox --fwdtotals --lines --status"
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
complete -F _check_exim check_exim
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opListLong="--sockets --active --kill --killqueries --killselects"
if [[ "$prev" == "--kill" ]]; then
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
complete -F _check_mysql check_mysql
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
opListLong="--listsigs --dir --user --signame --matches --outfile --auto-quarantine --no-quarantine"
opListShort="-l -d -u -s -m -o -h -y -n"
if [ "$prev" == "-u" ] || [ "$prev" == "--user" ]; then
COMPREPLY=( $(compgen -W "$(sudo \ls /var/cpanel/users/)" -- $cur) )
if [[ "$cur" == -* ]]; then
COMPREPLY=( $(compgen -W "$opListLong $opListShort" -- $cur) )
complete -F _shellscan shellscan.py
###############################################################################
local cur prev words cword
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
delOptsLong="--help --core --zip --backup --softaculous --temp"
delOptsShort="-h -c -z -b -s -t -a"
noteOptsLong="--help --wordpress"
# auto-complete operation modes
if [[ $cword == 1 ]]; then
COMPREPLY=( $(compgen -W "$opModes" -- $cur) )
# auto-complete options for each op mode
COMPREPLY=( $(compgen -W "$delOptsLong $delOptsShort" -- $cur) )
COMPREPLY=( $(compgen -W "$noteOptsLong $noteOptsShort" -- $cur) )
complete -F _disk_cleanup disk_cleanup.py