@@ -130,7 +130,7 @@ write_completion() {
130130}
131131
132132setup_bash_completions () {
133- local bin_path=" $1 " os=" $2 " xdg_data=" $3 "
133+ local bin_path=" $1 " os=" $2 " xdg_data=" $3 " user_only= " $4 "
134134 local sys_dir
135135 if [[ " $os " == " darwin" ]]; then
136136 local brew_prefix=" /usr/local"
@@ -140,7 +140,7 @@ setup_bash_completions() {
140140 sys_dir=" /usr/share/bash-completion/completions"
141141 fi
142142
143- if write_completion " $bin_path " bash " ${sys_dir} /aicr" ; then
143+ if [[ " $user_only " != " true " ]] && write_completion " $bin_path " bash " ${sys_dir} /aicr" ; then
144144 ok " Bash completions installed"
145145 elif write_completion " $bin_path " bash " ${xdg_data} /bash-completion/completions/aicr" ; then
146146 ok " Bash completions installed (user-local)"
@@ -150,7 +150,7 @@ setup_bash_completions() {
150150}
151151
152152setup_zsh_completions () {
153- local bin_path=" $1 " os=" $2 " xdg_data=" $3 "
153+ local bin_path=" $1 " os=" $2 " xdg_data=" $3 " user_only= " $4 "
154154 local sys_dir
155155 if [[ " $os " == " darwin" ]]; then
156156 local brew_prefix=" /usr/local"
@@ -160,7 +160,7 @@ setup_zsh_completions() {
160160 sys_dir=" /usr/local/share/zsh/site-functions"
161161 fi
162162
163- if write_completion " $bin_path " zsh " ${sys_dir} /_aicr" ; then
163+ if [[ " $user_only " != " true " ]] && write_completion " $bin_path " zsh " ${sys_dir} /_aicr" ; then
164164 ok " Zsh completions installed"
165165 elif write_completion " $bin_path " zsh " ${xdg_data} /zsh/site-functions/_aicr" ; then
166166 ok " Zsh completions installed (user-local)"
@@ -170,11 +170,11 @@ setup_zsh_completions() {
170170}
171171
172172setup_fish_completions () {
173- local bin_path=" $1 "
173+ local bin_path=" $1 " user_only= " $2 "
174174 local sys_dir=" /usr/share/fish/vendor_completions.d"
175175 local user_dir=" ${XDG_CONFIG_HOME:- $HOME / .config} /fish/completions"
176176
177- if [[ -d " $sys_dir " ]] && write_completion " $bin_path " fish " ${sys_dir} /aicr.fish" ; then
177+ if [[ " $user_only " != " true " ]] && [[ -d " $sys_dir " ]] && write_completion " $bin_path " fish " ${sys_dir} /aicr.fish" ; then
178178 ok " Fish completions installed"
179179 elif [[ -d " ${user_dir%/* } " ]] && write_completion " $bin_path " fish " ${user_dir} /aicr.fish" ; then
180180 ok " Fish completions installed (user-local)"
@@ -188,14 +188,19 @@ setup_completions() {
188188 fi
189189
190190 local bin_path=" ${INSTALL_DIR} /${BIN_NAME} "
191- local os xdg_data
191+ local os xdg_data user_only= " false "
192192 os=$( get_os)
193193 xdg_data=" ${XDG_DATA_HOME:- $HOME / .local/ share} "
194+
195+ # If the binary install did not need sudo, skip system completion dirs
196+ # to avoid unexpected sudo prompts (e.g., ./install -d ~/bin).
197+ [[ " ${USED_SUDO:- false} " == " false" ]] && user_only=" true"
198+
194199 step " Setting up shell completions..."
195200
196- setup_bash_completions " $bin_path " " $os " " $xdg_data "
197- setup_zsh_completions " $bin_path " " $os " " $xdg_data "
198- setup_fish_completions " $bin_path "
201+ setup_bash_completions " $bin_path " " $os " " $xdg_data " " $user_only "
202+ setup_zsh_completions " $bin_path " " $os " " $xdg_data " " $user_only "
203+ setup_fish_completions " $bin_path " " $user_only "
199204}
200205
201206# ==============================================================================
@@ -389,11 +394,13 @@ main() {
389394 chmod +x " ${temp_dir} /${BIN_NAME} "
390395 step " Installing $BIN_NAME to $INSTALL_DIR "
391396 mkdir -p " $INSTALL_DIR "
397+ USED_SUDO=false
392398 if [[ -w " $INSTALL_DIR " ]]; then
393399 mv " ${temp_dir} /${BIN_NAME} " " ${INSTALL_DIR} /${BIN_NAME} "
394400 [[ -f " ${temp_dir} /${BIN_NAME} -attestation.sigstore.json" ]] && \
395401 mv " ${temp_dir} /${BIN_NAME} -attestation.sigstore.json" " ${INSTALL_DIR} /${BIN_NAME} -attestation.sigstore.json"
396402 else
403+ USED_SUDO=true
397404 sudo mv " ${temp_dir} /${BIN_NAME} " " ${INSTALL_DIR} /${BIN_NAME} "
398405 [[ -f " ${temp_dir} /${BIN_NAME} -attestation.sigstore.json" ]] && \
399406 sudo mv " ${temp_dir} /${BIN_NAME} -attestation.sigstore.json" " ${INSTALL_DIR} /${BIN_NAME} -attestation.sigstore.json"
0 commit comments