summaryrefslogtreecommitdiff
path: root/tools/install.sh
diff options
context:
space:
mode:
authorTuowen Zhao <ztuowen@gmail.com>2022-04-02 13:24:35 -0500
committerTuowen Zhao <ztuowen@gmail.com>2022-04-02 13:24:35 -0500
commit2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945 (patch)
tree99add95300f57806b89bd885a5f5322ce9f9ac1a /tools/install.sh
parentcae9a2b797649379e865e6bd73bc67e294e4ac77 (diff)
parent53863e7b3ff0c2e2816e90dab3d870adebdf49c7 (diff)
downloadzsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.tar.gz
zsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.tar.bz2
zsh-2023d3ab658fe8ed4dd4ca33cd5974ab8f0ad945.zip
Merge remote-tracking branch 'origin/master'
Diffstat (limited to 'tools/install.sh')
-rwxr-xr-xtools/install.sh17
1 files changed, 14 insertions, 3 deletions
diff --git a/tools/install.sh b/tools/install.sh
index e64e39063..495ad2c11 100755
--- a/tools/install.sh
+++ b/tools/install.sh
@@ -42,13 +42,19 @@ set -e
# $USER is defined by login(1) which is not always executed (e.g. containers)
# POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html
USER=${USER:-$(id -u -n)}
+# $HOME is defined at the time of login, but it could be unset. If it is unset,
+# a tilde by itself (~) will not be expanded to the current user's home directory.
+# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
+HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
+# macOS does not have getent, but this works even if $HOME is unset
+HOME="${HOME:-$(eval echo ~$USER)}"
# Track if $ZSH was provided
custom_zsh=${ZSH:+yes}
# Default settings
-ZSH=${ZSH:-~/.oh-my-zsh}
+ZSH="${ZSH:-$HOME/.oh-my-zsh}"
REPO=${REPO:-ohmyzsh/ohmyzsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
BRANCH=${BRANCH:-master}
@@ -268,7 +274,7 @@ setup_ohmyzsh() {
fi
# Manual clone with git config options to support git < v1.7.2
- git init "$ZSH" && cd "$ZSH" \
+ git init --quiet "$ZSH" && cd "$ZSH" \
&& git config core.eol lf \
&& git config core.autocrlf false \
&& git config fsck.zeroPaddedFilemode ignore \
@@ -279,10 +285,15 @@ setup_ohmyzsh() {
&& git remote add origin "$REMOTE" \
&& git fetch --depth=1 origin \
&& git checkout -b "$BRANCH" "origin/$BRANCH" || {
- rm -rf "$ZSH"
+ [ ! -d "$ZSH" ] || {
+ cd -
+ rm -rf "$ZSH" 2>/dev/null
+ }
fmt_error "git clone of oh-my-zsh repo failed"
exit 1
}
+ # Exit installation directory
+ cd -
echo
}