.functions: Add autocompletion of proj() to bash
This commit is contained in:
parent
b42eacc539
commit
e7552dd682
20
.functions
20
.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
|
||||
}
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user