From bc6b16c014f34632a96d116ba27f5d6ede53253a Mon Sep 17 00:00:00 2001 From: William Melody Date: Thu, 16 Apr 2020 11:45:45 -0700 Subject: [PATCH] Improve `hosts-completion` script locations. --- etc/README.md | 4 ++-- scripts/hosts-completion | 36 ++++++++++++++++++++++-------------- 2 files changed, 24 insertions(+), 16 deletions(-) diff --git a/etc/README.md b/etc/README.md index 5686f72..f6dfac3 100644 --- a/etc/README.md +++ b/etc/README.md @@ -15,7 +15,7 @@ check the environment and attempt to install completions. If it's successful, you should see a message similar to: ```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 ``` @@ -51,7 +51,7 @@ Use the `check` subcommand to determine if completion scripts are installed: ```bash > ./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 ``` diff --git a/scripts/hosts-completion b/scripts/hosts-completion index fccd326..6f0c468 100755 --- a/scripts/hosts-completion +++ b/scripts/hosts-completion @@ -82,10 +82,10 @@ _check() { if [[ -n "${_bash_completion_path:-}" ]] && [[ -d "${_bash_completion_path}" ]] && [[ -w "${_bash_completion_path}" ]] && - [[ -e "${_bash_completion_path}/hosts-completion.bash" ]] + [[ -e "${_bash_completion_path}/hosts" ]] then _exists=1 - printf "Exists: %s\\n" "${_bash_completion_path}/hosts-completion.bash" + printf "Exists: %s\\n" "${_bash_completion_path}/hosts" fi local _zsh_completion_path="/usr/local/share/zsh/site-functions" @@ -109,13 +109,18 @@ _install() { if [[ -n "${_bash_completion_path:-}" ]] && [[ -d "${_bash_completion_path}" ]] && [[ -w "${_bash_completion_path}" ]] && - [[ ! -e "${_bash_completion_path}/hosts-completion.bash" ]] + [[ ! -e "${_bash_completion_path}/hosts" ]] then cp \ "${_MY_DIR}/../etc/hosts-completion.bash" \ - "${_bash_completion_path}/hosts-completion.bash" - printf "Completion installed: %s\\n" \ - "${_bash_completion_path}/hosts-completion.bash" + "${_bash_completion_path}/hosts" + printf "Completion installed: %s\\n" "${_bash_completion_path}/hosts" + + # Cleanup old completion script. + if [[ -e "${_bash_completion_path}/hosts-completion.bash" ]] + then + rm "${_bash_completion_path}/hosts-completion.bash" + fi fi local _zsh_completion_path="/usr/local/share/zsh/site-functions" @@ -127,8 +132,7 @@ _install() { cp \ "${_MY_DIR}/../etc/hosts-completion.zsh" \ "${_zsh_completion_path}/_hosts" - printf "Completion installed: %s\\n" \ - "${_zsh_completion_path}/_hosts" + printf "Completion installed: %s\\n" "${_zsh_completion_path}/_hosts" fi } @@ -140,11 +144,16 @@ _uninstall() { if [[ -n "${_bash_completion_path:-}" ]] && [[ -d "${_bash_completion_path}" ]] && [[ -w "${_bash_completion_path}" ]] && - [[ -e "${_bash_completion_path}/hosts-completion.bash" ]] + [[ -e "${_bash_completion_path}/hosts" ]] then - rm "${_bash_completion_path}/hosts-completion.bash" - printf "Completion removed: %s\\n" \ - "${_bash_completion_path}/hosts-completion.bash" + rm "${_bash_completion_path}/hosts" + printf "Completion removed: %s\\n" "${_bash_completion_path}/hosts" + + # Cleanup old completion script. + if [[ -e "${_bash_completion_path}/hosts-completion.bash" ]] + then + rm "${_bash_completion_path}/hosts-completion.bash" + fi fi local _zsh_completion_path="/usr/local/share/zsh/site-functions" @@ -154,8 +163,7 @@ _uninstall() { [[ -e "${_zsh_completion_path}/_hosts" ]] then rm "${_zsh_completion_path}/_hosts" - printf "Completion removed: %s\\n" \ - "${_zsh_completion_path}/_hosts" + printf "Completion removed: %s\\n" "${_zsh_completion_path}/_hosts" fi }