Improve `hosts-completion` script locations.

This commit is contained in:
William Melody 2020-04-16 11:45:45 -07:00
parent 4088591bb2
commit bc6b16c014
2 changed files with 24 additions and 16 deletions

View File

@ -15,7 +15,7 @@ check the environment and attempt to install completions. If it's successful,
you should see a message similar to: you should see a message similar to:
```bash ```bash
Completion installed: /usr/local/etc/bash_completion.d/hosts-completion.bash Completion installed: /usr/local/etc/bash_completion.d/hosts
Completion installed: /usr/local/share/zsh/site-functions/_hosts Completion installed: /usr/local/share/zsh/site-functions/_hosts
``` ```
@ -51,7 +51,7 @@ Use the `check` subcommand to determine if completion scripts are installed:
```bash ```bash
> ./hosts-completion check > ./hosts-completion check
Exists: /usr/local/etc/bash_completion.d/hosts-completion.bash Exists: /usr/local/etc/bash_completion.d/hosts
Exists: /usr/local/share/zsh/site-functions/_hosts Exists: /usr/local/share/zsh/site-functions/_hosts
``` ```

View File

@ -82,10 +82,10 @@ _check() {
if [[ -n "${_bash_completion_path:-}" ]] && if [[ -n "${_bash_completion_path:-}" ]] &&
[[ -d "${_bash_completion_path}" ]] && [[ -d "${_bash_completion_path}" ]] &&
[[ -w "${_bash_completion_path}" ]] && [[ -w "${_bash_completion_path}" ]] &&
[[ -e "${_bash_completion_path}/hosts-completion.bash" ]] [[ -e "${_bash_completion_path}/hosts" ]]
then then
_exists=1 _exists=1
printf "Exists: %s\\n" "${_bash_completion_path}/hosts-completion.bash" printf "Exists: %s\\n" "${_bash_completion_path}/hosts"
fi fi
local _zsh_completion_path="/usr/local/share/zsh/site-functions" local _zsh_completion_path="/usr/local/share/zsh/site-functions"
@ -109,13 +109,18 @@ _install() {
if [[ -n "${_bash_completion_path:-}" ]] && if [[ -n "${_bash_completion_path:-}" ]] &&
[[ -d "${_bash_completion_path}" ]] && [[ -d "${_bash_completion_path}" ]] &&
[[ -w "${_bash_completion_path}" ]] && [[ -w "${_bash_completion_path}" ]] &&
[[ ! -e "${_bash_completion_path}/hosts-completion.bash" ]] [[ ! -e "${_bash_completion_path}/hosts" ]]
then then
cp \ cp \
"${_MY_DIR}/../etc/hosts-completion.bash" \ "${_MY_DIR}/../etc/hosts-completion.bash" \
"${_bash_completion_path}/hosts-completion.bash" "${_bash_completion_path}/hosts"
printf "Completion installed: %s\\n" \ printf "Completion installed: %s\\n" "${_bash_completion_path}/hosts"
"${_bash_completion_path}/hosts-completion.bash"
# Cleanup old completion script.
if [[ -e "${_bash_completion_path}/hosts-completion.bash" ]]
then
rm "${_bash_completion_path}/hosts-completion.bash"
fi
fi fi
local _zsh_completion_path="/usr/local/share/zsh/site-functions" local _zsh_completion_path="/usr/local/share/zsh/site-functions"
@ -127,8 +132,7 @@ _install() {
cp \ cp \
"${_MY_DIR}/../etc/hosts-completion.zsh" \ "${_MY_DIR}/../etc/hosts-completion.zsh" \
"${_zsh_completion_path}/_hosts" "${_zsh_completion_path}/_hosts"
printf "Completion installed: %s\\n" \ printf "Completion installed: %s\\n" "${_zsh_completion_path}/_hosts"
"${_zsh_completion_path}/_hosts"
fi fi
} }
@ -140,11 +144,16 @@ _uninstall() {
if [[ -n "${_bash_completion_path:-}" ]] && if [[ -n "${_bash_completion_path:-}" ]] &&
[[ -d "${_bash_completion_path}" ]] && [[ -d "${_bash_completion_path}" ]] &&
[[ -w "${_bash_completion_path}" ]] && [[ -w "${_bash_completion_path}" ]] &&
[[ -e "${_bash_completion_path}/hosts-completion.bash" ]] [[ -e "${_bash_completion_path}/hosts" ]]
then then
rm "${_bash_completion_path}/hosts-completion.bash" rm "${_bash_completion_path}/hosts"
printf "Completion removed: %s\\n" \ printf "Completion removed: %s\\n" "${_bash_completion_path}/hosts"
"${_bash_completion_path}/hosts-completion.bash"
# Cleanup old completion script.
if [[ -e "${_bash_completion_path}/hosts-completion.bash" ]]
then
rm "${_bash_completion_path}/hosts-completion.bash"
fi
fi fi
local _zsh_completion_path="/usr/local/share/zsh/site-functions" local _zsh_completion_path="/usr/local/share/zsh/site-functions"
@ -154,8 +163,7 @@ _uninstall() {
[[ -e "${_zsh_completion_path}/_hosts" ]] [[ -e "${_zsh_completion_path}/_hosts" ]]
then then
rm "${_zsh_completion_path}/_hosts" rm "${_zsh_completion_path}/_hosts"
printf "Completion removed: %s\\n" \ printf "Completion removed: %s\\n" "${_zsh_completion_path}/_hosts"
"${_zsh_completion_path}/_hosts"
fi fi
} }