-
Notifications
You must be signed in to change notification settings - Fork 5
/
setup_completions.sh
executable file
·68 lines (58 loc) · 1.82 KB
/
setup_completions.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
#!/bin/bash
COMPLETIONS_DIR=~/.zsh/completions
# Generate completion for apps that generate them
completion_generators=(
"poetry completions zsh"
"pipenv --completion"
"bw completion --shell zsh"
"pritunl-client completion zsh"
)
for completion_generator in "${completion_generators[@]}"; do
cmd=$(echo $completion_generator | cut -d' ' -f1)
if hash $cmd 2>/dev/null; then
eval "$completion_generator" > $COMPLETIONS_DIR/_$cmd
fi
done
# source ~/.bash_completion.d/python-argcomplete.sh
# Download completions from github
download_completions=(
"jupyter/jupyter_core/master/examples/completions-zsh _jupyter"
"docker/cli/master/contrib/completion/zsh/_docker _docker"
"robbyrussell/oh-my-zsh/master/plugins/geeknote/_geeknote _geeknote"
)
base_url="https://raw.githubusercontent.com"
for comp in "${download_completions[@]}"; do
path=$(echo $comp | cut -d' ' -f1)
output_name=$(echo $comp | cut -d' ' -f2)
curl -sL "${base_url}/${path}" -o "$COMPLETIONS_DIR/${output_name}"
done
# Generate completions for Click apps
click_apps=(
black
pip-compile
pip-sync
git-up
cookiecutter
)
for app in "${click_apps[@]}";do
env_magic=$(echo $app | tr '[:lower:]' '[:upper:]' | tr '-' '_')
eval "_${env_magic}_COMPLETE=zsh_source $app > $COMPLETIONS_DIR/_$app"
done
# make sure #compdef is always at the top of completions
for f in $(find $COMPLETIONS_DIR -type f); do
cname=$(echo $f | sed -E 's/.+_//')
header="#compdef $cname"
if [ -z "$(grep "$header" $f)" ] && [ "$cname" != "tlp-radio-devices" ]; then
if [[ "$OSTYPE" == linux* ]]; then
sed_cmd="1i$header"
sed -i "$sed_cmd" $f
else
sed_cmd="1 i\\
$header
"
sed -i '' "$sed_cmd" $f
fi
fi
done
# clear existing comp cache
rm -rf ~/.zcomp*