Skip to content

Instantly share code, notes, and snippets.

@holly
Last active February 28, 2026 12:19
Show Gist options
  • Select an option

  • Save holly/2bd195b9e72b2978d2d3e95102f51fd7 to your computer and use it in GitHub Desktop.

Select an option

Save holly/2bd195b9e72b2978d2d3e95102f51fd7 to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
set -e
set -u
set -o pipefail
set -C
ARCH=$(uname -m)
GITHUB_API_URL="https://api.github.com/repos/fish-shell/fish-shell/releases/latest"
FISH_VERSION=$(curl -sfL $GITHUB_API_URL | jq -r ".tag_name")
DOWNLOAD_URL="https://github.com/fish-shell/fish-shell/releases/download/${FISH_VERSION}/fish-${FISH_VERSION}-linux-${ARCH}.tar.xz"
INSTALL_DIR="/usr/local/bin"
INSTALL_PATH="${INSTALL_DIR}/fish"
_is_root() {
if [[ $(id -u) -eq 0 ]]; then
return 0
else
return 1
fi
}
_execute() {
local BASH=$(which bash)
if ! _is_root; then
BASH="sudo $BASH"
fi
$BASH -c "$@"
}
_fish_local_version() {
$INSTALL_PATH --version | perl -nlpe 's/^(.*)\s+([\d\.]+)$/$2/'
}
install() {
if [[ -f $INSTALL_PATH ]]; then
echo "$INSTALL_PATH is already exists."
exit 1
fi
_execute "curl -sfL $DOWNLOAD_URL | tar -C $INSTALL_DIR -pxvJf -"
}
forceinstall() {
uninstall
echo "nvim force install."
echo ""
install
}
update() {
if [[ ! -f $INSTALL_PATH ]]; then
echo "$INSTALL_PATH is not exists."
exit 1
fi
FISH_LOCAL_VERSION=$(_fish_local_version)
if [[ "$FISH_LOCAL_VERSION" = "$FISH_VERSION" ]];then
echo "fish local version is $FISH_LOCAL_VERSION and fish latest version is $FISH_VERSION. skip."
exit
fi
forceinstall
}
uninstall() {
if [[ ! -f $INSTALL_PATH ]]; then
echo "$INSTALL_PATH is not exists."
exit 1
fi
_execute "rm -frv $INSTALL_PATH"
}
usage() {
echo "Usage: $0 [install|forceinstall|update|uninstall]"
exit 1
}
if [ $# -ne 1 ]; then
usage
fi
COMMAND=$1
case "$COMMAND" in
"install" ) install ;;
"forceinstall" ) forceinstall ;;
"update" ) update ;;
"uninstall" ) uninstall ;;
* ) usage;;
esac
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment