File tree Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Expand file tree Collapse file tree 1 file changed +31
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,35 @@ get_download_url() {
4949 cut -d' "' -f4
5050}
5151
52+ # get the user's shell (as portably as possible)
53+ # and print out the command to enable tab completion
54+ emit_completion_command () {
55+ local shell file
56+
57+ if command -v getent > /dev/null; then
58+ shell=$( getent passwd " ${USER} " | cut -d: -f7)
59+ elif command -v finger > /dev/null; then
60+ shell=$( finger " ${USER} " | sed -nE ' /.*Shell: / { s///; s/ .*//; p; }' )
61+ elif [[ -f /etc/passwd ]]; then
62+ shell=$( awk -F: -v u=" ${USER} " ' $1 == u {print $7}' /etc/passwd)
63+ fi
64+
65+ if [[ -z " ${shell} " ]]; then
66+ # could not detect the shell
67+ return
68+ fi
69+
70+ file=" bin/completions/configlet.$( basename " ${shell} " ) "
71+ if [[ -f " ${file} " && -r " ${file} " ]]; then
72+ case " ${shell} " in
73+ bash | fish) echo " Enable tab completions: source ${file} " ;;
74+ zsh)
75+ : # is there more to do here than the above?
76+ ;;
77+ esac
78+ fi
79+ }
80+
5281main () {
5382 if [[ -d ./bin ]]; then
5483 output_dir=" ./bin"
@@ -69,6 +98,8 @@ main() {
6998 esac
7099
71100 rm -f " ${output_path} "
101+
102+ emit_completion_command
72103}
73104
74105main
You can’t perform that action at this time.
0 commit comments