Update 13.05.2022

This commit is contained in:
2022-05-13 22:49:55 +05:00
parent 04423b8c5c
commit b40b4515e3
126 changed files with 2457 additions and 6430 deletions

View File

@@ -23,8 +23,7 @@ TYPES=(
test "Testing"
)
#* Types that will be displayed in their own section,
#* in the order specified here.
#* Types that will be displayed in their own section, in the order specified here.
local -a MAIN_TYPES
MAIN_TYPES=(feat fix perf docs)
@@ -34,7 +33,8 @@ OTHER_TYPES=(refactor style other)
#* Commit types that don't appear in $MAIN_TYPES nor $OTHER_TYPES
#* will not be displayed and will simply be ignored.
local -a IGNORED_TYPES
IGNORED_TYPES=(${${${(@k)TYPES}:|MAIN_TYPES}:|OTHER_TYPES})
############################
# COMMIT PARSING UTILITIES #
@@ -139,7 +139,7 @@ function parse-commit {
# [BREAKING CHANGE: warning]
# commits holds the commit type
commits[$hash]="$(commit:type "$subject")"
types[$hash]="$(commit:type "$subject")"
# scopes holds the commit scope
scopes[$hash]="$(commit:scope "$subject")"
# subjects holds the commit subject
@@ -164,26 +164,32 @@ function parse-commit {
function display-release {
# This function uses the following globals: output, version,
# commits (A), subjects (A), scopes (A), breaking (A) and reverts (A).
# types (A), subjects (A), scopes (A), breaking (A) and reverts (A).
#
# - output is the output format to use when formatting (raw|text|md)
# - version is the version in which the commits are made
# - commits, subjects, scopes, breaking, and reverts are associative arrays
# - types, subjects, scopes, breaking, and reverts are associative arrays
# with commit hashes as keys
# Remove commits that were reverted
local hash rhash
for hash rhash in ${(kv)reverts}; do
if (( ${+commits[$rhash]} )); then
if (( ${+types[$rhash]} )); then
# Remove revert commit
unset "commits[$hash]" "subjects[$hash]" "scopes[$hash]" "breaking[$hash]"
unset "types[$hash]" "subjects[$hash]" "scopes[$hash]" "breaking[$hash]"
# Remove reverted commit
unset "commits[$rhash]" "subjects[$rhash]" "scopes[$rhash]" "breaking[$rhash]"
unset "types[$rhash]" "subjects[$rhash]" "scopes[$rhash]" "breaking[$rhash]"
fi
done
# Remove commits from ignored types unless it has breaking change information
for hash in ${(k)types[(R)${(j:|:)IGNORED_TYPES}]}; do
(( ! ${+breaking[$hash]} )) || continue
unset "types[$hash]" "subjects[$hash]" "scopes[$hash]"
done
# If no commits left skip displaying the release
if (( $#commits == 0 )); then
if (( $#types == 0 )); then
return
fi
@@ -313,7 +319,7 @@ function display-release {
local hash type="$1"
local -a hashes
hashes=(${(k)commits[(R)$type]})
hashes=(${(k)types[(R)$type]})
# If no commits found of type $type, go to next type
(( $#hashes != 0 )) || return 0
@@ -330,7 +336,7 @@ function display-release {
# Commits made under types considered other changes
local -A changes
changes=(${(kv)commits[(R)${(j:|:)OTHER_TYPES}]})
changes=(${(kv)types[(R)${(j:|:)OTHER_TYPES}]})
# If no commits found under "other" types, don't display anything
(( $#changes != 0 )) || return 0
@@ -388,7 +394,7 @@ function main {
fi
# Commit classification arrays
local -A commits subjects scopes breaking reverts
local -A types subjects scopes breaking reverts
local truncate=0 read_commits=0
local version tag
local hash refs subject body
@@ -441,7 +447,7 @@ function main {
# Output previous release
display-release
# Reinitialize commit storage
commits=()
types=()
subjects=()
scopes=()
breaking=()

View File

@@ -36,11 +36,11 @@ function current_epoch() {
function is_update_available() {
local branch
branch=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master}
branch=${"$(builtin cd -q "$ZSH"; git config --local oh-my-zsh.branch)":-master}
local remote remote_url remote_repo
remote=${"$(cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
remote_url=$(cd -q "$ZSH"; git config remote.$remote.url)
remote=${"$(builtin cd -q "$ZSH"; git config --local oh-my-zsh.remote)":-origin}
remote_url=$(builtin cd -q "$ZSH"; git config remote.$remote.url)
local repo
case "$remote_url" in
@@ -58,25 +58,34 @@ function is_update_available() {
# Get local HEAD. If this fails assume there are updates
local local_head
local_head=$(cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
local_head=$(builtin cd -q "$ZSH"; git rev-parse $branch 2>/dev/null) || return 0
# Get remote HEAD. If no suitable command is found assume there are updates
# On any other error, skip the update (connection may be down)
local remote_head
remote_head=$(
if (( ${+commands[curl]} )); then
curl -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
curl -m 2 -fsSL -H 'Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
elif (( ${+commands[wget]} )); then
wget -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
wget -T 2 -O- --header='Accept: application/vnd.github.v3.sha' $api_url 2>/dev/null
elif (( ${+commands[fetch]} )); then
HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -o - $api_url 2>/dev/null
HTTP_ACCEPT='Accept: application/vnd.github.v3.sha' fetch -T 2 -o - $api_url 2>/dev/null
else
exit 0
fi
) || return 1
# Compare local and remote HEADs
[[ "$local_head" != "$remote_head" ]]
# Compare local and remote HEADs (if they're equal there are no updates)
[[ "$local_head" != "$remote_head" ]] || return 1
# If local and remote HEADs don't match, check if there's a common ancestor
# If the merge-base call fails, $remote_head might not be downloaded so assume there are updates
local base
base=$(builtin cd -q "$ZSH"; git merge-base $local_head $remote_head 2>/dev/null) || return 0
# If the common ancestor ($base) is not $remote_head,
# the local HEAD is older than the remote HEAD
[[ $base != $remote_head ]]
}
function update_last_updated_file() {
@@ -89,6 +98,31 @@ function update_ohmyzsh() {
fi
}
function has_typed_input() {
# Created by Philippe Troin <phil@fifi.org>
# https://zsh.org/mla/users/2022/msg00062.html
emulate -L zsh
zmodload zsh/zselect
# Back up stty settings prior to disabling canonical mode
# Consider that no input can be typed if stty fails
# (this might happen if stdin is not a terminal)
local termios
termios=$(stty --save 2>/dev/null) || return 1
{
# Disable canonical mode so that typed input counts
# regardless of whether Enter was pressed
stty -icanon
# Poll stdin (fd 0) for data ready to be read
zselect -t 0 -r 0
return $?
} always {
# Restore stty settings
stty $termios
}
}
() {
emulate -L zsh
@@ -136,7 +170,7 @@ function update_ohmyzsh() {
fi
# Test if Oh My Zsh directory is a git repository
if ! (cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then
if ! (builtin cd -q "$ZSH" && LANG= git rev-parse &>/dev/null); then
echo >&2 "[oh-my-zsh] Can't update: not a git repository."
return
fi
@@ -146,26 +180,29 @@ function update_ohmyzsh() {
return
fi
# Ask for confirmation before updating unless in auto mode
# If in reminder mode or user has typed input, show reminder and exit
if [[ "$update_mode" = reminder ]] || has_typed_input; then
printf '\r\e[0K' # move cursor to first column and clear whole line
echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
return 0
fi
# Don't ask for confirmation before updating if in auto mode
if [[ "$update_mode" = auto ]]; then
update_ohmyzsh
elif [[ "$update_mode" = reminder ]]; then
echo "[oh-my-zsh] It's time to update! You can do that by running \`omz update\`"
else
# input sink to swallow all characters typed before the prompt
# and add a newline if there wasn't one after characters typed
while read -t -k 1 option; do true; done
[[ "$option" != ($'\n'|"") ]] && echo
echo -n "[oh-my-zsh] Would you like to update? [Y/n] "
read -r -k 1 option
[[ "$option" != $'\n' ]] && echo
case "$option" in
[yY$'\n']) update_ohmyzsh ;;
[nN]) update_last_updated_file ;&
*) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
esac
return $?
fi
# 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] "
read -r -k 1 option
[[ "$option" = $'\n' ]] || echo
case "$option" in
[yY$'\n']) update_ohmyzsh ;;
[nN]) update_last_updated_file ;&
*) echo "[oh-my-zsh] You can update manually by running \`omz update\`" ;;
esac
}
unset update_mode

View File

@@ -37,11 +37,24 @@
#
set -e
# Make sure important variables exist if not already defined
#
# $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}
@@ -51,9 +64,6 @@ CHSH=${CHSH:-yes}
RUNZSH=${RUNZSH:-yes}
KEEP_ZSHRC=${KEEP_ZSHRC:-no}
# Sane defaults
USER=${USER:-$(whoami)}
command_exists() {
command -v "$@" >/dev/null 2>&1
@@ -263,16 +273,27 @@ setup_ohmyzsh() {
exit 1
fi
git clone -c core.eol=lf -c core.autocrlf=false \
-c fsck.zeroPaddedFilemode=ignore \
-c fetch.fsck.zeroPaddedFilemode=ignore \
-c receive.fsck.zeroPaddedFilemode=ignore \
-c oh-my-zsh.remote=origin \
-c oh-my-zsh.branch="$BRANCH" \
--depth=1 --branch "$BRANCH" "$REMOTE" "$ZSH" || {
# Manual clone with git config options to support git < v1.7.2
git init --quiet "$ZSH" && cd "$ZSH" \
&& git config core.eol lf \
&& git config core.autocrlf false \
&& git config fsck.zeroPaddedFilemode ignore \
&& git config fetch.fsck.zeroPaddedFilemode ignore \
&& git config receive.fsck.zeroPaddedFilemode ignore \
&& git config oh-my-zsh.remote origin \
&& git config oh-my-zsh.branch "$BRANCH" \
&& git remote add origin "$REMOTE" \
&& git fetch --depth=1 origin \
&& git checkout -b "$BRANCH" "origin/$BRANCH" || {
[ ! -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
}

View File

@@ -164,6 +164,10 @@ git remote -v | while read remote url extra; do
git@github.com:robbyrussell/oh-my-zsh(|.git))
git remote set-url "$remote" "git@github.com:ohmyzsh/ohmyzsh.git"
break ;;
# Update out-of-date "unauthenticated git protocol on port 9418" to https
git://github.com/robbyrussell/oh-my-zsh(|.git))
git remote set-url "$remote" "https://github.com/ohmyzsh/ohmyzsh.git"
break ;;
esac
done