Skip to content

Commit

Permalink
Merge pull request #281 from TheQueasle/253-autocomplete-install
Browse files Browse the repository at this point in the history
First pass at adding in the autocomplete files to the installer script
  • Loading branch information
schollz authored Oct 4, 2020
2 parents 6264905 + 4675976 commit 669920d
Showing 1 changed file with 37 additions and 2 deletions.
39 changes: 37 additions & 2 deletions src/install/default.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
# Issues: https://github.com/schollz/croc/issues
#
# CREATED: 08/10/2019 16:41
# REVISION: 0.9.1
# REVISION: 0.9.2
#===============================================================================
set -o nounset # Treat unset variables as an error

Expand Down Expand Up @@ -521,12 +521,21 @@ main() {
local extract_file_rcode
local install_file_rcode
local create_prefix_rcode
local bash_autocomplete_file
local bash_autocomplete_prefix
local zsh_autocomplete_file
local zsh_autocomplete_prefix
local autocomplete_install_rcode

croc_bin_name="croc"
croc_version="8.3.2"
croc_dl_ext="tar.gz"
croc_base_url="https://github.com/schollz/croc/releases/download"
prefix="${1}"
bash_autocomplete_file="bash_autocomplete"
bash_autocomplete_prefix="/etc/bash_completion.d"
zsh_autocomplete_file="zsh_autocomplete"
zsh_autocomplete_prefix="/etc/zsh"

print_banner
print_message "== Install prefix set to ${prefix}" "info"
Expand Down Expand Up @@ -686,7 +695,8 @@ main() {
"Windows" ) install_file_cygwin "${tmpdir}/${croc_bin_name}" "${prefix}/";
install_file_rcode="${?}";;
esac
if [[ "${install_file_rcode}" == "0" ]]; then

if [[ "${install_file_rcode}" == "0" ]] ; then
print_message "== Installed ${croc_bin_name} to ${prefix}/" "ok"
elif [[ "${install_file_rcode}" == "1" ]]; then
print_message "== Failed to install ${croc_bin_name}" "error"
Expand All @@ -702,6 +712,31 @@ main() {
exit 1
fi

case "$(basename ${SHELL})" in
"bash" ) install_file_linux "${tmpdir}/${bash_autocomplete_file}" "${bash_autocomplete_prefix}/croc";
autocomplete_install_rcode="${?}";;
"zsh" ) install_file_linux "${tmpdir}/${zsh_autocomplete_file}" "${zsh_autocomplete_prefix}/zsh_autocomplete_croc";
autocomplete_install_rcode="${?}";
print_message "== You will need to add the following to your ~/.zshrc to enable autocompletion" "info";
print_message "\nPROG=croc\n_CLI_ZSH_AUTOCOMPLETE_HACK=1\nsource /etc/zsh/zsh_autocomplete_croc\n" "info";;
esac

if [[ "${autocomplete_install_rcode}" == "0" ]] ; then
print_message "== Installed autocompletions for $(basename "${SHELL}")" "ok"
elif [[ "${autocomplete_install_rcode}" == "1" ]]; then
print_message "== Failed to install ${bash_autocomplete_file}" "error"
exit 1
elif [[ "${autocomplete_install_rcode}" == "20" ]]; then
print_message "== Failed to locate 'install' command" "error"
exit 1
elif [[ "${autocomplete_install_rcode}" == "21" ]]; then
print_message "== Failed to locate 'sudo' command" "error"
exit 1
else
print_message "== Install attempt returned an unexpected value of ${autocomplete_install_rcode}" "error"
exit 1
fi

print_message "== Installation complete" "ok"

exit 0
Expand Down

0 comments on commit 669920d

Please sign in to comment.