From e7552dd682c8a068d94398531dccb13e13960f8c Mon Sep 17 00:00:00 2001 From: Salt Date: Tue, 6 Nov 2018 18:20:37 -0600 Subject: [PATCH] .functions: Add autocompletion of proj() to bash --- .functions | 20 ++++++++++++++++++-- 1 file changed, 18 insertions(+), 2 deletions(-) diff --git a/.functions b/.functions index a150ef4a..03b0ef89 100644 --- a/.functions +++ b/.functions @@ -10,14 +10,13 @@ proj() { echo "proj: requires argument" return 1 fi - projname="${1//[^ a-zA-Z0-9]/}" + projname="${1//[^ a-zA-Z0-9.]/}" projdir="$HOME/Projects/$projname" # Ensure we have a ~/Projects directory mkdir -p "$HOME/Projects" > /dev/null 2>&1 # cd into the project or make it if necessary if [ -d "$projdir" ]; then # It exists - echo "Going to existing project \"$projname\"" cd "$projdir" else # It does not exist @@ -35,4 +34,21 @@ proj() { fi fi } +# Autocompletion for bash +complete -F _proj proj > /dev/null 2>&1 && +_proj() { + [ "${#COMP_WORDS[@]}" != "2" ] && return 0 + for dir in $HOME/Projects/*; do + reply="$(basename "$dir")" + reply="${reply//[^ a-zA-Z0-9.]/}" + COMPREPLY+=" $reply" + done + COMPREPLY=($(compgen -W "$COMPREPLY" "${COMP_WORDS[COMP_CWORD]}")) + return 0 +} +# Autocompletion for zsh +compdef _proj proj > /dev/null 2>&1 && +_proj() { + return 0 +}