diff options
| author | Tuowen Zhao <ztuowen@gmail.com> | 2026-01-04 22:47:54 -0800 |
|---|---|---|
| committer | Tuowen Zhao <ztuowen@gmail.com> | 2026-01-04 22:47:54 -0800 |
| commit | 2aa4cb7a52b28722816ecfd55f3b06293332c55c (patch) | |
| tree | f02a9f3d59d109c70caf932a24e43368994e0e8c /tools | |
| parent | 7e951c254e779ff0620537cf43ca69dd878387b4 (diff) | |
| parent | d23d3ea69fdb839088e6e5589557cce77b34aaf8 (diff) | |
| download | zsh-master.tar.gz zsh-master.tar.bz2 zsh-master.zip | |
Diffstat (limited to 'tools')
| -rwxr-xr-x | tools/changelog.sh | 37 | ||||
| -rw-r--r-- | tools/check_for_upgrade.sh | 21 | ||||
| -rwxr-xr-x | tools/install.sh | 51 | ||||
| -rwxr-xr-x | tools/theme_chooser.sh | 2 | ||||
| -rwxr-xr-x | tools/upgrade.sh | 24 |
5 files changed, 99 insertions, 36 deletions
diff --git a/tools/changelog.sh b/tools/changelog.sh index 6d768963e..ff409115f 100755 --- a/tools/changelog.sh +++ b/tools/changelog.sh @@ -221,11 +221,16 @@ supports_hyperlinks() { # If $TERM_PROGRAM is set, these terminals support hyperlinks case "$TERM_PROGRAM" in - Hyper|iTerm.app|terminology|WezTerm) return 0 ;; + Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;; esac - # kitty supports hyperlinks - if [ "$TERM" = xterm-kitty ]; then + # These termcap entries support hyperlinks + case "$TERM" in + xterm-kitty|alacritty|alacritty-direct) return 0 ;; + esac + + # xfce4-terminal supports hyperlinks + if [ "$COLORTERM" = "xfce4-terminal" ]; then return 0 fi @@ -292,16 +297,17 @@ function display-release { function fmt:hash { #* Uses $hash from outer scope local hash="${1:-$hash}" + local short_hash="${hash:0:7}" # 7 characters sha, top level sha is 12 characters case "$output" in - raw) printf '%s' "$hash" ;; + raw) printf '%s' "$short_hash" ;; text) - local text="\e[33m$hash\e[0m"; # red + local text="\e[33m$short_hash\e[0m"; # red if supports_hyperlinks; then printf "\e]8;;%s\a%s\e]8;;\a" "https://github.com/ohmyzsh/ohmyzsh/commit/$hash" $text; else echo $text; fi ;; - md) printf '[`%s`](https://github.com/ohmyzsh/ohmyzsh/commit/%s)' "$hash" "$hash" ;; + md) printf '[`%s`](https://github.com/ohmyzsh/ohmyzsh/commit/%s)' "$short_hash" "$hash" ;; esac } @@ -394,6 +400,9 @@ function display-release { function display:breaking { (( $#breaking != 0 )) || return 0 + # If we reach here we have shown commits, set flag + shown_commits=1 + case "$output" in text) printf '\e[31m'; fmt:header "BREAKING CHANGES" 3 ;; raw) fmt:header "BREAKING CHANGES" 3 ;; @@ -421,6 +430,9 @@ function display-release { # If no commits found of type $type, go to next type (( $#hashes != 0 )) || return 0 + # If we reach here we have shown commits, set flag + shown_commits=1 + fmt:header "${TYPES[$type]}" 3 for hash in $hashes; do echo " - $(fmt:hash) $(fmt:scope)$(fmt:subject)" @@ -438,6 +450,9 @@ function display-release { # If no commits found under "other" types, don't display anything (( $#changes != 0 )) || return 0 + # If we reach here we have shown commits, set flag + shown_commits=1 + fmt:header "Other changes" 3 for hash type in ${(kv)changes}; do case "$type" in @@ -492,7 +507,7 @@ function main { # Commit classification arrays local -A types subjects scopes breaking reverts - local truncate=0 read_commits=0 + local truncate=0 read_commits=0 shown_commits=0 local version tag local hash refs subject body @@ -512,13 +527,13 @@ function main { # Git log options # -z: commits are delimited by null bytes # --format: [7-char hash]<field sep>[ref names]<field sep>[subject]<field sep>[body] - # --abbrev=7: force commit hashes to be 7 characters long + # --abbrev=7: force commit hashes to be 12 characters long # --no-merges: merge commits are omitted # --first-parent: commits from merged branches are omitted local SEP="0mZmAgIcSeP" local -a raw_commits raw_commits=(${(0)"$(command git -c log.showSignature=false log -z \ - --format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=7 \ + --format="%h${SEP}%D${SEP}%s${SEP}%b" --abbrev=12 \ --no-merges --first-parent $range)"}) local raw_commit @@ -563,6 +578,10 @@ function main { echo " ...more commits omitted" echo fi + + if (( ! shown_commits )); then + echo "No changes to mention." + fi } # Use raw output if stdout is not a tty diff --git a/tools/check_for_upgrade.sh b/tools/check_for_upgrade.sh index 1cc193bde..44dbb7b31 100644 --- a/tools/check_for_upgrade.sh +++ b/tools/check_for_upgrade.sh @@ -20,14 +20,16 @@ zstyle -s ':omz:update' mode update_mode || { } # Cancel update if: -# - the automatic update is disabled. -# - the current user doesn't have write permissions nor owns the $ZSH directory. +# - the automatic update is disabled +# - the current user doesn't have write permissions nor owns the $ZSH directory # - is not run from a tty -# - git is unavailable on the system. +# - git is unavailable on the system +# - $ZSH is not a git repository if [[ "$update_mode" = disabled ]] \ || [[ ! -w "$ZSH" || ! -O "$ZSH" ]] \ - || [[ ! -t 1 ]] \ - || ! command git --version 2>&1 >/dev/null; then + || [[ ! -t 1 && ${POWERLEVEL9K_INSTANT_PROMPT:-off} == off ]] \ + || ! command git --version 2>&1 >/dev/null \ + || (builtin cd -q "$ZSH"; ! command git rev-parse --is-inside-work-tree &>/dev/null); then unset update_mode return fi @@ -110,6 +112,11 @@ function update_ohmyzsh() { local verbose_mode zstyle -s ':omz:update' verbose verbose_mode || verbose_mode=default + # Force verbose mode to silent if p10k instant prompt is enabled + if [[ ${POWERLEVEL9K_INSTANT_PROMPT:-off} != "off" ]]; then + verbose_mode=silent + fi + if [[ "$update_mode" != background-alpha ]] \ && LANG= ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" -i -v $verbose_mode; then update_last_updated_file @@ -225,7 +232,7 @@ function handle_update() { # Ask for confirmation and only update on 'y', 'Y' or Enter # Otherwise just show a reminder for how to update - echo -n "[oh-my-zsh] Would you like to update? [Y/n] " + printf "[oh-my-zsh] Would you like to update? [Y/n] " read -r -k 1 option [[ "$option" = $'\n' ]] || echo case "$option" in @@ -273,7 +280,7 @@ case "$update_mode" in return 0 elif [[ "$EXIT_STATUS" -ne 0 ]]; then print -P "\n%F{red}[oh-my-zsh] There was an error updating:%f" - printf "\n${fg[yellow]}%s${reset_color}" "$ERROR" + printf "\n${fg[yellow]}%s${reset_color}" "${ERROR}" return 0 fi } always { diff --git a/tools/install.sh b/tools/install.sh index 508fc2f77..c31ce2d55 100755 --- a/tools/install.sh +++ b/tools/install.sh @@ -25,9 +25,10 @@ # BRANCH - branch to check out immediately after install (default: master) # # Other options: -# CHSH - 'no' means the installer will not change the default shell (default: yes) -# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes) -# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no) +# CHSH - 'no' means the installer will not change the default shell (default: yes) +# RUNZSH - 'no' means the installer will not run zsh after the install (default: yes) +# KEEP_ZSHRC - 'yes' means the installer will not replace an existing .zshrc (default: no) +# OVERWRITE_CONFIRMATION - 'no' means the installer will not ask for confirmation to overwrite the existing .zshrc (default: yes) # # You can also pass some arguments to the install script to set some these options: # --skip-chsh: has the same behavior as setting CHSH to 'no' @@ -77,6 +78,7 @@ BRANCH=${BRANCH:-master} CHSH=${CHSH:-yes} RUNZSH=${RUNZSH:-yes} KEEP_ZSHRC=${KEEP_ZSHRC:-no} +OVERWRITE_CONFIRMATION=${OVERWRITE_CONFIRMATION:-yes} command_exists() { @@ -166,11 +168,16 @@ supports_hyperlinks() { # If $TERM_PROGRAM is set, these terminals support hyperlinks case "$TERM_PROGRAM" in - Hyper|iTerm.app|terminology|WezTerm) return 0 ;; + Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;; esac - # kitty supports hyperlinks - if [ "$TERM" = xterm-kitty ]; then + # These termcap entries support hyperlinks + case "$TERM" in + xterm-kitty|alacritty|alacritty-direct) return 0 ;; + esac + + # xfce4-terminal supports hyperlinks + if [ "$COLORTERM" = "xfce4-terminal" ]; then return 0 fi @@ -336,6 +343,25 @@ setup_zshrc() { echo "${FMT_YELLOW}Found ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Keeping...${FMT_RESET}" return fi + + if [ $OVERWRITE_CONFIRMATION != "no" ]; then + # Ask user for confirmation before backing up and overwriting + echo "${FMT_YELLOW}Found ${zdot}/.zshrc." + echo "The existing .zshrc will be backed up to .zshrc.pre-oh-my-zsh if overwritten." + echo "Make sure your .zshrc contains the following minimal configuration if you choose not to overwrite it:${FMT_RESET}" + echo "----------------------------------------" + cat "$ZSH/templates/minimal.zshrc" + echo "----------------------------------------" + printf '%sDo you want to overwrite it with the Oh My Zsh template? [Y/n]%s ' \ + "$FMT_YELLOW" "$FMT_RESET" + read -r opt + case $opt in + [Yy]*|"") ;; + [Nn]*) echo "Overwrite skipped. Existing .zshrc will be kept."; return ;; + *) echo "Invalid choice. Overwrite skipped. Existing .zshrc will be kept."; return ;; + esac + fi + if [ -e "$OLD_ZSHRC" ]; then OLD_OLD_ZSHRC="${OLD_ZSHRC}-$(date +%Y-%m-%d_%H-%M-%S)" if [ -e "$OLD_OLD_ZSHRC" ]; then @@ -348,7 +374,7 @@ setup_zshrc() { 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 ${zdot}/.zshrc.${FMT_RESET} ${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}" + echo "${FMT_GREEN}Backing up to ${OLD_ZSHRC}${FMT_RESET}" mv "$zdot/.zshrc" "$OLD_ZSHRC" fi @@ -394,8 +420,8 @@ EOF "$FMT_YELLOW" "$FMT_RESET" read -r opt case $opt in - y*|Y*|"") ;; - n*|N*) echo "Shell change skipped."; return ;; + [Yy]*|"") ;; + [Nn]*) echo "Shell change skipped."; return ;; *) echo "Invalid choice. Shell change skipped."; return ;; esac @@ -477,9 +503,9 @@ print_success() { "$(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)" + printf '%s\n' "• Follow us on X: $(fmt_link @ohmyzsh https://x.com/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 "CommitGoods Shop" https://commitgoods.com/collections/oh-my-zsh)" printf '%s\n' $FMT_RESET } @@ -488,12 +514,13 @@ main() { if [ ! -t 0 ]; then RUNZSH=no CHSH=no + OVERWRITE_CONFIRMATION=no fi # Parse arguments while [ $# -gt 0 ]; do case $1 in - --unattended) RUNZSH=no; CHSH=no ;; + --unattended) RUNZSH=no; CHSH=no; OVERWRITE_CONFIRMATION=no ;; --skip-chsh) CHSH=no ;; --keep-zshrc) KEEP_ZSHRC=yes ;; esac diff --git a/tools/theme_chooser.sh b/tools/theme_chooser.sh index 3883f1d37..ab270e8e1 100755 --- a/tools/theme_chooser.sh +++ b/tools/theme_chooser.sh @@ -1,4 +1,4 @@ -#!/bin/zsh +#!/usr/bin/env zsh # Zsh Theme Chooser by fox (fox91 at anche dot no) # This program is free software. It comes without any warranty, to diff --git a/tools/upgrade.sh b/tools/upgrade.sh index f7a263d66..01719d217 100755 --- a/tools/upgrade.sh +++ b/tools/upgrade.sh @@ -10,9 +10,14 @@ fi # Protect against unwanted sourcing case "$ZSH_EVAL_CONTEXT" in - *:file) echo "error: this file should not be sourced" && return ;; + *:file) echo "error: this file should not be sourced" && return 1 ;; esac +# Define "$ZSH" if not defined -- in theory this should be `export`ed by the calling script +if [[ -z "$ZSH" ]]; then + ZSH="${0:a:h:h}" +fi + cd "$ZSH" verbose_mode="default" @@ -90,11 +95,16 @@ supports_hyperlinks() { # If $TERM_PROGRAM is set, these terminals support hyperlinks case "$TERM_PROGRAM" in - Hyper|iTerm.app|terminology|WezTerm) return 0 ;; + Hyper|iTerm.app|terminology|WezTerm|vscode) return 0 ;; + esac + + # These termcap entries support hyperlinks + case "$TERM" in + xterm-kitty|alacritty|alacritty-direct) return 0 ;; esac - # kitty supports hyperlinks - if [ "$TERM" = xterm-kitty ]; then + # xfce4-terminal supports hyperlinks + if [ "$COLORTERM" = "xfce4-terminal" ]; then return 0 fi @@ -244,7 +254,7 @@ if LANG= git pull --quiet --rebase $remote $branch; then # Print changelog to the terminal if [[ $interactive == true && $verbose_mode == default ]]; then - "$ZSH/tools/changelog.sh" HEAD "$last_commit" + ZSH="$ZSH" command zsh -f "$ZSH/tools/changelog.sh" HEAD "$last_commit" fi if [[ $verbose_mode != silent ]]; then @@ -261,9 +271,9 @@ if LANG= git pull --quiet --rebase $remote $branch; then printf '%s %s %s %s /____/ %s %s %s %s\n' $RAINBOW $RESET printf '\n' printf "${BLUE}%s${RESET}\n\n" "$message" - printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on Twitter:" "$(fmt_link @ohmyzsh https://twitter.com/ohmyzsh)" + printf "${BLUE}${BOLD}%s %s${RESET}\n" "To keep up with the latest news and updates, follow us on X:" "$(fmt_link @ohmyzsh https://x.com/ohmyzsh)" printf "${BLUE}${BOLD}%s %s${RESET}\n" "Want to get involved in the community? Join our Discord:" "$(fmt_link "Discord server" https://discord.gg/ohmyzsh)" - printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "Planet Argon Shop" https://shop.planetargon.com/collections/oh-my-zsh)" + printf "${BLUE}${BOLD}%s %s${RESET}\n" "Get your Oh My Zsh swag at:" "$(fmt_link "CommitGoods Shop" https://commitgoods.com/collections/oh-my-zsh)" elif [[ $verbose_mode == minimal ]]; then printf "${BLUE}%s${RESET}\n" "$message" fi |
