diff --git a/README.md b/README.md index 9438dc4..1a82f46 100644 --- a/README.md +++ b/README.md @@ -55,6 +55,12 @@ Use the script to install the latest version directly from this repo (independen wget -qO- https://git.io/papirus-folders-install | sh ``` +To install papirus-folders to **home directory** using the following command: + +``` +wget -qO- https://git.io/papirus-folders-install | env PREFIX=$HOME/.local sh +``` + To install papirus-folders on **BSD systems** using the following command: ``` diff --git a/install.sh b/install.sh index 059caec..e2c0fc0 100755 --- a/install.sh +++ b/install.sh @@ -36,10 +36,18 @@ _msg() { echo "=>" "$@" } +_sudo() { + if [ -w "$PREFIX" ] || [ -w "$(dirname "$PREFIX")" ]; then + "$@" + else + sudo "$@" + fi +} + _rm() { # removes parent directories if empty - sudo rm -rf "$1" - sudo rmdir -p "$(dirname "$1")" 2>/dev/null || true + _sudo rm -rf "$1" + _sudo rmdir -p "$(dirname "$1")" 2>/dev/null || true } _download() { @@ -63,17 +71,17 @@ _install() { tag="${TAG#v}" _msg "Installing ..." - sudo mkdir -p "$PREFIX/bin" - sudo install -m 755 "$temp_dir/$gh_repo-$tag/$bin_name" \ + _sudo mkdir -p "$PREFIX/bin" + _sudo install -m 755 "$temp_dir/$gh_repo-$tag/$bin_name" \ "$PREFIX/bin/$bin_name" - sudo mkdir -p "$PREFIX/share/bash-completion/completions" - sudo install -m 644 "$temp_dir/$gh_repo-$tag/completion/$bin_name" \ + _sudo mkdir -p "$PREFIX/share/bash-completion/completions" + _sudo install -m 644 "$temp_dir/$gh_repo-$tag/completion/$bin_name" \ "$PREFIX/share/bash-completion/completions" if [ -d "$PREFIX/share/zsh/site-functions" ]; then - sudo install -m 644 "$temp_dir/$gh_repo-$tag/completion/_$bin_name" \ + _sudo install -m 644 "$temp_dir/$gh_repo-$tag/completion/_$bin_name" \ "$PREFIX/share/zsh/site-functions" elif [ -d "$PREFIX/share/zsh/vendor-completions" ]; then - sudo install -m 644 "$temp_dir/$gh_repo-$tag/completion/_$bin_name" \ + _sudo install -m 644 "$temp_dir/$gh_repo-$tag/completion/_$bin_name" \ "$PREFIX/share/zsh/vendor-completions" else : fi