nodejs-bash-completion/completions/_completion_template

47 lines
1.5 KiB
Plaintext

[[ "$1" != "" ]] || {
echo "Usage: source _completion_template <scriptname>"
}
[[ "$1" = "" ]] || {
_pm()
{
local cur prev
local IFS=$'\n'
# Retrieve the original value
local width=$(bind -v | sed -n 's/^set completion-display-width //p')
if [[ $width -ne 0 ]]; then
# Change the readline variable
bind "set completion-display-width 0"
# On the first tab press, expand a common prefix
# On the second tab press, list out options
# Any subsequent tab presses cycle through these options
bind "set show-all-if-ambiguous on"
bind "set menu-complete-display-prefix on"
bind "TAB: menu-complete"
bind "set colored-completion-prefix on"
bind "set colored-stats on"
# Set up PROMPT_COMMAND to reset itself to its current value
PROMPT_COMMAND="PROMPT_COMMAND=$(printf %q "$PROMPT_COMMAND")"
# Set up PROMPT_COMMAND to reset the readline variable
PROMPT_COMMAND+="; bind 'set completion-display-width $width'"
fi
cur=${COMP_WORDS[COMP_CWORD]}
prev=${COMP_WORDS[COMP_CWORD-1]}
# Get all options from omelette
COMPREPLY=( $(compgen -W '$(./'$1' --compbash --compgen "${COMP_CWORD}" "${prev}" "${COMP_LINE}")' -- "$cur") )
# If no options available, print files and folders
if [ ${#COMPREPLY[@]} -eq 0 ]; then
COMPREPLY=( $(compgen -f -o default -o plusdirs $cur) )
fi
return 0
}
complete -F _pm $1
}