Skip to content

Instantly share code, notes, and snippets.

@amanjuman
Created February 16, 2020 18:10
Show Gist options
  • Save amanjuman/7e8155be9777f68a67b0380f8236d9aa to your computer and use it in GitHub Desktop.
Save amanjuman/7e8155be9777f68a67b0380f8236d9aa to your computer and use it in GitHub Desktop.
Nginx bash autocomplete script
# Name: nginx
# Desc: Nginx bash autocomplete script
# Ver: 1.0
_nginx_allcomp()
{
command ls /etc/nginx/$1 2>/dev/null
}
_nginx_sites()
{
COMPREPLY=( $( compgen -W '$( _nginx_allcomp $1 )' -- $cur ) )
}
_nginx_conf()
{
COMPREPLY=( $( compgen -W '$( _nginx_allcomp $1 \
| sed -e 's/[.]conf$//' )' -- $cur ) )
}
_n2ensite()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
_nginx_sites sites-available
}
complete -F _n2ensite n2ensite
_n2dissite()
{
local cur
COMPREPLY=()
cur=${COMP_WORDS[COMP_CWORD]}
_nginx_sites sites-enabled
}
complete -F _n2dissite n2dissite
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment