merge from upstream

This commit is contained in:
abc 2023-04-07 16:01:57 +08:00
commit 64603fdc86
230 changed files with 5829 additions and 2392 deletions

View file

@ -16,6 +16,9 @@
# ZSH=~/.zsh sh install.sh
#
# Respects the following environment variables:
# ZDOTDIR - path to Zsh dotfiles directory (default: unset). See [1][2]
# [1] https://zsh.sourceforge.io/Doc/Release/Parameters.html#index-ZDOTDIR
# [2] https://zsh.sourceforge.io/Doc/Release/Files.html#index-ZDOTDIR_002c-use-of
# ZSH - path to the Oh My Zsh repository folder (default: $HOME/.oh-my-zsh)
# REPO - name of the GitHub repo to install from (default: ohmyzsh/ohmyzsh)
# REMOTE - full remote URL of the git repo to install (default: GitHub via HTTPS)
@ -53,7 +56,14 @@ HOME="${HOME:-$(eval echo ~$USER)}"
# Track if $ZSH was provided
custom_zsh=${ZSH:+yes}
# Default settings
# Use $zdot to keep track of where the directory is for zsh dotfiles
# To check if $ZDOTDIR was provided, explicitly check for $ZDOTDIR
zdot="${ZDOTDIR:-$HOME}"
# Default value for $ZSH
# a) if $ZDOTDIR is supplied and not $HOME: $ZDOTDIR/ohmyzsh
# b) otherwise, $HOME/.oh-my-zsh
[ "$ZDOTDIR" = "$HOME" ] || ZSH="${ZSH:-${ZDOTDIR:+$ZDOTDIR/ohmyzsh}}"
ZSH="${ZSH:-$HOME/.oh-my-zsh}"
REPO=${REPO:-snakewarhead/oh-my-zsh}
REMOTE=${REMOTE:-https://github.com/${REPO}.git}
@ -72,6 +82,10 @@ command_exists() {
user_can_sudo() {
# Check if sudo is installed
command_exists sudo || return 1
# Termux can't run sudo, so we can detect it and exit the function early.
case "$PREFIX" in
*com.termux*) return 1 ;;
esac
# The following command has 3 parts:
#
# 1. Run `sudo` with `-v`. Does the following:
@ -156,11 +170,17 @@ supports_hyperlinks() {
return 0
fi
# Windows Terminal or Konsole also support hyperlinks
if [ -n "$WT_SESSION" ] || [ -n "$KONSOLE_VERSION" ]; then
# Windows Terminal also supports hyperlinks
if [ -n "$WT_SESSION" ]; then
return 0
fi
# Konsole supports hyperlinks, but it's an opt-in setting that can't be detected
# https://github.com/ohmyzsh/ohmyzsh/issues/10964
# if [ -n "$KONSOLE_VERSION" ]; then
# return 0
# fi
return 1
}
@ -185,7 +205,7 @@ supports_truecolor() {
fmt_link() {
# $1: text, $2: url, $3: fallback mode
if supports_hyperlinks; then
printf '\033]8;;%s\a%s\033]8;;\a\n' "$2" "$1"
printf '\033]8;;%s\033\\%s\033]8;;\033\\\n' "$2" "$1"
return
fi
@ -267,7 +287,7 @@ setup_ohmyzsh() {
}
ostype=$(uname)
if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -q msysgit; then
if [ -z "${ostype%CYGWIN*}" ] && git --version | grep -Eq 'msysgit|windows'; then
fmt_error "Windows/MSYS Git is not supported on Cygwin"
fmt_error "Make sure the Cygwin git package is installed and is first on the \$PATH"
exit 1
@ -305,11 +325,11 @@ setup_zshrc() {
echo "${FMT_BLUE}Looking for an existing zsh config...${FMT_RESET}"
# Must use this exact name so uninstall.sh can find it
OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
OLD_ZSHRC="$zdot/.zshrc.pre-oh-my-zsh"
if [ -f "$zdot/.zshrc" ] || [ -h "$zdot/.zshrc" ]; then
# Skip this if the user doesn't want to replace an existing .zshrc
if [ "$KEEP_ZSHRC" = yes ]; then
echo "${FMT_YELLOW}Found ~/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
return
fi
if [ -e "$OLD_ZSHRC" ]; then
@ -321,19 +341,24 @@ setup_zshrc() {
fi
mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
echo "${FMT_YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
echo "${FMT_YELLOW}Found old .zshrc.pre-oh-my-zsh." \
"${FMT_GREEN}Backing up to ${OLD_OLD_ZSHRC}${FMT_RESET}"
fi
echo "${FMT_YELLOW}Found ~/.zshrc.${FMT_RESET} ${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
mv ~/.zshrc "$OLD_ZSHRC"
echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
mv "$zdot/.zshrc" "$OLD_ZSHRC"
fi
echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${FMT_RESET}"
echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to $zdot/.zshrc.${FMT_RESET}"
# Replace $HOME path with '$HOME' in $ZSH variable in .zshrc file
omz=$(echo "$ZSH" | sed "s|^$HOME/|\$HOME/|")
sed "s|^export ZSH=.*$|export ZSH=\"${omz}\"|" "$ZSH/templates/zshrc.zsh-template" > ~/.zshrc-omztemp
mv -f ~/.zshrc-omztemp ~/.zshrc
# Modify $ZSH variable in .zshrc directory to use the literal $ZDOTDIR or $HOME
omz="$ZSH"
if [ -n "$ZDOTDIR" ] && [ "$ZDOTDIR" != "$HOME" ]; then
omz=$(echo "$omz" | sed "s|^$ZDOTDIR/|\$ZDOTDIR/|")
fi
omz=$(echo "$omz" | sed "s|^$HOME/|\$HOME/|")
sed "s|^export ZSH=.*$|export ZSH=\"${omz}\"|" "$ZSH/templates/zshrc.zsh-template" > "$zdot/.zshrc-omztemp"
mv -f "$zdot/.zshrc-omztemp" "$zdot/.zshrc"
# create ~/.zshrc_custom
touch ~/.zshrc_custom
@ -404,9 +429,9 @@ EOF
# We're going to change the default shell, so back up the current one
if [ -n "$SHELL" ]; then
echo "$SHELL" > ~/.shell.pre-oh-my-zsh
echo "$SHELL" > "$zdot/.shell.pre-oh-my-zsh"
else
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > ~/.shell.pre-oh-my-zsh
grep "^$USER:" /etc/passwd | awk -F: '{print $7}' > "$zdot/.shell.pre-oh-my-zsh"
fi
echo "Changing your shell to $zsh..."
@ -448,7 +473,7 @@ print_success() {
printf '\n'
printf '\n'
printf "%s %s %s\n" "Before you scream ${FMT_BOLD}${FMT_YELLOW}Oh My Zsh!${FMT_RESET} look over the" \
"$(fmt_code "$(fmt_link ".zshrc" "file://$HOME/.zshrc" --text)")" \
"$(fmt_code "$(fmt_link ".zshrc" "file://$zdot/.zshrc" --text)")" \
"file to select plugins, themes, and options."
printf '\n'
printf '%s\n' "• Follow us on Twitter: $(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
@ -503,6 +528,11 @@ EOF
exit 1
fi
# Create ZDOTDIR folder structure if it doesn't exist
if [ -n "$ZDOTDIR" ]; then
mkdir -p "$ZDOTDIR"
fi
setup_ohmyzsh
setup_zshrc
setup_shell