Skip to content

Commit 85d348a

Browse files
committed
Added basic bash completion for tykky shell function
1 parent fc3c334 commit 85d348a

File tree

2 files changed

+43
-0
lines changed

2 files changed

+43
-0
lines changed
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
_tykky_completions() {
2+
if [ "${#COMP_WORDS[@]}" == "2" ]; then
3+
COMPREPLY=($(compgen -W "activate deactivate" "${COMP_WORDS[1]}"))
4+
return
5+
fi
6+
if [[ ${#COMP_WORDS[@]} -gt 2 ]]; then
7+
if [[ "${COMP_WORDS[1]}" == "activate" && "${COMP_WORDS[2]}" != *"/"* ]]; then
8+
local __tykky_env_list=""
9+
local __tykky_path __candidate
10+
local oldIFS=$IFS
11+
IFS=:
12+
for __tykky_path in ${TYKKY_PATH:-~/.tykky}; do
13+
IFS=$oldIFS
14+
for __candidate in $__tykky_path/*; do
15+
if [[ -d "$__candidate" && -f "$__candidate/common.sh" && -d "$__candidate/bin" ]]; then
16+
__tykky_env_list+="$(basename $__candidate) "
17+
fi
18+
done
19+
done
20+
COMPREPLY=($(compgen -W "$__tykky_env_list" "${COMP_WORDS[2]}"))
21+
return
22+
elif [[ "${COMP_WORDS[1]}" == "activate" && "${COMP_WORDS[2]}" == *"/"* ]]; then
23+
COMPREPLY=( $(compgen -d -- "${COMP_WORDS[2]}") )
24+
local i
25+
for i in "${!COMPREPLY[@]}"; do
26+
if [[ -d "${COMPREPLY[$i]}" && ! -f "${COMPREPLY[$i]}/common.sh" && ! -d "${COMPREPLY[$i]}/bin" ]]; then
27+
COMPREPLY[$i]="${COMPREPLY[$i]}/"
28+
fi
29+
done
30+
compopt -o nospace
31+
fi
32+
fi
33+
return
34+
}
35+
36+
complete -F _tykky_completions tykky

etc/profile.d/tykky.sh

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -91,3 +91,10 @@ tykky() {
9191
;;
9292
esac
9393
}
94+
95+
# Enable BASH autocompletion
96+
if [ -n "$BASH_VERSION" ] && [ -n "$PS1" ]; then
97+
__tykky_bash_completion_file="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)/../bash_completion.d/tykky_completion"
98+
[ -f "$__tykky_bash_completion_file" ] && . "$__tykky_bash_completion_file"
99+
unset __tykky_bash_completion_file
100+
fi

0 commit comments

Comments
 (0)