mirror of
https://github.com/starship/starship.git
synced 2024-11-22 08:14:10 +01:00
refactor: install.sh to improve usage and install instructions (#3025)
* Refactored the usage function to use printf Using printf to print the usage function instead of a here doc handles the formatting for us so it will be consistent across a wide variety of terminal emulators. Here docs also tend to mess up auto-formatters so removing it has that added benefit. * Made the install instructions their own function The function loops through simular install instructions so this way we won't have to repeat ourselves every time we add a new supported shell. * Set default config_file location The default location is based on the name of the shell. It is overwritten when needed. Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com> Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
This commit is contained in:
parent
7388c5a79e
commit
296718ce28
@ -115,36 +115,21 @@ unpack() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
usage() {
|
usage() {
|
||||||
cat <<EOT
|
printf "%s\n" \
|
||||||
install.sh [option]
|
"install.sh [option]" \
|
||||||
|
"" \
|
||||||
|
"Fetch and install the latest version of starship, if starship is already" \
|
||||||
|
"installed it will be updated to the latest version."
|
||||||
|
|
||||||
Fetch and install the latest version of starship, if starship is already
|
printf "\n%s\n" "Options"
|
||||||
installed it will be updated to the latest version.
|
printf "\t%s\n\t\t%s\n\n" \
|
||||||
|
"-V, --verbose" "Enable verbose output for the installer" \
|
||||||
Options
|
"-f, -y, --force, --yes" "Skip the confirmation prompt during installation" \
|
||||||
|
"-p, --platform" "Override the platform identified by the installer [default: ${PLATFORM}]" \
|
||||||
-V, --verbose
|
"-b, --bin-dir" "Override the bin installation directory [default: ${BIN_DIR}]" \
|
||||||
Enable verbose output for the installer
|
"-a, --arch" "Override the architecture identified by the installer [default: ${ARCH}]" \
|
||||||
|
"-B, --base-url" "Override the base URL used for downloading releases [default: ${BASE_URL}]" \
|
||||||
-f, -y, --force, --yes
|
"-h, --help" "Dispays this help message"
|
||||||
Skip the confirmation prompt during installation
|
|
||||||
|
|
||||||
-p, --platform
|
|
||||||
Override the platform identified by the installer [default: ${PLATFORM}]
|
|
||||||
|
|
||||||
-b, --bin-dir
|
|
||||||
Override the bin installation directory [default: ${BIN_DIR}]
|
|
||||||
|
|
||||||
-a, --arch
|
|
||||||
Override the architecture identified by the installer [default: ${ARCH}]
|
|
||||||
|
|
||||||
-B, --base-url
|
|
||||||
Override the base URL used for downloading releases [default: ${BASE_URL}]
|
|
||||||
|
|
||||||
-h, --help
|
|
||||||
Dispays this help message
|
|
||||||
|
|
||||||
EOT
|
|
||||||
}
|
}
|
||||||
|
|
||||||
elevate_priv() {
|
elevate_priv() {
|
||||||
@ -288,6 +273,84 @@ check_bin_dir() {
|
|||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print_install() {
|
||||||
|
# if the shell does not fit the default case change the config file
|
||||||
|
# and or the config cmd variable
|
||||||
|
for s in "bash" "zsh" "ion" "tcsh" "xonsh" "fish"
|
||||||
|
do
|
||||||
|
# shellcheck disable=SC2088
|
||||||
|
# we don't want these '~' expanding
|
||||||
|
config_file="~/.${s}rc"
|
||||||
|
config_cmd="eval \"\$(starship init ${s})\""
|
||||||
|
|
||||||
|
case ${s} in
|
||||||
|
ion )
|
||||||
|
# shellcheck disable=SC2088
|
||||||
|
config_file="~/.config/ion/initrc"
|
||||||
|
config_cmd="eval \$(starship init ${s})"
|
||||||
|
;;
|
||||||
|
fish )
|
||||||
|
# shellcheck disable=SC2088
|
||||||
|
config_file="~/.config/fish/config.fish"
|
||||||
|
config_cmd="starship init fish | source"
|
||||||
|
;;
|
||||||
|
tcsh )
|
||||||
|
config_cmd="eval \`starship init ${s}\`"
|
||||||
|
;;
|
||||||
|
xonsh )
|
||||||
|
config_cmd="execx(\$(starship init xonsh))"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
|
||||||
|
printf " %s\n Add the following to the end of %s:\n\n\t%s\n\n" \
|
||||||
|
"${BOLD}${UNDERLINE}${s}${NO_COLOR}" \
|
||||||
|
"${BOLD}${config_file}${NO_COLOR}" \
|
||||||
|
"${config_cmd}"
|
||||||
|
done
|
||||||
|
|
||||||
|
for s in "elvish" "nushell"
|
||||||
|
do
|
||||||
|
|
||||||
|
warning="${BOLD}Warning${NO_COLOR}"
|
||||||
|
case ${s} in
|
||||||
|
elvish )
|
||||||
|
# shellcheck disable=SC2088
|
||||||
|
config_file="~/.elvish/rc.elv"
|
||||||
|
config_cmd="eval (starship init elvish)"
|
||||||
|
warning="${warning} Only elvish v0.15 or higher is supported."
|
||||||
|
;;
|
||||||
|
nushell )
|
||||||
|
# shellcheck disable=SC2088
|
||||||
|
config_file="your nu config file."
|
||||||
|
config_cmd="startup = [
|
||||||
|
\"mkdir ~/.cache/starship\",
|
||||||
|
\"starship init nu | save ~/.cache/starship/init.nu\",
|
||||||
|
\"source ~/.cache/starship/init.nu\"
|
||||||
|
]
|
||||||
|
prompt = \"starship_prompt\""
|
||||||
|
warning="${warning} This will change in the future.
|
||||||
|
Only nu version v0.33 or higher is supported.
|
||||||
|
You can check the location of this your config file by running config path in nu"
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
printf " %s\n %s\n Add the following to the end of %s:\n\n\t%s\n\n" \
|
||||||
|
"${BOLD}${UNDERLINE}${s}${NO_COLOR}" \
|
||||||
|
"${warning}" \
|
||||||
|
"${BOLD}${config_file}${NO_COLOR}" \
|
||||||
|
"${config_cmd}"
|
||||||
|
done
|
||||||
|
|
||||||
|
printf " %s\n Add the following to the end of %s:\n %s\n\n\t%s\n\n" \
|
||||||
|
"${BOLD}${UNDERLINE}PowerShell${NO_COLOR}" \
|
||||||
|
"${BOLD}Microsoft.PowerShell_profile.ps1${NO_COLOR}" \
|
||||||
|
"You can check the location of this file by querying the \$PROFILE variable in PowerShell.
|
||||||
|
Typically the path is ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 or ~/.config/powershell/Microsoft.PowerShell_profile.ps1 on -Nix." \
|
||||||
|
"Invoke-Expression (&starship init powershell)"
|
||||||
|
|
||||||
|
printf "\n"
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
is_build_available() {
|
is_build_available() {
|
||||||
arch="$1"
|
arch="$1"
|
||||||
platform="$2"
|
platform="$2"
|
||||||
@ -430,36 +493,7 @@ install "${EXT}"
|
|||||||
completed "Starship installed"
|
completed "Starship installed"
|
||||||
|
|
||||||
printf '\n'
|
printf '\n'
|
||||||
info "Please follow the steps for your shell to complete the installation:
|
info "Please follow the steps for your shell to complete the installation:"
|
||||||
|
|
||||||
${BOLD}${UNDERLINE}Bash${NO_COLOR}
|
print_install
|
||||||
Add the following to the end of ${BOLD}~/.bashrc${NO_COLOR}:
|
|
||||||
|
|
||||||
eval \"\$(starship init bash)\"
|
|
||||||
|
|
||||||
${BOLD}${UNDERLINE}Fish${NO_COLOR}
|
|
||||||
Add the following to the end of ${BOLD}~/.config/fish/config.fish${NO_COLOR}:
|
|
||||||
|
|
||||||
starship init fish | source
|
|
||||||
|
|
||||||
${BOLD}${UNDERLINE}Zsh${NO_COLOR}
|
|
||||||
Add the following to the end of ${BOLD}~/.zshrc${NO_COLOR}:
|
|
||||||
|
|
||||||
eval \"\$(starship init zsh)\"
|
|
||||||
|
|
||||||
${BOLD}${UNDERLINE}Ion${NO_COLOR}
|
|
||||||
Add the following to the end of ${BOLD}~/.config/ion/initrc${NO_COLOR}:
|
|
||||||
|
|
||||||
eval \$(starship init ion)
|
|
||||||
|
|
||||||
${BOLD}${UNDERLINE}Tcsh${NO_COLOR}
|
|
||||||
Add the following to the end of ${BOLD}~/.tcshrc${NO_COLOR}:
|
|
||||||
|
|
||||||
eval \`starship init tcsh\`
|
|
||||||
|
|
||||||
${BOLD}${UNDERLINE}Xonsh${NO_COLOR}
|
|
||||||
Add the following to the end of ${BOLD}~/.xonshrc${NO_COLOR}:
|
|
||||||
|
|
||||||
execx($(starship init xonsh))
|
|
||||||
|
|
||||||
"
|
|
||||||
|
Loading…
Reference in New Issue
Block a user