mirror of
https://github.com/ohmyzsh/ohmyzsh.git
synced 2024-11-14 01:40:09 +00:00
style(installer): prefix formatting variables with FMT_
This commit is contained in:
parent
3f5402e268
commit
c7221c5f25
1 changed files with 39 additions and 39 deletions
|
@ -190,24 +190,24 @@ fmt_code() {
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt_error() {
|
fmt_error() {
|
||||||
printf '%sError: %s%s\n' "$BOLD$RED" "$*" "$RESET" >&2
|
printf '%sError: %s%s\n' "${FMT_BOLD}${FMT_RED}" "$*" "$FMT_RESET" >&2
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_color() {
|
setup_color() {
|
||||||
# Only use colors if connected to a terminal
|
# Only use colors if connected to a terminal
|
||||||
if ! is_tty; then
|
if ! is_tty; then
|
||||||
RAINBOW=""
|
FMT_RAINBOW=""
|
||||||
RED=""
|
FMT_RED=""
|
||||||
GREEN=""
|
FMT_GREEN=""
|
||||||
YELLOW=""
|
FMT_YELLOW=""
|
||||||
BLUE=""
|
FMT_BLUE=""
|
||||||
BOLD=""
|
FMT_BOLD=""
|
||||||
RESET=""
|
FMT_RESET=""
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if supports_truecolor; then
|
if supports_truecolor; then
|
||||||
RAINBOW="
|
FMT_RAINBOW="
|
||||||
$(printf '\033[38;2;255;0;0m')
|
$(printf '\033[38;2;255;0;0m')
|
||||||
$(printf '\033[38;2;255;97;0m')
|
$(printf '\033[38;2;255;97;0m')
|
||||||
$(printf '\033[38;2;247;255;0m')
|
$(printf '\033[38;2;247;255;0m')
|
||||||
|
@ -217,7 +217,7 @@ setup_color() {
|
||||||
$(printf '\033[38;2;245;0;172m')
|
$(printf '\033[38;2;245;0;172m')
|
||||||
"
|
"
|
||||||
else
|
else
|
||||||
RAINBOW="
|
FMT_RAINBOW="
|
||||||
$(printf '\033[38;5;196m')
|
$(printf '\033[38;5;196m')
|
||||||
$(printf '\033[38;5;202m')
|
$(printf '\033[38;5;202m')
|
||||||
$(printf '\033[38;5;226m')
|
$(printf '\033[38;5;226m')
|
||||||
|
@ -228,12 +228,12 @@ setup_color() {
|
||||||
"
|
"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
RED=$(printf '\033[31m')
|
FMT_RED=$(printf '\033[31m')
|
||||||
GREEN=$(printf '\033[32m')
|
FMT_GREEN=$(printf '\033[32m')
|
||||||
YELLOW=$(printf '\033[33m')
|
FMT_YELLOW=$(printf '\033[33m')
|
||||||
BLUE=$(printf '\033[34m')
|
FMT_BLUE=$(printf '\033[34m')
|
||||||
BOLD=$(printf '\033[1m')
|
FMT_BOLD=$(printf '\033[1m')
|
||||||
RESET=$(printf '\033[0m')
|
FMT_RESET=$(printf '\033[0m')
|
||||||
}
|
}
|
||||||
|
|
||||||
setup_ohmyzsh() {
|
setup_ohmyzsh() {
|
||||||
|
@ -244,7 +244,7 @@ setup_ohmyzsh() {
|
||||||
# precedence over umasks except for filesystems mounted with option "noacl".
|
# precedence over umasks except for filesystems mounted with option "noacl".
|
||||||
umask g-w,o-w
|
umask g-w,o-w
|
||||||
|
|
||||||
echo "${BLUE}Cloning Oh My Zsh...${RESET}"
|
echo "${FMT_BLUE}Cloning Oh My Zsh...${FMT_RESET}"
|
||||||
|
|
||||||
command_exists git || {
|
command_exists git || {
|
||||||
fmt_error "git is not installed"
|
fmt_error "git is not installed"
|
||||||
|
@ -276,14 +276,14 @@ setup_zshrc() {
|
||||||
# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
|
# Keep most recent old .zshrc at .zshrc.pre-oh-my-zsh, and older ones
|
||||||
# with datestamp of installation that moved them aside, so we never actually
|
# with datestamp of installation that moved them aside, so we never actually
|
||||||
# destroy a user's original zshrc
|
# destroy a user's original zshrc
|
||||||
echo "${BLUE}Looking for an existing zsh config...${RESET}"
|
echo "${FMT_BLUE}Looking for an existing zsh config...${FMT_RESET}"
|
||||||
|
|
||||||
# Must use this exact name so uninstall.sh can find it
|
# Must use this exact name so uninstall.sh can find it
|
||||||
OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
|
OLD_ZSHRC=~/.zshrc.pre-oh-my-zsh
|
||||||
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
|
if [ -f ~/.zshrc ] || [ -h ~/.zshrc ]; then
|
||||||
# Skip this if the user doesn't want to replace an existing .zshrc
|
# Skip this if the user doesn't want to replace an existing .zshrc
|
||||||
if [ "$KEEP_ZSHRC" = yes ]; then
|
if [ "$KEEP_ZSHRC" = yes ]; then
|
||||||
echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Keeping...${RESET}"
|
echo "${FMT_YELLOW}Found ~/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
if [ -e "$OLD_ZSHRC" ]; then
|
if [ -e "$OLD_ZSHRC" ]; then
|
||||||
|
@ -295,14 +295,14 @@ setup_zshrc() {
|
||||||
fi
|
fi
|
||||||
mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
|
mv "$OLD_ZSHRC" "${OLD_OLD_ZSHRC}"
|
||||||
|
|
||||||
echo "${YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
|
echo "${FMT_YELLOW}Found old ~/.zshrc.pre-oh-my-zsh." \
|
||||||
"${GREEN}Backing up to ${OLD_OLD_ZSHRC}${RESET}"
|
"${FMT_GREEN}Backing up to ${OLD_OLD_ZSHRC}${FMT_RESET}"
|
||||||
fi
|
fi
|
||||||
echo "${YELLOW}Found ~/.zshrc.${RESET} ${GREEN}Backing up to ${OLD_ZSHRC}${RESET}"
|
echo "${FMT_YELLOW}Found ~/.zshrc.${FMT_RESET} ${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}"
|
||||||
mv ~/.zshrc "$OLD_ZSHRC"
|
mv ~/.zshrc "$OLD_ZSHRC"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${RESET}"
|
echo "${FMT_GREEN}Using the Oh My Zsh template file and adding it to ~/.zshrc.${FMT_RESET}"
|
||||||
|
|
||||||
# Replace $HOME path with '$HOME' in $ZSH variable in .zshrc file
|
# Replace $HOME path with '$HOME' in $ZSH variable in .zshrc file
|
||||||
omz=$(echo "$ZSH" | sed "s|^$HOME/|\$HOME/|")
|
omz=$(echo "$ZSH" | sed "s|^$HOME/|\$HOME/|")
|
||||||
|
@ -327,16 +327,16 @@ setup_shell() {
|
||||||
if ! command_exists chsh; then
|
if ! command_exists chsh; then
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
I can't change your shell automatically because this system does not have chsh.
|
I can't change your shell automatically because this system does not have chsh.
|
||||||
${BLUE}Please manually change your default shell to zsh${RESET}
|
${FMT_BLUE}Please manually change your default shell to zsh${FMT_RESET}
|
||||||
EOF
|
EOF
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "${BLUE}Time to change your default shell to zsh:${RESET}"
|
echo "${FMT_BLUE}Time to change your default shell to zsh:${FMT_RESET}"
|
||||||
|
|
||||||
# Prompt for user choice on changing the default login shell
|
# Prompt for user choice on changing the default login shell
|
||||||
printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \
|
printf '%sDo you want to change your default shell to zsh? [Y/n]%s ' \
|
||||||
"$YELLOW" "$RESET"
|
"$FMT_YELLOW" "$FMT_RESET"
|
||||||
read -r opt
|
read -r opt
|
||||||
case $opt in
|
case $opt in
|
||||||
y*|Y*|"") ;;
|
y*|Y*|"") ;;
|
||||||
|
@ -402,30 +402,30 @@ EOF
|
||||||
fmt_error "chsh command unsuccessful. Change your default shell manually."
|
fmt_error "chsh command unsuccessful. Change your default shell manually."
|
||||||
else
|
else
|
||||||
export SHELL="$zsh"
|
export SHELL="$zsh"
|
||||||
echo "${GREEN}Shell successfully changed to '$zsh'.${RESET}"
|
echo "${FMT_GREEN}Shell successfully changed to '$zsh'.${FMT_RESET}"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo
|
echo
|
||||||
}
|
}
|
||||||
|
|
||||||
# shellcheck disable=SC2183 # printf string has more %s than arguments ($RAINBOW expands to multiple arguments)
|
# shellcheck disable=SC2183 # printf string has more %s than arguments ($FMT_RAINBOW expands to multiple arguments)
|
||||||
print_success() {
|
print_success() {
|
||||||
printf '%s %s__ %s %s %s %s %s__ %s\n' $RAINBOW $RESET
|
printf '%s %s__ %s %s %s %s %s__ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $RAINBOW $RESET
|
printf '%s ____ %s/ /_ %s ____ ___ %s__ __ %s ____ %s_____%s/ /_ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $RAINBOW $RESET
|
printf '%s / __ \\%s/ __ \\ %s / __ `__ \\%s/ / / / %s /_ / %s/ ___/%s __ \\ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $RAINBOW $RESET
|
printf '%s/ /_/ /%s / / / %s / / / / / /%s /_/ / %s / /_%s(__ )%s / / / %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $RAINBOW $RESET
|
printf '%s\\____/%s_/ /_/ %s /_/ /_/ /_/%s\\__, / %s /___/%s____/%s_/ /_/ %s\n' $FMT_RAINBOW $FMT_RESET
|
||||||
printf '%s %s %s %s /____/ %s %s %s %s....is now installed!%s\n' $RAINBOW $GREEN $RESET
|
printf '%s %s %s %s /____/ %s %s %s %s....is now installed!%s\n' $FMT_RAINBOW $FMT_GREEN $FMT_RESET
|
||||||
printf '\n'
|
printf '\n'
|
||||||
printf '\n'
|
printf '\n'
|
||||||
printf "%s %s %s\n" "Before you scream ${BOLD}${YELLOW}Oh My Zsh!${RESET} look over the" \
|
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://$HOME/.zshrc" --text)")" \
|
||||||
"file to select plugins, themes, and options."
|
"file to select plugins, themes, and options."
|
||||||
printf '\n'
|
printf '\n'
|
||||||
printf '%s\n' "• Follow us on Twitter: $(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
|
printf '%s\n' "• Follow us on Twitter: $(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)"
|
||||||
printf '%s\n' "• Join our Discord community: $(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
|
printf '%s\n' "• Join our Discord community: $(fmt_link "Discord server" https://discord.gg/ohmyzsh)"
|
||||||
printf '%s\n' "• Get stickers, t-shirts, coffee mugs and more: $(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
|
printf '%s\n' "• Get stickers, t-shirts, coffee mugs and more: $(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)"
|
||||||
printf '%s\n' $RESET
|
printf '%s\n' $FMT_RESET
|
||||||
}
|
}
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
|
@ -448,12 +448,12 @@ main() {
|
||||||
setup_color
|
setup_color
|
||||||
|
|
||||||
if ! command_exists zsh; then
|
if ! command_exists zsh; then
|
||||||
echo "${YELLOW}Zsh is not installed.${RESET} Please install zsh first."
|
echo "${FMT_YELLOW}Zsh is not installed.${FMT_RESET} Please install zsh first."
|
||||||
exit 1
|
exit 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ -d "$ZSH" ]; then
|
if [ -d "$ZSH" ]; then
|
||||||
echo "${YELLOW}The \$ZSH folder already exists ($ZSH).${RESET}"
|
echo "${FMT_YELLOW}The \$ZSH folder already exists ($ZSH).${FMT_RESET}"
|
||||||
if [ "$custom_zsh" = yes ]; then
|
if [ "$custom_zsh" = yes ]; then
|
||||||
cat <<EOF
|
cat <<EOF
|
||||||
|
|
||||||
|
@ -481,7 +481,7 @@ EOF
|
||||||
print_success
|
print_success
|
||||||
|
|
||||||
if [ $RUNZSH = no ]; then
|
if [ $RUNZSH = no ]; then
|
||||||
echo "${YELLOW}Run zsh to try it out.${RESET}"
|
echo "${FMT_YELLOW}Run zsh to try it out.${FMT_RESET}"
|
||||||
exit
|
exit
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue