Update 30.01.2022
This commit is contained in:
187
zsh/lib/cli.zsh
187
zsh/lib/cli.zsh
@@ -26,8 +26,10 @@ function _omz {
|
||||
'help:Usage information'
|
||||
'plugin:Manage plugins'
|
||||
'pr:Manage Oh My Zsh Pull Requests'
|
||||
'reload:Reload the current zsh session'
|
||||
'theme:Manage themes'
|
||||
'update:Update Oh My Zsh'
|
||||
'version:Show the version'
|
||||
)
|
||||
|
||||
if (( CURRENT == 2 )); then
|
||||
@@ -35,7 +37,7 @@ function _omz {
|
||||
elif (( CURRENT == 3 )); then
|
||||
case "$words[2]" in
|
||||
changelog) local -a refs
|
||||
refs=("${(@f)$(command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
|
||||
refs=("${(@f)$(builtin cd -q "$ZSH"; command git for-each-ref --format="%(refname:short):%(subject)" refs/heads refs/tags)}")
|
||||
_describe 'command' refs ;;
|
||||
plugin) subcmds=(
|
||||
'disable:Disable plugin(s)'
|
||||
@@ -59,17 +61,19 @@ function _omz {
|
||||
# if command is "disable", only offer already enabled plugins
|
||||
valid_plugins=($plugins)
|
||||
else
|
||||
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
|
||||
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||
# if command is "enable", remove already enabled plugins
|
||||
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
||||
fi
|
||||
|
||||
_describe 'plugin' valid_plugins ;;
|
||||
plugin::info)
|
||||
local -aU plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
|
||||
local -aU plugins
|
||||
plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||
_describe 'plugin' plugins ;;
|
||||
theme::(set|use))
|
||||
local -aU themes=("$ZSH"/themes/*.zsh-theme(.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
|
||||
local -aU themes
|
||||
themes=("$ZSH"/themes/*.zsh-theme(-.N:t:r) "$ZSH_CUSTOM"/**/*.zsh-theme(-.N:r:gs:"$ZSH_CUSTOM"/themes/:::gs:"$ZSH_CUSTOM"/:::))
|
||||
_describe 'theme' themes ;;
|
||||
esac
|
||||
elif (( CURRENT > 4 )); then
|
||||
@@ -81,7 +85,7 @@ function _omz {
|
||||
# if command is "disable", only offer already enabled plugins
|
||||
valid_plugins=($plugins)
|
||||
else
|
||||
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(.N:h:t))
|
||||
valid_plugins=("$ZSH"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t) "$ZSH_CUSTOM"/plugins/*/{_*,*.plugin.zsh}(-.N:h:t))
|
||||
# if command is "enable", remove already enabled plugins
|
||||
[[ "${words[3]}" = enable ]] && valid_plugins=(${valid_plugins:|plugins})
|
||||
fi
|
||||
@@ -90,7 +94,8 @@ function _omz {
|
||||
# NOTE: $(( CURRENT - 1 )) is the last plugin argument completely passed, i.e. that which
|
||||
# has a space after them. This is to avoid removing plugins partially passed, which makes
|
||||
# the completion not add a space after the completed plugin.
|
||||
local -a args=(${words[4,$(( CURRENT - 1))]})
|
||||
local -a args
|
||||
args=(${words[4,$(( CURRENT - 1))]})
|
||||
valid_plugins=(${valid_plugins:|args})
|
||||
|
||||
_describe 'plugin' valid_plugins ;;
|
||||
@@ -159,8 +164,10 @@ Available commands:
|
||||
changelog Print the changelog
|
||||
plugin <command> Manage plugins
|
||||
pr <command> Manage Oh My Zsh Pull Requests
|
||||
reload Reload the current zsh session
|
||||
theme <command> Manage themes
|
||||
update Update Oh My Zsh
|
||||
version Show the version
|
||||
|
||||
EOF
|
||||
}
|
||||
@@ -168,11 +175,14 @@ EOF
|
||||
function _omz::changelog {
|
||||
local version=${1:-HEAD} format=${3:-"--text"}
|
||||
|
||||
if ! command git -C "$ZSH" show-ref --verify refs/heads/$version &>/dev/null && \
|
||||
! command git -C "$ZSH" show-ref --verify refs/tags/$version &>/dev/null && \
|
||||
! command git -C "$ZSH" rev-parse --verify "${version}^{commit}" &>/dev/null; then
|
||||
if (
|
||||
builtin cd -q "$ZSH"
|
||||
! command git show-ref --verify refs/heads/$version && \
|
||||
! command git show-ref --verify refs/tags/$version && \
|
||||
! command git rev-parse --verify "${version}^{commit}"
|
||||
) &>/dev/null; then
|
||||
cat >&2 <<EOF
|
||||
Usage: omz changelog [version]
|
||||
Usage: ${(j: :)${(s.::.)0#_}} [version]
|
||||
|
||||
NOTE: <version> must be a valid branch, tag or commit.
|
||||
EOF
|
||||
@@ -183,9 +193,9 @@ EOF
|
||||
}
|
||||
|
||||
function _omz::plugin {
|
||||
(( $# > 0 && $+functions[_omz::plugin::$1] )) || {
|
||||
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||
cat >&2 <<EOF
|
||||
Usage: omz plugin <command> [options]
|
||||
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||
|
||||
Available commands:
|
||||
|
||||
@@ -202,17 +212,17 @@ EOF
|
||||
local command="$1"
|
||||
shift
|
||||
|
||||
_omz::plugin::$command "$@"
|
||||
$0::$command "$@"
|
||||
}
|
||||
|
||||
function _omz::plugin::disable {
|
||||
if [[ -z "$1" ]]; then
|
||||
echo >&2 "Usage: omz plugin disable <plugin> [...]"
|
||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check that plugin is in $plugins
|
||||
local -a dis_plugins=()
|
||||
local -a dis_plugins
|
||||
for plugin in "$@"; do
|
||||
if [[ ${plugins[(Ie)$plugin]} -eq 0 ]]; then
|
||||
_omz::log warn "plugin '$plugin' is not enabled."
|
||||
@@ -266,9 +276,10 @@ multi == 1 && length(\$0) > 0 {
|
||||
{ print \$0 }
|
||||
"
|
||||
|
||||
awk "$awk_script" ~/.zshrc > ~/.zshrc.new \
|
||||
&& command mv -f ~/.zshrc ~/.zshrc.bck \
|
||||
&& command mv -f ~/.zshrc.new ~/.zshrc
|
||||
local zdot="${ZDOTDIR:-$HOME}"
|
||||
awk "$awk_script" "$zdot/.zshrc" > "$zdot/.zshrc.new" \
|
||||
&& command mv -f "$zdot/.zshrc" "$zdot/.zshrc.bck" \
|
||||
&& command mv -f "$zdot/.zshrc.new" "$zdot/.zshrc"
|
||||
|
||||
# Exit if the new .zshrc file wasn't created correctly
|
||||
[[ $? -eq 0 ]] || {
|
||||
@@ -278,10 +289,10 @@ multi == 1 && length(\$0) > 0 {
|
||||
}
|
||||
|
||||
# Exit if the new .zshrc file has syntax errors
|
||||
if ! zsh -n ~/.zshrc; then
|
||||
_omz::log error "broken syntax in ~/.zshrc. Rolling back changes..."
|
||||
command mv -f ~/.zshrc ~/.zshrc.new
|
||||
command mv -f ~/.zshrc.bck ~/.zshrc
|
||||
if ! command zsh -n "$zdot/.zshrc"; then
|
||||
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
||||
command mv -f "$zdot/.zshrc" "$zdot/.zshrc.new"
|
||||
command mv -f "$zdot/.zshrc.bck" "$zdot/.zshrc"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -296,12 +307,12 @@ multi == 1 && length(\$0) > 0 {
|
||||
|
||||
function _omz::plugin::enable {
|
||||
if [[ -z "$1" ]]; then
|
||||
echo >&2 "Usage: omz plugin enable <plugin> [...]"
|
||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Check that plugin is not in $plugins
|
||||
local -a add_plugins=()
|
||||
local -a add_plugins
|
||||
for plugin in "$@"; do
|
||||
if [[ ${plugins[(Ie)$plugin]} -ne 0 ]]; then
|
||||
_omz::log warn "plugin '$plugin' is already enabled."
|
||||
@@ -341,9 +352,10 @@ multi == 1 && /^[^#]*\)/ {
|
||||
{ print \$0 }
|
||||
"
|
||||
|
||||
awk "$awk_script" ~/.zshrc > ~/.zshrc.new \
|
||||
&& command mv -f ~/.zshrc ~/.zshrc.bck \
|
||||
&& command mv -f ~/.zshrc.new ~/.zshrc
|
||||
local zdot="${ZDOTDIR:-$HOME}"
|
||||
awk "$awk_script" "$zdot/.zshrc" > "$zdot/.zshrc.new" \
|
||||
&& command mv -f "$zdot/.zshrc" "$zdot/.zshrc.bck" \
|
||||
&& command mv -f "$zdot/.zshrc.new" "$zdot/.zshrc"
|
||||
|
||||
# Exit if the new .zshrc file wasn't created correctly
|
||||
[[ $? -eq 0 ]] || {
|
||||
@@ -353,10 +365,10 @@ multi == 1 && /^[^#]*\)/ {
|
||||
}
|
||||
|
||||
# Exit if the new .zshrc file has syntax errors
|
||||
if ! zsh -n ~/.zshrc; then
|
||||
_omz::log error "broken syntax in ~/.zshrc. Rolling back changes..."
|
||||
command mv -f ~/.zshrc ~/.zshrc.new
|
||||
command mv -f ~/.zshrc.bck ~/.zshrc
|
||||
if ! command zsh -n "$zdot/.zshrc"; then
|
||||
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
||||
command mv -f "$zdot/.zshrc" "$zdot/.zshrc.new"
|
||||
command mv -f "$zdot/.zshrc.bck" "$zdot/.zshrc"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -371,7 +383,7 @@ multi == 1 && /^[^#]*\)/ {
|
||||
|
||||
function _omz::plugin::info {
|
||||
if [[ -z "$1" ]]; then
|
||||
echo >&2 "Usage: omz plugin info <plugin>"
|
||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -418,14 +430,12 @@ function _omz::plugin::list {
|
||||
|
||||
function _omz::plugin::load {
|
||||
if [[ -z "$1" ]]; then
|
||||
echo >&2 "Usage: omz plugin load <plugin> [...]"
|
||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <plugin> [...]"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local plugins=("$@")
|
||||
local plugin base has_completion=0
|
||||
|
||||
for plugin in $plugins; do
|
||||
for plugin in "$@"; do
|
||||
if [[ -d "$ZSH_CUSTOM/plugins/$plugin" ]]; then
|
||||
base="$ZSH_CUSTOM/plugins/$plugin"
|
||||
elif [[ -d "$ZSH/plugins/$plugin" ]]; then
|
||||
@@ -445,9 +455,9 @@ function _omz::plugin::load {
|
||||
fi
|
||||
|
||||
# Check if it has completion to reload compinit
|
||||
if [[ -f "$base/_$plugin" ]]; then
|
||||
has_completion=1
|
||||
fi
|
||||
local -a comp_files
|
||||
comp_files=($base/_*(N))
|
||||
has_completion=$(( $#comp_files > 0 ))
|
||||
|
||||
# Load the plugin
|
||||
if [[ -f "$base/$plugin.plugin.zsh" ]]; then
|
||||
@@ -467,9 +477,9 @@ function _omz::plugin::load {
|
||||
}
|
||||
|
||||
function _omz::pr {
|
||||
(( $# > 0 && $+functions[_omz::pr::$1] )) || {
|
||||
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||
cat >&2 <<EOF
|
||||
Usage: omz pr <command> [options]
|
||||
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||
|
||||
Available commands:
|
||||
|
||||
@@ -483,7 +493,7 @@ EOF
|
||||
local command="$1"
|
||||
shift
|
||||
|
||||
_omz::pr::$command "$@"
|
||||
$0::$command "$@"
|
||||
}
|
||||
|
||||
function _omz::pr::clean {
|
||||
@@ -524,7 +534,7 @@ function _omz::pr::test {
|
||||
|
||||
# Check the input
|
||||
if ! [[ -n "$1" && "$1" =~ ^[[:digit:]]+$ ]]; then
|
||||
echo >&2 "Usage: omz pr test <PR_NUMBER_or_URL>"
|
||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <PR_NUMBER_or_URL>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -598,10 +608,20 @@ function _omz::pr::test {
|
||||
)
|
||||
}
|
||||
|
||||
function _omz::reload {
|
||||
# Delete current completion cache
|
||||
command rm -f $_comp_dumpfile $ZSH_COMPDUMP
|
||||
|
||||
# Old zsh versions don't have ZSH_ARGZERO
|
||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||
# Check whether to run a login shell
|
||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||
}
|
||||
|
||||
function _omz::theme {
|
||||
(( $# > 0 && $+functions[_omz::theme::$1] )) || {
|
||||
(( $# > 0 && $+functions[$0::$1] )) || {
|
||||
cat >&2 <<EOF
|
||||
Usage: omz theme <command> [options]
|
||||
Usage: ${(j: :)${(s.::.)0#_}} <command> [options]
|
||||
|
||||
Available commands:
|
||||
|
||||
@@ -616,7 +636,7 @@ EOF
|
||||
local command="$1"
|
||||
shift
|
||||
|
||||
_omz::theme::$command "$@"
|
||||
$0::$command "$@"
|
||||
}
|
||||
|
||||
function _omz::theme::list {
|
||||
@@ -630,22 +650,28 @@ function _omz::theme::list {
|
||||
return
|
||||
fi
|
||||
|
||||
# Print theme in use
|
||||
if [[ -n "$ZSH_THEME" ]]; then
|
||||
print -Pn "%U%BCurrent theme%b%u: "
|
||||
[[ $ZSH_THEME = random ]] && echo "$RANDOM_THEME (via random)" || echo "$ZSH_THEME"
|
||||
echo
|
||||
fi
|
||||
|
||||
# Print custom themes if there are any
|
||||
if (( ${#custom_themes} )); then
|
||||
print -P "%U%BCustom themes%b%u:"
|
||||
print -l ${(q-)custom_themes} | column -x
|
||||
echo
|
||||
fi
|
||||
|
||||
if (( ${#builtin_themes} )); then
|
||||
(( ${#custom_themes} )) && echo # add a line of separation
|
||||
|
||||
print -P "%U%BBuilt-in themes%b%u:"
|
||||
print -l ${(q-)builtin_themes} | column -x
|
||||
fi
|
||||
# Print built-in themes
|
||||
print -P "%U%BBuilt-in themes%b%u:"
|
||||
print -l ${(q-)builtin_themes} | column -x
|
||||
}
|
||||
|
||||
function _omz::theme::set {
|
||||
if [[ -z "$1" ]]; then
|
||||
echo >&2 "Usage: omz theme set <theme>"
|
||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <theme>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -674,17 +700,18 @@ END {
|
||||
}
|
||||
'
|
||||
|
||||
awk "$awk_script" ~/.zshrc > ~/.zshrc.new \
|
||||
local zdot="${ZDOTDIR:-$HOME}"
|
||||
awk "$awk_script" "$zdot/.zshrc" > "$zdot/.zshrc.new" \
|
||||
|| {
|
||||
# Prepend ZSH_THEME= line to .zshrc if it doesn't exist
|
||||
cat <<EOF
|
||||
ZSH_THEME="$1" # set by \`omz\`
|
||||
|
||||
EOF
|
||||
cat ~/.zshrc
|
||||
} > ~/.zshrc.new \
|
||||
&& command mv -f ~/.zshrc ~/.zshrc.bck \
|
||||
&& command mv -f ~/.zshrc.new ~/.zshrc
|
||||
cat "$zdot/.zshrc"
|
||||
} > "$zdot/.zshrc.new" \
|
||||
&& command mv -f "$zdot/.zshrc" "$zdot/.zshrc.bck" \
|
||||
&& command mv -f "$zdot/.zshrc.new" "$zdot/.zshrc"
|
||||
|
||||
# Exit if the new .zshrc file wasn't created correctly
|
||||
[[ $? -eq 0 ]] || {
|
||||
@@ -694,10 +721,10 @@ EOF
|
||||
}
|
||||
|
||||
# Exit if the new .zshrc file has syntax errors
|
||||
if ! zsh -n ~/.zshrc; then
|
||||
_omz::log error "broken syntax in ~/.zshrc. Rolling back changes..."
|
||||
command mv -f ~/.zshrc ~/.zshrc.new
|
||||
command mv -f ~/.zshrc.bck ~/.zshrc
|
||||
if ! command zsh -n "$zdot/.zshrc"; then
|
||||
_omz::log error "broken syntax in '"${zdot/#$HOME/\~}/.zshrc"'. Rolling back changes..."
|
||||
command mv -f "$zdot/.zshrc" "$zdot/.zshrc.new"
|
||||
command mv -f "$zdot/.zshrc.bck" "$zdot/.zshrc"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -712,7 +739,7 @@ EOF
|
||||
|
||||
function _omz::theme::use {
|
||||
if [[ -z "$1" ]]; then
|
||||
echo >&2 "Usage: omz theme use <theme>"
|
||||
echo >&2 "Usage: ${(j: :)${(s.::.)0#_}} <theme>"
|
||||
return 1
|
||||
fi
|
||||
|
||||
@@ -727,16 +754,20 @@ function _omz::theme::use {
|
||||
_omz::log error "%B$1%b theme not found"
|
||||
return 1
|
||||
fi
|
||||
|
||||
# Update theme settings
|
||||
ZSH_THEME="$1"
|
||||
[[ $1 = random ]] || unset RANDOM_THEME
|
||||
}
|
||||
|
||||
function _omz::update {
|
||||
local last_commit=$(cd "$ZSH"; git rev-parse HEAD)
|
||||
local last_commit=$(builtin cd -q "$ZSH"; git rev-parse HEAD)
|
||||
|
||||
# Run update script
|
||||
if [[ "$1" != --unattended ]]; then
|
||||
ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh" --interactive
|
||||
ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" --interactive || return $?
|
||||
else
|
||||
ZSH="$ZSH" zsh -f "$ZSH/tools/upgrade.sh"
|
||||
ZSH="$ZSH" command zsh -f "$ZSH/tools/upgrade.sh" || return $?
|
||||
fi
|
||||
|
||||
# Update last updated file
|
||||
@@ -746,10 +777,32 @@ function _omz::update {
|
||||
command rm -rf "$ZSH/log/update.lock"
|
||||
|
||||
# Restart the zsh session if there were changes
|
||||
if [[ "$1" != --unattended && "$(cd "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
||||
if [[ "$1" != --unattended && "$(builtin cd -q "$ZSH"; git rev-parse HEAD)" != "$last_commit" ]]; then
|
||||
# Old zsh versions don't have ZSH_ARGZERO
|
||||
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
|
||||
# Check whether to run a login shell
|
||||
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
|
||||
fi
|
||||
}
|
||||
|
||||
function _omz::version {
|
||||
(
|
||||
builtin cd -q "$ZSH"
|
||||
|
||||
# Get the version name:
|
||||
# 1) try tag-like version
|
||||
# 2) try branch name
|
||||
# 3) try name-rev (tag~<rev> or branch~<rev>)
|
||||
local version
|
||||
version=$(command git describe --tags HEAD 2>/dev/null) \
|
||||
|| version=$(command git symbolic-ref --quiet --short HEAD 2>/dev/null) \
|
||||
|| version=$(command git name-rev --no-undefined --name-only --exclude="remotes/*" HEAD 2>/dev/null) \
|
||||
|| version="<detached>"
|
||||
|
||||
# Get short hash for the current HEAD
|
||||
local commit=$(command git rev-parse --short HEAD 2>/dev/null)
|
||||
|
||||
# Show version and commit hash
|
||||
printf "%s (%s)\n" "$version" "$commit"
|
||||
)
|
||||
}
|
||||
|
||||
@@ -9,6 +9,7 @@ if [[ "$ENABLE_CORRECTION" == "true" ]]; then
|
||||
alias mv='nocorrect mv'
|
||||
alias mysql='nocorrect mysql'
|
||||
alias sudo='nocorrect sudo'
|
||||
alias su='nocorrect su'
|
||||
|
||||
setopt correct_all
|
||||
fi
|
||||
|
||||
@@ -335,7 +335,7 @@ function _omz_diag_dump_os_specific_version() {
|
||||
builtin echo "OS Version: $osname $osver build $(sw_vers -buildVersion)"
|
||||
;;
|
||||
cygwin)
|
||||
command systeminfo | command head -4 | command tail -2
|
||||
command systeminfo | command head -n 4 | command tail -n 2
|
||||
;;
|
||||
esac
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ alias -g .....='../../../..'
|
||||
alias -g ......='../../../../..'
|
||||
|
||||
alias -- -='cd -'
|
||||
alias 1='cd -'
|
||||
alias 1='cd -1'
|
||||
alias 2='cd -2'
|
||||
alias 3='cd -3'
|
||||
alias 4='cd -4'
|
||||
@@ -26,7 +26,7 @@ function d () {
|
||||
if [[ -n $1 ]]; then
|
||||
dirs "$@"
|
||||
else
|
||||
dirs -v | head -10
|
||||
dirs -v | head -n 10
|
||||
fi
|
||||
}
|
||||
compdef _dirs d
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
function zsh_stats() {
|
||||
fc -l 1 \
|
||||
| awk '{ CMD[$2]++; count++; } END { for (a in CMD) print CMD[a] " " CMD[a]*100/count "% " a }' \
|
||||
| grep -v "./" | sort -nr | head -20 | column -c3 -s " " -t | nl
|
||||
| grep -v "./" | sort -nr | head -n 20 | column -c3 -s " " -t | nl
|
||||
}
|
||||
|
||||
function uninstall_oh_my_zsh() {
|
||||
@@ -45,7 +45,7 @@ function takeurl() {
|
||||
data="$(mktemp)"
|
||||
curl -L "$1" > "$data"
|
||||
tar xf "$data"
|
||||
thedir="$(tar tf "$data" | head -1)"
|
||||
thedir="$(tar tf "$data" | head -n 1)"
|
||||
rm "$data"
|
||||
cd "$thedir"
|
||||
}
|
||||
@@ -237,12 +237,11 @@ function omz_urldecode {
|
||||
tmp=${tmp:gs/\\/\\\\/}
|
||||
# Handle %-escapes by turning them into `\xXX` printf escapes
|
||||
tmp=${tmp:gs/%/\\x/}
|
||||
local decoded
|
||||
eval "decoded=\$'$tmp'"
|
||||
local decoded="$(printf -- "$tmp")"
|
||||
|
||||
# Now we have a UTF-8 encoded string in the variable. We need to re-encode
|
||||
# it if caller is in a non-UTF-8 locale.
|
||||
local safe_encodings
|
||||
local -a safe_encodings
|
||||
safe_encodings=(UTF-8 utf8 US-ASCII)
|
||||
if [[ -z ${safe_encodings[(r)$caller_encoding]} ]]; then
|
||||
decoded=$(echo -E "$decoded" | iconv -f UTF-8 -t $caller_encoding)
|
||||
|
||||
@@ -29,7 +29,7 @@ function git_prompt_info() {
|
||||
&& upstream=" -> ${upstream}"
|
||||
fi
|
||||
|
||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref}${upstream}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||
echo "${ZSH_THEME_GIT_PROMPT_PREFIX}${ref:gs/%/%%}${upstream:gs/%/%%}$(parse_git_dirty)${ZSH_THEME_GIT_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
# Checks if working tree is dirty
|
||||
@@ -51,7 +51,7 @@ function parse_git_dirty() {
|
||||
FLAGS+="--ignore-submodules=${GIT_STATUS_IGNORE_SUBMODULES:-dirty}"
|
||||
;;
|
||||
esac
|
||||
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -1)
|
||||
STATUS=$(__git_prompt_git status ${FLAGS} 2> /dev/null | tail -n 1)
|
||||
fi
|
||||
if [[ -n $STATUS ]]; then
|
||||
echo "$ZSH_THEME_GIT_PROMPT_DIRTY"
|
||||
@@ -82,7 +82,7 @@ function git_remote_status() {
|
||||
fi
|
||||
|
||||
if [[ -n $ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_DETAILED ]]; then
|
||||
git_remote_status="$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX$remote$git_remote_status_detailed$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX"
|
||||
git_remote_status="$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_PREFIX${remote:gs/%/%%}$git_remote_status_detailed$ZSH_THEME_GIT_PROMPT_REMOTE_STATUS_SUFFIX"
|
||||
fi
|
||||
|
||||
echo $git_remote_status
|
||||
@@ -206,7 +206,8 @@ function git_prompt_status() {
|
||||
STASHED UNMERGED AHEAD BEHIND DIVERGED
|
||||
)
|
||||
|
||||
local status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)"
|
||||
local status_text
|
||||
status_text="$(__git_prompt_git status --porcelain -b 2> /dev/null)"
|
||||
|
||||
# Don't continue on a catastrophic failure
|
||||
if [[ $? -eq 128 ]]; then
|
||||
|
||||
@@ -2,5 +2,5 @@
|
||||
function nvm_prompt_info() {
|
||||
which nvm &>/dev/null || return
|
||||
local nvm_prompt=${$(nvm current)#v}
|
||||
echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt}${ZSH_THEME_NVM_PROMPT_SUFFIX}"
|
||||
echo "${ZSH_THEME_NVM_PROMPT_PREFIX}${nvm_prompt:gs/%/%%}${ZSH_THEME_NVM_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
@@ -30,7 +30,7 @@ function rvm_prompt_info() {
|
||||
local rvm_prompt
|
||||
rvm_prompt=$($HOME/.rvm/bin/rvm-prompt ${=ZSH_THEME_RVM_PROMPT_OPTIONS} 2>/dev/null)
|
||||
[[ -z "${rvm_prompt}" ]] && return 1
|
||||
echo "${ZSH_THEME_RUBY_PROMPT_PREFIX}${rvm_prompt}${ZSH_THEME_RUBY_PROMPT_SUFFIX}"
|
||||
echo "${ZSH_THEME_RUBY_PROMPT_PREFIX}${rvm_prompt:gs/%/%%}${ZSH_THEME_RUBY_PROMPT_SUFFIX}"
|
||||
}
|
||||
|
||||
ZSH_THEME_RVM_PROMPT_OPTIONS="i v g"
|
||||
|
||||
@@ -20,16 +20,18 @@ done
|
||||
|
||||
# Show all 256 colors with color number
|
||||
function spectrum_ls() {
|
||||
setopt localoptions nopromptsubst
|
||||
local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
|
||||
for code in {000..255}; do
|
||||
print -P -- "$code: $FG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}"
|
||||
print -P -- "$code: ${FG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
|
||||
done
|
||||
}
|
||||
|
||||
# Show all 256 colors where the background is set to specific color
|
||||
function spectrum_bls() {
|
||||
setopt localoptions nopromptsubst
|
||||
local ZSH_SPECTRUM_TEXT=${ZSH_SPECTRUM_TEXT:-Arma virumque cano Troiae qui primus ab oris}
|
||||
for code in {000..255}; do
|
||||
print -P -- "$code: $BG[$code]$ZSH_SPECTRUM_TEXT%{$reset_color%}"
|
||||
print -P -- "$code: ${BG[$code]}${ZSH_SPECTRUM_TEXT}%{$reset_color%}"
|
||||
done
|
||||
}
|
||||
|
||||
@@ -7,10 +7,10 @@
|
||||
# (In screen, only short_tab_title is used)
|
||||
# Limited support for Apple Terminal (Terminal can't set window and tab separately)
|
||||
function title {
|
||||
emulate -L zsh
|
||||
setopt prompt_subst
|
||||
setopt localoptions nopromptsubst
|
||||
|
||||
[[ "$INSIDE_EMACS" == *term* ]] && return
|
||||
# Don't set the title if inside emacs, unless using vterm
|
||||
[[ -n "${INSIDE_EMACS:-}" && "$INSIDE_EMACS" != vterm ]] && return
|
||||
|
||||
# if $2 is unset use $1 as default
|
||||
# if it is set and empty, leave it as is
|
||||
@@ -29,12 +29,9 @@ function title {
|
||||
print -Pn "\e]2;${2:q}\a" # set window name
|
||||
print -Pn "\e]1;${1:q}\a" # set tab name
|
||||
else
|
||||
# Try to use terminfo to set the title
|
||||
# If the feature is available set title
|
||||
if [[ -n "$terminfo[fsl]" ]] && [[ -n "$terminfo[tsl]" ]]; then
|
||||
echoti tsl
|
||||
print -Pn "$1"
|
||||
echoti fsl
|
||||
# Try to use terminfo to set the title if the feature is available
|
||||
if (( ${+terminfo[fsl]} && ${+terminfo[tsl]} )); then
|
||||
print -Pn "${terminfo[tsl]}$1${terminfo[fsl]}"
|
||||
fi
|
||||
fi
|
||||
;;
|
||||
@@ -50,13 +47,13 @@ fi
|
||||
|
||||
# Runs before showing the prompt
|
||||
function omz_termsupport_precmd {
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
|
||||
title $ZSH_THEME_TERM_TAB_TITLE_IDLE $ZSH_THEME_TERM_TITLE_IDLE
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return
|
||||
title "$ZSH_THEME_TERM_TAB_TITLE_IDLE" "$ZSH_THEME_TERM_TITLE_IDLE"
|
||||
}
|
||||
|
||||
# Runs before executing the command
|
||||
function omz_termsupport_preexec {
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" == true ]] && return
|
||||
[[ "${DISABLE_AUTO_TITLE:-}" != true ]] || return
|
||||
|
||||
emulate -L zsh
|
||||
setopt extended_glob
|
||||
@@ -99,16 +96,18 @@ function omz_termsupport_preexec {
|
||||
fi
|
||||
|
||||
# cmd name only, or if this is sudo or ssh, the next cmd
|
||||
local CMD=${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}
|
||||
local CMD="${1[(wr)^(*=*|sudo|ssh|mosh|rake|-*)]:gs/%/%%}"
|
||||
local LINE="${2:gs/%/%%}"
|
||||
|
||||
title '$CMD' '%100>...>$LINE%<<'
|
||||
title "$CMD" "%100>...>${LINE}%<<"
|
||||
}
|
||||
|
||||
autoload -U add-zsh-hook
|
||||
add-zsh-hook precmd omz_termsupport_precmd
|
||||
add-zsh-hook preexec omz_termsupport_preexec
|
||||
autoload -Uz add-zsh-hook
|
||||
|
||||
if [[ -z "$INSIDE_EMACS" || "$INSIDE_EMACS" = vterm ]]; then
|
||||
add-zsh-hook precmd omz_termsupport_precmd
|
||||
add-zsh-hook preexec omz_termsupport_preexec
|
||||
fi
|
||||
|
||||
# Keep Apple Terminal.app's current working directory updated
|
||||
# Based on this answer: https://superuser.com/a/315029
|
||||
|
||||
@@ -40,7 +40,7 @@ if [[ "$DISABLE_LS_COLORS" != "true" ]]; then
|
||||
fi
|
||||
|
||||
# enable diff color if possible.
|
||||
if command diff --color . . &>/dev/null; then
|
||||
if command diff --color /dev/null /dev/null &>/dev/null; then
|
||||
alias diff='diff --color'
|
||||
fi
|
||||
|
||||
|
||||
Reference in New Issue
Block a user