Skip to content

Instantly share code, notes, and snippets.

@Akianonymus
Created June 22, 2020 08:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Akianonymus/56e80cc1aa469c5b74d41273e202cadd to your computer and use it in GitHub Desktop.
Save Akianonymus/56e80cc1aa469c5b74d41273e202cadd to your computer and use it in GitHub Desktop.
#!/usr/bin/env bash
CURRENT_SHELL="${SHELL##*/}"
case "$CURRENT_SHELL" in
'bash') SHELL_FILE="$(ls "$HOME"/.bashrc)" ;;
'zsh') SHELL_FILE="$(ls "$HOME"/.zshrc)" ;;
*) echo "Not a supported shell" && exit 1 ;;
esac
case "$(uname -m)" in
'armv7l') ARCH=arm ;;
'i386') ARCH=386 ;;
'x86_64') ARCH=amd64 ;;
*) echo "Not supported architecture" && exit 1 ;;
esac
if ! type -p shfmt > /dev/null 2>&1; then
printf 'shfmt not installed\n'
printf 'Fetching latest release...\n'
LATEST_RELEASE="$(ver="$(curl https://github.com/mvdan/sh/releases.atom -s | grep '<title>v.*</title>' -m1)" && regex="(>.*<)" && [[ $ver =~ $regex ]] && echo "${BASH_REMATCH[1]:1:-1}")"
printf "\033[1A\033[2K"
printf "Latest Release: %s \\n" "$LATEST_RELEASE"
LINK=https://github.com/mvdan/sh/releases/download/"$LATEST_RELEASE"/shfmt_"$LATEST_RELEASE"_linux_"$ARCH"
mkdir -p "$HOME"/.shfmt
printf "Architecture=%s detected, downloading...\\n" "$ARCH"
wget --show-progress -q "$LINK" -O "$HOME"/.shfmt/shfmt
chmod +x "$HOME"/.shfmt/shfmt
PATH="$HOME/.shfmt/:$PATH"
export PATH
echo -e "\nPATH=$HOME/.shfmt/:$PATH" >> "$SHELL_FILE"
echo "shfmt installed"
echo "shfmt --help"
else
echo "shfmt already installed"
echo "Path: $(type -p shfmt)"
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment