feat(install): use user-writable installation directories by default

relates to #5284
This commit is contained in:
Jan De Dobbeleer 2024-07-17 08:23:08 +02:00 committed by Jan De Dobbeleer
parent 024c8b6ed5
commit 55113b8e66

View file

@ -24,7 +24,7 @@ help() {
echo "Syntax: install.sh [-h|d|t]"
echo "options:"
echo "-h Print this help."
echo "-d Specify the installation directory. Defaults to /usr/local/bin or the directory where oh-my-posh is installed."
echo "-d Specify the installation directory. Defaults to $HOME/bin, $HOME/.local/bin or the directory where oh-my-posh is installed."
echo "-t Specify the themes installation directory. Defaults to the oh-my-posh cache directory."
echo
}
@ -74,9 +74,22 @@ set_install_directory() {
install_dir=$(dirname $real_dir)
info "Oh My Posh is already installed, updating existing installation in:"
info " ${install_dir}"
else
install_dir="/usr/local/bin"
return 0
fi
# check if $HOME/bin exists and is writable
if [ -d "$HOME/bin" ] && [ -w "$HOME/bin" ]; then
install_dir="$HOME/bin"
return 0
fi
# check if $HOME/.local/bin exists and is writable
if ([ -d "$HOME/.local/bin" ] && [ -w "$HOME/.local/bin" ]) || mkdir "$HOME/.local/bin"; then
install_dir="$HOME/.local/bin"
return 0
fi
error "Cannot determine installation directory. Please specify a directory and try again: \ncurl -s https://ohmyposh.dev/install.sh | bash -s -- -d {directory}"
}
validate_install_directory() {
@ -102,7 +115,7 @@ validate_install_directory() {
)
if [ "${good}" != "1" ]; then
warn "Installation directory ${install_dir} is not in your \$PATH"
warn "Installation directory ${install_dir} is not in your \$PATH, add it using \nexport PATH=\$PATH:${install_dir}"
fi
}