diff --git a/.ci/install.sh b/.ci/install.sh index a93d1c7..f9f1699 100755 --- a/.ci/install.sh +++ b/.ci/install.sh @@ -12,6 +12,35 @@ else exit 1 fi +INSTALL_DIR="$HOME/.fnm" + +# Parse Flags +parse_args() { + while [[ $# -gt 0 ]] + do + key="$1" + + case $key in + -d|--install-dir) + INSTALL_DIR="$2" + shift # past argument + shift # past value + ;; + -s|--skip-shell) + SKIP_SHELL="true" + shift # past argument + ;; + *) + echo "Unrecognized argument $key" + exit 1 + ;; + esac + done +} + +parse_args "$@" + + get_latest_release() { # Taken from https://gist.github.com/lukechilds/a83e1d7127b78fef38c2914c4ececc3c curl --silent "https://api.github.com/repos/$1/releases/latest" | # Get latest release from GitHub api @@ -26,11 +55,11 @@ download_fnm() { echo "Downloading $URL..." - mkdir -p $HOME/.fnm &> /dev/null + mkdir -p $INSTALL_DIR &> /dev/null curl --progress-bar -L $URL -o $DOWNLOAD_DIR/$FILENAME.zip unzip -q $DOWNLOAD_DIR/$FILENAME.zip -d $DOWNLOAD_DIR - mv $DOWNLOAD_DIR/$FILENAME/fnm $HOME/.fnm/fnm - chmod u+x $HOME/.fnm/fnm + mv $DOWNLOAD_DIR/$FILENAME/fnm $INSTALL_DIR/fnm + chmod u+x $INSTALL_DIR/fnm } check_dependencies() { @@ -112,4 +141,6 @@ setup_shell() { check_dependencies download_fnm -setup_shell +if [ "$SKIP_SHELL" != "true" ]; then + setup_shell +fi diff --git a/README.md b/README.md index 221fec9..1bc7c9f 100644 --- a/README.md +++ b/README.md @@ -28,6 +28,21 @@ For `bash`, `zsh` and `fish` shells, there's an [automatic installation script]( curl https://raw.githubusercontent.com/Schniz/fnm/master/.ci/install.sh | bash ``` +#### Parameters + +`--install-dir` + +Set a custom directory for fnm to be installed. The default is `$HOME/.fnm`. + +`--skip-shell` + +Skip appending shell specific loader to shell config file, based on the current user shell, defined in `$SHELL`. e.g. for Bash, `$HOME/.bashrc`. `$HOME/.zshrc` for Zsh. For Fish - `$HOME/.config/fish/config.fish` + +Example: +```bash +curl https://raw.githubusercontent.com/Schniz/fnm/master/.ci/install.sh | bash --install-dir "./.fnm" --skip-shell +``` + ### Manually - Download the [latest release binary](https://github.com/Schniz/fnm/releases) for your system