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
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 1 |
+
#!/bin/sh
|
| 2 |
+
#
|
| 3 |
+
# This script should be run via curl:
|
| 4 |
+
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
| 5 |
+
# or via wget:
|
| 6 |
+
# sh -c "$(wget -qO- https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
| 7 |
+
# or via fetch:
|
| 8 |
+
# sh -c "$(fetch -o - https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
| 9 |
+
#
|
| 10 |
+
# As an alternative, you can first download the install script and run it afterwards:
|
| 11 |
+
# wget https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh
|
| 12 |
+
# sh install.sh
|
| 13 |
+
#
|
| 14 |
+
# You can tweak the install behavior by setting variables when running the script. For
|
| 15 |
+
# example, to change the path to the Oh My Zsh repository:
|
| 16 |
+
# ZSH=~/.zsh sh install.sh
|
| 17 |
+
#
|
| 18 |
+
# Respects the following environment variables:
|
| 19 |
+
# ZDOTDIR - path to Zsh dotfiles directory (default: unset). See [1][2]
|
| 20 |
+
# [1] https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZDOTDIR
|
| 21 |
+
# [2] https://zsh.sourceforge.io/Doc/Release/Files.html#index-ZDOTDIR_002c-use-of
|
| 22 |
+
# ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
|
| 23 |
+
# REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)
|
| 24 |
+
# REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS)
|
| 25 |
+
# BRANCH - branch to check out immediately after install (default: master)
|
| 26 |
+
#
|
| 27 |
+
# Other options:
|
| 28 |
+
# CHSH - 'no' means the installer will not change the default shell (default: yes)
|
| 29 |
+
# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes)
|
| 30 |
+
# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no)
|
| 31 |
+
#
|
| 32 |
+
# You can also pass some arguments to the install script to set some these options:
|
| 33 |
+
# --skip-chsh: has the same behavior as setting CHSH to 'no'
|
| 34 |
+
# --unattended: sets both CHSH and RUNZSH to 'no'
|
| 35 |
+
# --keep-zshrc: sets KEEP_ZSHRC to 'yes'
|
| 36 |
+
# For example:
|
| 37 |
+
# sh install.sh --unattended
|
| 38 |
+
# or:
|
| 39 |
+
# sh -c "$(curl -fsSL https://raw.githubusercontent.com/ohmyzsh/ohmyzsh/master/tools/install.sh)" "" --unattended
|
| 40 |
+
#
|
| 41 |
+
set -e
|
| 42 |
+
|
| 43 |
+
# Make sure important variables exist if not already defined
|
| 44 |
+
#
|
| 45 |
+
# $USER is defined by login(1) which is not always executed (e.g. containers)
|
| 46 |
+
# POSIX: https://pubs.opengroup.org/onlinepubs/009695299/utilities/id.html
|
| 47 |
+
USER=${USER:-$(id -u -n)}
|
| 48 |
+
# $HOME is defined at the time of login, but it could be unset. If it is unset,
|
| 49 |
+
# a tilde by itself (~) will not be expanded to the current user's home directory.
|
| 50 |
+
# POSIX: https://pubs.opengroup.org/onlinepubs/009696899/basedefs/xbd_chap08.html#tag_08_03
|
| 51 |
+
HOME="${HOME:-$(getent passwd $USER 2>/dev/null | cut -d: -f6)}"
|
| 52 |
+
# macOS does not have getent, but this works even if $HOME is unset
|
| 53 |
+
HOME="${HOME:-$(eval echo ~$USER)}"
|
| 54 |
+
|
| 55 |
+
|
| 56 |
+
# Track if $ZSH was provided
|
| 57 |
+
custom_zsh=${ZSH:+yes}
|
| 58 |
+
|
| 59 |
+
# Use $zdot to keep track of where the directory is for zsh dotfiles
|
| 60 |
+
# To check if $ZDOTDIR was provided, explicitly check for $ZDOTDIR
|
| 61 |
+
zdot="${ZDOTDIR:-$HOME}"
|
| 62 |
+
|
| 63 |
+
# Default value for $ZSH
|
| 64 |
+
# a) if $ZDOTDIR is supplied and not $HOME: $ZDOTDIR/ohmyzsh
|
| 65 |
+
# b) otherwise, $HOME/.oh-my-zsh
|
| 66 |
+
if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then
|
| 67 |
+
ZSH="${ZSH:-$ZDOTDIR/ohmyzsh}"
|
| 68 |
+
fi
|
| 69 |
+
ZSH="${ZSH:-$HOME/.oh-my-zsh}"
|
| 70 |
+
|
| 71 |
+
# Default settings
|
| 72 |
+
REPO=${REPO:-mirrors/oh-my-zsh}
|
| 73 |
+
REMOTE=${REMOTE:-https://gitee.com/${REPO}.git}
|
| 74 |
+
BRANCH=${BRANCH:-master}
|
| 75 |
+
|
| 76 |
+
# Other options
|
| 77 |
+
CHSH=${CHSH:-yes}
|
| 78 |
+
RUNZSH=${RUNZSH:-yes}
|
| 79 |
+
KEEP_ZSHRC=${KEEP_ZSHRC:-no}
|
| 80 |
+
|
| 81 |
+
|
| 82 |
+
command_exists() {
|
| 83 |
+
command -v "$@" >/dev/null 2>&1
|
| 84 |
+
}
|
| 85 |
+
|
| 86 |
+
user_can_sudo() {
|
| 87 |
+
# Check if sudo is installed
|
| 88 |
+
command_exists sudo || return 1
|
| 89 |
+
# Termux can't run sudo, so we can detect it and exit the function early.
|
| 90 |
+
case "$PREFIX" in
|
| 91 |
+
*com.termux*) return 1 ;;
|
| 92 |
+
esac
|
| 93 |
+
# The following command has 3 parts:
|
| 94 |
+
#
|
| 95 |
+
# 1. Run `sudo` with `-v`. Does the following:
|
| 96 |
+
# • with privilege: asks for a password immediately.
|
| 97 |
+
# • without privilege: exits with error code 1 and prints the message:
|
| 98 |
+
# Sorry, user <username> may not run sudo on <hostname>
|
| 99 |
+
#
|
| 100 |
+
# 2. Pass `-n` to `sudo` to tell it to not ask for a password. If the
|
| 101 |
+
# password is not required, the command will finish with exit code 0.
|
| 102 |
+
# If one is required, sudo will exit with error code 1 and print the
|
| 103 |
+
# message:
|
| 104 |
+
# sudo: a password is required
|
| 105 |
+
#
|
| 106 |
+
# 3. Check for the words "may not run sudo" in the output to really tell
|
| 107 |
+
# whether the user has privileges or not. For that we have to make sure
|
| 108 |
+
# to run `sudo` in the default locale (with `LANG=`) so that the message
|
| 109 |
+
# stays consistent regardless of the user's locale.
|
| 110 |
+
#
|
| 111 |
+
! LANG= sudo -n -v 2>&1 | grep -q "may not run sudo"
|
| 112 |
+
}
|
| 113 |
+
|
| 114 |
+
# The [ -t 1 ] check only works when the function is not called from
|
| 115 |
+
# a subshell (like in `$(...)` or `(...)`, so this hack redefines the
|
| 116 |
+
# function at the top level to always return false when stdout is not
|
| 117 |
+
# a tty.
|
| 118 |
+
if [ -t 1 ]; then
|
| 119 |
+
is_tty() {
|
| 120 |
+
true
|
| 121 |
+
}
|
| 122 |
+
else
|
| 123 |
+
is_tty() {
|
| 124 |
+
false
|
| 125 |
+
}
|
| 126 |
+
fi
|
| 127 |
+
|
| 128 |
+
# This function uses the logic from supports-hyperlinks[1][2], which is
|
| 129 |
+
# made by Kat Marchán (@zkat) and licensed under the Apache License 2.0.
|
| 130 |
+
# [1] https://github.com/zkat/supports-hyperlinks
|
| 131 |
+
# [2] https://crates.io/crates/supports-hyperlinks
|
| 132 |
+
#
|
| 133 |
+
# Copyright (c) 2021 Kat Marchán
|
| 134 |
+
#
|
| 135 |
+
# Licensed under the Apache License, Version 2.0 (the "License");
|
| 136 |
+
# you may not use this file except in compliance with the License.
|
| 137 |
+
# You may obtain a copy of the License at
|
| 138 |
+
#
|
| 139 |
+
# http://www.apache.org/licenses/LICENSE-2.0
|
| 140 |
+
#
|
| 141 |
+
# Unless required by applicable law or agreed to in writing, software
|
| 142 |
+
# distributed under the License is distributed on an "AS IS" BASIS,
|
| 143 |
+
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
| 144 |
+
# See the License for the specific language governing permissions and
|
| 145 |
+
# limitations under the License.
|
| 146 |
+
supports_hyperlinks() {
|
| 147 |
+
# $FORCE_HYPERLINK must be set and be non-zero (this acts as a logic bypass)
|
| 148 |
+
if [ -n "$FORCE_HYPERLINK" ]; then
|
| 149 |
+
[ "$FORCE_HYPERLINK" != 0 ]
|
| 150 |
+
return $?
|
| 151 |
+
fi
|
| 152 |
+
|
| 153 |
+
# If stdout is not a tty, it doesn't support hyperlinks
|
| 154 |
+
is_tty || return 1
|
| 155 |
+
|
| 156 |
+
# DomTerm terminal emulator (domterm.org)
|
| 157 |
+
if [ -n "$DOMTERM" ]; then
|
| 158 |
+
return 0
|
| 159 |
+
fi
|
| 160 |
+
|
| 161 |
+
# VTE-based terminals above v0.50 (Gnome Terminal, Guake, ROXTerm, etc)
|
| 162 |
+
if [ -n "$VTE_VERSION" ]; then
|
| 163 |
+
[ $VTE_VERSION -ge 5000 ]
|
| 164 |
+
return $?
|
| 165 |
+
fi
|
| 166 |
+
|
| 167 |
+
# If $TERM_PROGRAM is set, these terminals support hyperlinks
|
| 168 |
+
case "$TERM_PROGRAM" in
|
| 169 |
+
Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;;
|
| 170 |
+
esac
|
| 171 |
+
|
| 172 |
+
# These termcap entries support hyperlinks
|
| 173 |
+
case "$TERM" in
|
| 174 |
+
xterm-kitty|alacritty|alacritty-direct) return 0 ;;
|
| 175 |
+
esac
|
| 176 |
+
|
| 177 |
+
# xfce4-terminal supports hyperlinks
|
| 178 |
+
if [ "$COLORTERM" = "xfce4-terminal" ]; then
|
| 179 |
+
return 0
|
| 180 |
+
fi
|
| 181 |
+
|
| 182 |
+
# Windows Terminal also supports hyperlinks
|
| 183 |
+
if [ -n "$WT_SESSION" ]; then
|
| 184 |
+
return 0
|
| 185 |
+
fi
|
| 186 |
+
|
| 187 |
+
# Konsole supports hyperlinks, but it's an opt-in setting that can't be detected
|
| 188 |
+
# https://github.com/ohmyzsh/ohmyzsh/issues/10964
|
| 189 |
+
# if [ -n "$KONSOLE_VERSION" ]; then
|
| 190 |
+
# return 0
|
| 191 |
+
# fi
|
| 192 |
+
|
| 193 |
+
return 1
|
| 194 |
+
}
|
| 195 |
+
|
| 196 |
+
# Adapted from code and information by Anton Kochkov (@XVilka)
|
| 197 |
+
# Source: https://gist.github.com/XVilka/8346728
|
| 198 |
+
supports_truecolor() {
|
| 199 |
+
case "$COLORTERM" in
|
| 200 |
+
truecolor|24bit) return 0 ;;
|
| 201 |
+
esac
|
| 202 |
+
|
| 203 |
+
case "$TERM" in
|
| 204 |
+
iterm |\
|
| 205 |
+
tmux-truecolor |\
|
| 206 |
+
linux-truecolor |\
|
| 207 |
+
xterm-truecolor |\
|
| 208 |
+
screen-truecolor) return 0 ;;
|
| 209 |
+
esac
|
| 210 |
+
|
| 211 |
+
return 1
|
| 212 |
+
}
|
| 213 |
+
|
| 214 |
+
fmt_link() {
|
| 215 |
+
# $1: text, $2: url, $3: fallback mode
|
| 216 |
+
if supports_hyperlinks; then
|
| 217 |
+
printf '\033]8;;%s\033\\%s\033]8;;\033\\\n' "$2" "$1"
|
| 218 |
+
return
|
| 219 |
+
fi
|
| 220 |
+
|
| 221 |
+
case "$3" in
|
| 222 |
+
--text) printf '%s\n' "$1" ;;
|
| 223 |
+
--url|*) fmt_underline "$2" ;;
|
| 224 |
+
esac
|
| 225 |
+
}
|
| 226 |
+
|
| 227 |
+
fmt_underline() {
|
| 228 |
+
is_tty && printf '\033[4m%s\033[24m\n' "$*" || printf '%s\n' "$*"
|
| 229 |
+
}
|
| 230 |
+
|
| 231 |
+
# shellcheck disable=SC2016 # backtick in single-quote
|
| 232 |
+
fmt_code() {
|
| 233 |
+
is_tty && printf '`\033[2m%s\033[22m`\n' "$*" || printf '`%s`\n' "$*"
|
| 234 |
+
}
|
| 235 |
+
|
| 236 |
+
fmt_error() {
|
| 237 |
+
printf '%sError: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "$FMT_RESET" >&2
|
| 238 |
+
}
|
| 239 |
+
|
| 240 |
+
setup_color() {
|
| 241 |
+
# Only use colors if connected to a terminal
|
| 242 |
+
if ! is_tty; then
|
| 243 |
+
FMT_RAINBOW=""
|
| 244 |
+
FMT_RED=""
|
| 245 |
+
FMT_GREEN=""
|
| 246 |
+
FMT_YELLOW=""
|
| 247 |
+
FMT_BLUE=""
|
| 248 |
+
FMT_BOLD=""
|
| 249 |
+
FMT_RESET=""
|
| 250 |
+
return
|
| 251 |
+
fi
|
| 252 |
+
|
| 253 |
+
if supports_truecolor; then
|
| 254 |
+
FMT_RAINBOW="
|
| 255 |
+
$(printf '\033[38;2;255;0;0m')
|
| 256 |
+
$(printf '\033[38;2;255;97;0m')
|
| 257 |
+
$(printf '\033[38;2;247;255;0m')
|
| 258 |
+
$(printf '\033[38;2;0;255;30m')
|
| 259 |
+
$(printf '\033[38;2;77;0;255m')
|
| 260 |
+
$(printf '\033[38;2;168;0;255m')
|
| 261 |
+
$(printf '\033[38;2;245;0;172m')
|
| 262 |
+
"
|
| 263 |
+
else
|
| 264 |
+
FMT_RAINBOW="
|
| 265 |
+
$(printf '\033[38;5;196m')
|
| 266 |
+
$(printf '\033[38;5;202m')
|
| 267 |
+
$(printf '\033[38;5;226m')
|
| 268 |
+
$(printf '\033[38;5;082m')
|
| 269 |
+
$(printf '\033[38;5;021m')
|
| 270 |
+
$(printf '\033[38;5;093m')
|
| 271 |
+
$(printf '\033[38;5;163m')
|
| 272 |
+
"
|
| 273 |
+
fi
|
| 274 |
+
|
| 275 |
+
FMT_RED=$(printf '\033[31m')
|
| 276 |
+
FMT_GREEN=$(printf '\033[32m')
|
| 277 |
+
FMT_YELLOW=$(printf '\033[33m')
|
| 278 |
+
FMT_BLUE=$(printf '\033[34m')
|
| 279 |
+
FMT_BOLD=$(printf '\033[1m')
|
| 280 |
+
FMT_RESET=$(printf '\033[0m')
|
| 281 |
+
}
|
| 282 |
+
|
| 283 |
+
setup_ohmyzsh() {
|
| 284 |
+
# Prevent the cloned repository from having insecure permissions. Failing to do
|
| 285 |
+
# so causes compinit() calls to fail with "command not found: compdef" errors
|
| 286 |
+
# for users with insecure umasks (e.g., "002", allowing group writability). Note
|
| 287 |
+
# that this will be ignored under Cygwin by default, as Windows ACLs take
|
| 288 |
+
# precedence over umasks except for filesystems mounted with option "noacl".
|
| 289 |
+
umask g-w,o-w
|
| 290 |
+
|
| 291 |
+
echo "${FMT_BLUE}Cloning Oh My Zsh...${FMT_RESET}"
|
| 292 |
+
|
| 293 |
+
command_exists git || {
|
| 294 |
+
fmt_error "git is not installed"
|
| 295 |
+
exit 1
|
| 296 |
+
}
|
| 297 |
+
|
| 298 |
+
ostype=$(uname)
|
| 299 |
+
if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -Eq 'msysgit|windows'; then
|
| 300 |
+
fmt_error "Windows/MSYS Git is not supported on Cygwin"
|
| 301 |
+
fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH"
|
| 302 |
+
exit 1
|
| 303 |
+
fi
|
| 304 |
+
|
| 305 |
+
# Manual clone with git config options to support git < v1.7.2
|
| 306 |
+
git init --quiet "$ZSH" && cd "$ZSH" \
|
| 307 |
+
&& git config core.eol lf \
|
| 308 |
+
&& git config core.autocrlf false \
|
| 309 |
+
&& git config fsck.zeroPaddedFilemode ignore \
|
| 310 |
+
&& git config fetch.fsck.zeroPaddedFilemode ignore \
|
| 311 |
+
&& git config receive.fsck.zeroPaddedFilemode ignore \
|
| 312 |
+
&& git config oh-my-zsh.remote origin \
|
| 313 |
+
&& git config oh-my-zsh.branch "$BRANCH" \
|
| 314 |
+
&& git remote add origin "$REMOTE" \
|
| 315 |
+
&& git fetch --depth=1 origin \
|
| 316 |
+
&& git checkout -b "$BRANCH" "origin/$BRANCH" || {
|
| 317 |
+
[ ! -d "$ZSH" ] || {
|
| 318 |
+
cd -
|
| 319 |
+
rm -rf "$ZSH" 2>/dev/null
|
| 320 |
+
}
|
| 321 |
+
fmt_error "git clone of oh-my-zsh repo failed"
|
| 322 |
+
exit 1
|
| 323 |
+
}
|
| 324 |
+
# Exit installation directory
|
| 325 |
+
cd -
|
| 326 |
+
|
| 327 |
+
echo
|
| 328 |
+
}
|
| 329 |
+
|
| 330 |
+
setup_zshrc() {
|
| 331 |
+
# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
|
| 332 |
+
# with datestamp of installation that moved them aside, so we never actually
|
| 333 |
+
# destroy a user's original zshrc
|
| 334 |
+
echo "${FMT_BLUE}Looking for an existing zsh config...${FMT_RESET}"
|
| 335 |
+
|
| 336 |
+
# Must use this exact name so uninstall.sh can find it
|
| 337 |
+
OLD_ZSHRC="$zdot/.zshrc.pre-oh-my-zsh"
|
| 338 |
+
if [ -f "$zdot/.zshrc" ] || [ -h "$zdot/.zshrc" ]; then
|
| 339 |
+
# Skip this if the user doesn't want to replace an existing .zshrc
|
| 340 |
+
if [ "$KEEP_ZSHRC" = yes ]; then
|
| 341 |
+
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
|
| 342 |
+
return
|
| 343 |
+
fi
|
| 344 |
+
if [ -e "$OLD_ZSHRC" ]; then
|
| 345 |
+
OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)"
|
| 346 |
+
if [ -e "$OLD_OLD_ZSHRC" ]; then
|
| 347 |
+
fmt_error "$OLD_OLD_ZSHRC exists. Can't back up ${OLD_ZSHRC}"
|
| 348 |
+
fmt_error "re-run the installer again in a couple of seconds"
|
| 349 |
+
exit 1
|
| 350 |
+
fi
|
| 351 |
+
mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
|
| 352 |
+
|
| 353 |
+
echo "${FMT_YELLOW}Found old .zshrc.pre-oh-my-zsh." \
|
| 354 |
+
"${FMT_GREEN}Backing up to ${OLD_OLD_ZSHRC}${FMT_RESET}"
|
| 355 |
+
fi
|
| 356 |
+
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
|
| 357 |
+
mv "$zdot/.zshrc" "$OLD_ZSHRC"
|
| 358 |
+
fi
|
| 359 |
+
|
| 360 |
+
echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to $zdot/.zshrc.${FMT_RESET}"
|
| 361 |
+
|
| 362 |
+
# Modify $ZSH variable in .zshrc directory to use the literal $ZDOTDIR or $HOME
|
| 363 |
+
omz="$ZSH"
|
| 364 |
+
if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then
|
| 365 |
+
omz=$(echo "$omz" | sed "s|^$ZDOTDIR/|\$ZDOTDIR/|")
|
| 366 |
+
fi
|
| 367 |
+
omz=$(echo "$omz" | sed "s|^$HOME/|\$HOME/|")
|
| 368 |
+
|
| 369 |
+
sed "s|^export ZSH=.*$|export ZSH=\"${omz}\"|" "$ZSH/templates/zshrc.zsh-template" > "$zdot/.zshrc-omztemp"
|
| 370 |
+
mv -f "$zdot/.zshrc-omztemp" "$zdot/.zshrc"
|
| 371 |
+
|
| 372 |
+
echo
|
| 373 |
+
}
|
| 374 |
+
|
| 375 |
+
setup_shell() {
|
| 376 |
+
# Skip setup if the user wants or stdin is closed (not running interactively).
|
| 377 |
+
if [ "$CHSH" = no ]; then
|
| 378 |
+
return
|
| 379 |
+
fi
|
| 380 |
+
|
| 381 |
+
# If this user's login shell is already "zsh", do not attempt to switch.
|
| 382 |
+
if [ "$(basename -- "$SHELL")" = "zsh" ]; then
|
| 383 |
+
return
|
| 384 |
+
fi
|
| 385 |
+
|
| 386 |
+
# If this platform doesn't provide a "chsh" command, bail out.
|
| 387 |
+
if ! command_exists chsh; then
|
| 388 |
+
cat <<EOF
|
| 389 |
+
I can't change your shell automatically because this system does not have chsh.
|
| 390 |
+
${FMT_BLUE}Please manually change your default shell to zsh${FMT_RESET}
|
| 391 |
+
EOF
|
| 392 |
+
return
|
| 393 |
+
fi
|
| 394 |
+
|
| 395 |
+
echo "${FMT_BLUE}Time to change your default shell to zsh:${FMT_RESET}"
|
| 396 |
+
|
| 397 |
+
# Prompt for user choice on changing the default login shell
|
| 398 |
+
printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \
|
| 399 |
+
"$FMT_YELLOW" "$FMT_RESET"
|
| 400 |
+
read -r opt
|
| 401 |
+
case $opt in
|
| 402 |
+
y*|Y*|"") ;;
|
| 403 |
+
n*|N*) echo "Shell change skipped."; return ;;
|
| 404 |
+
*) echo "Invalid choice. Shell change skipped."; return ;;
|
| 405 |
+
esac
|
| 406 |
+
|
| 407 |
+
# Check if we're running on Termux
|
| 408 |
+
case "$PREFIX" in
|
| 409 |
+
*com.termux*) termux=true; zsh=zsh ;;
|
| 410 |
+
*) termux=false ;;
|
| 411 |
+
esac
|
| 412 |
+
|
| 413 |
+
if [ "$termux" != true ]; then
|
| 414 |
+
# Test for the right location of the "shells" file
|
| 415 |
+
if [ -f /etc/shells ]; then
|
| 416 |
+
shells_file=/etc/shells
|
| 417 |
+
elif [ -f /usr/share/defaults/etc/shells ]; then # Solus OS
|
| 418 |
+
shells_file=/usr/share/defaults/etc/shells
|
| 419 |
+
else
|
| 420 |
+
fmt_error "could not find /etc/shells file. Change your default shell manually."
|
| 421 |
+
return
|
| 422 |
+
fi
|
| 423 |
+
|
| 424 |
+
# Get the path to the right zsh binary
|
| 425 |
+
# 1. Use the most preceding one based on $PATH, then check that it's in the shells file
|
| 426 |
+
# 2. If that fails, get a zsh path from the shells file, then check it actually exists
|
| 427 |
+
if ! zsh=$(command -v zsh) || ! grep -qx "$zsh" "$shells_file"; then
|
| 428 |
+
if ! zsh=$(grep '^/.*/zsh$' "$shells_file" | tail -n 1) || [ ! -f "$zsh" ]; then
|
| 429 |
+
fmt_error "no zsh binary found or not present in '$shells_file'"
|
| 430 |
+
fmt_error "change your default shell manually."
|
| 431 |
+
return
|
| 432 |
+
fi
|
| 433 |
+
fi
|
| 434 |
+
fi
|
| 435 |
+
|
| 436 |
+
# We're going to change the default shell, so back up the current one
|
| 437 |
+
if [ -n "$SHELL" ]; then
|
| 438 |
+
echo "$SHELL" > "$zdot/.shell.pre-oh-my-zsh"
|
| 439 |
+
else
|
| 440 |
+
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > "$zdot/.shell.pre-oh-my-zsh"
|
| 441 |
+
fi
|
| 442 |
+
|
| 443 |
+
echo "Changing your shell to $zsh..."
|
| 444 |
+
|
| 445 |
+
# Check if user has sudo privileges to run `chsh` with or without `sudo`
|
| 446 |
+
#
|
| 447 |
+
# This allows the call to succeed without password on systems where the
|
| 448 |
+
# user does not have a password but does have sudo privileges, like in
|
| 449 |
+
# Google Cloud Shell.
|
| 450 |
+
#
|
| 451 |
+
# On systems that don't have a user with passwordless sudo, the user will
|
| 452 |
+
# be prompted for the password either way, so this shouldn't cause any issues.
|
| 453 |
+
#
|
| 454 |
+
if user_can_sudo; then
|
| 455 |
+
sudo -k chsh -s "$zsh" "$USER" # -k forces the password prompt
|
| 456 |
+
else
|
| 457 |
+
chsh -s "$zsh" "$USER" # run chsh normally
|
| 458 |
+
fi
|
| 459 |
+
|
| 460 |
+
# Check if the shell change was successful
|
| 461 |
+
if [ $? -ne 0 ]; then
|
| 462 |
+
fmt_error "chsh command unsuccessful. Change your default shell manually."
|
| 463 |
+
else
|
| 464 |
+
export SHELL="$zsh"
|
| 465 |
+
echo "${FMT_GREEN}Shell successfully changed to '$zsh'.${FMT_RESET}"
|
| 466 |
+
fi
|
| 467 |
+
|
| 468 |
+
echo
|
| 469 |
+
}
|
| 470 |
+
|
| 471 |
+
# shellcheck disable=SC2183 # printf string has more %s than arguments ($FMT_RAINBOW expands to multiple arguments)
|
| 472 |
+
print_success() {
|
| 473 |
+
printf '%s %s__ %s %s %s %s %s__ %s\n' $FMT_RAINBOW $FMT_RESET
|
| 474 |
+
printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $FMT_RAINBOW $FMT_RESET
|
| 475 |
+
printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $FMT_RAINBOW $FMT_RESET
|
| 476 |
+
printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $FMT_RAINBOW $FMT_RESET
|
| 477 |
+
printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $FMT_RAINBOW $FMT_RESET
|
| 478 |
+
printf '%s %s %s %s /____/ %s %s %s %s....is now installed!%s\n' $FMT_RAINBOW $FMT_GREEN $FMT_RESET
|
| 479 |
+
printf '\n'
|
| 480 |
+
printf '\n'
|
| 481 |
+
printf "%s %s %s\n" "Before you scream ${FMT_BOLD}${FMT_YELLOW}Oh My Zsh!${FMT_RESET} look over the" \
|
| 482 |
+
"$(fmt_code "$(fmt_link ".zshrc" "file://$zdot/.zshrc" --text)")" \
|
| 483 |
+
"file to select plugins, themes, and options."
|
| 484 |
+
printf '\n'
|
| 485 |
+
printf '%s\n' "• Follow us on Twitter: $(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
|
| 486 |
+
printf '%s\n' "• Join our Discord community: $(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
|
| 487 |
+
printf '%s\n' "• Get stickers, t-shirts, coffee mugs and more: $(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
|
| 488 |
+
printf '%s\n' $FMT_RESET
|
| 489 |
+
}
|
| 490 |
+
|
| 491 |
+
main() {
|
| 492 |
+
# Run as unattended if stdin is not a tty
|
| 493 |
+
if [ ! -t 0 ]; then
|
| 494 |
+
RUNZSH=no
|
| 495 |
+
CHSH=no
|
| 496 |
+
fi
|
| 497 |
+
|
| 498 |
+
# Parse arguments
|
| 499 |
+
while [ $# -gt 0 ]; do
|
| 500 |
+
case $1 in
|
| 501 |
+
--unattended) RUNZSH=no; CHSH=no ;;
|
| 502 |
+
--skip-chsh) CHSH=no ;;
|
| 503 |
+
--keep-zshrc) KEEP_ZSHRC=yes ;;
|
| 504 |
+
esac
|
| 505 |
+
shift
|
| 506 |
+
done
|
| 507 |
+
|
| 508 |
+
setup_color
|
| 509 |
+
|
| 510 |
+
if ! command_exists zsh; then
|
| 511 |
+
echo "${FMT_YELLOW}Zsh is not installed.${FMT_RESET} Please install zsh first."
|
| 512 |
+
exit 1
|
| 513 |
+
fi
|
| 514 |
+
|
| 515 |
+
if [ -d "$ZSH" ]; then
|
| 516 |
+
echo "${FMT_YELLOW}The \$ZSH folder already exists ($ZSH).${FMT_RESET}"
|
| 517 |
+
if [ "$custom_zsh" = yes ]; then
|
| 518 |
+
cat <<EOF
|
| 519 |
+
|
| 520 |
+
You ran the installer with the \$ZSH setting or the \$ZSH variable is
|
| 521 |
+
exported. You have 3 options:
|
| 522 |
+
|
| 523 |
+
1. Unset the ZSH variable when calling the installer:
|
| 524 |
+
$(fmt_code "ZSH= sh install.sh")
|
| 525 |
+
2. Install Oh My Zsh to a directory that doesn't exist yet:
|
| 526 |
+
$(fmt_code "ZSH=path/to/new/ohmyzsh/folder sh install.sh")
|
| 527 |
+
3. (Caution) If the folder doesn't contain important information,
|
| 528 |
+
you can just remove it with $(fmt_code "rm -r $ZSH")
|
| 529 |
+
|
| 530 |
+
EOF
|
| 531 |
+
else
|
| 532 |
+
echo "You'll need to remove it if you want to reinstall."
|
| 533 |
+
fi
|
| 534 |
+
exit 1
|
| 535 |
+
fi
|
| 536 |
+
|
| 537 |
+
# Create ZDOTDIR folder structure if it doesn't exist
|
| 538 |
+
if [ -n "$ZDOTDIR" ]; then
|
| 539 |
+
mkdir -p "$ZDOTDIR"
|
| 540 |
+
fi
|
| 541 |
+
|
| 542 |
+
setup_ohmyzsh
|
| 543 |
+
setup_zshrc
|
| 544 |
+
setup_shell
|
| 545 |
+
|
| 546 |
+
print_success
|
| 547 |
+
|
| 548 |
+
if [ $RUNZSH = no ]; then
|
| 549 |
+
echo "${FMT_YELLOW}Run zsh to try it out.${FMT_RESET}"
|
| 550 |
+
exit
|
| 551 |
+
fi
|
| 552 |
+
|
| 553 |
+
exec zsh -l
|
| 554 |
+
}
|
| 555 |
+
|
| 556 |
+
main "$@"
|