Compare commits

...
3 Commits
3 changed files with 103 additions and 59 deletions
+4 -4
View File
@@ -739,8 +739,8 @@ function _omz::reload {
# Old zsh versions don't have ZSH_ARGZERO
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
# anything that is not absolute (see #13919)
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="$commands[zsh]"
# anything that is not absolute via $PATH at exec time (see #13919)
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
# Check whether to run a login shell
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
}
@@ -923,8 +923,8 @@ function _omz::update {
# Old zsh versions don't have ZSH_ARGZERO
local zsh="${ZSH_ARGZERO:-${functrace[-1]%:*}}"
# ZSH_ARGZERO is how zsh was invoked, not the path to it, so re-resolve
# anything that is not absolute (see #13919)
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="$commands[zsh]"
# anything that is not absolute via $PATH at exec time (see #13919)
[[ "${zsh#-}" != /* ]] && (( $+commands[zsh] )) && zsh="zsh"
# Check whether to run a login shell
[[ "$zsh" = -* || -o login ]] && exec -l "${zsh#-}" || exec "$zsh"
fi
+77 -54
View File
@@ -13,69 +13,92 @@ ZSH_THEME_RUBY_PROMPT_PREFIX="("
ZSH_THEME_RUBY_PROMPT_SUFFIX=")"
# The command probes below fork a process each, and their result doesn't change
# from one shell to the next, so they're cached for a day (like lib/grep.zsh).
typeset -A __omz_probes
__omz_probe_cache="$ZSH_CACHE_DIR/appearance-probes"
__omz_probe_cached=("$__omz_probe_cache"(Nm-1))
[[ -z "$__omz_probe_cached" ]] || source "$__omz_probe_cache"
function __omz_test_cmd_args {
# Usage: __omz_test_cmd_args cmd args...
# Runs `cmd args... /dev/null` and remembers whether it succeeded, so a
# command needing two operands passes the first one itself:
# e.g. __omz_test_cmd_args gls --color -> gls --color /dev/null
# __omz_test_cmd_args diff --color /dev/null -> diff --color /dev/null /dev/null
local key="$*"
if (( ! ${+__omz_probes[$key]} )); then
command "$@" /dev/null &>/dev/null
__omz_probes[$key]=$?
if [[ -w "$ZSH_CACHE_DIR" ]]; then
print -r -- "__omz_probes=(" "${(@qqkv)__omz_probes}" ")" >| "$__omz_probe_cache"
fi
fi
return $__omz_probes[$key]
}
# Use diff --color if available
if command diff --color /dev/null{,} &>/dev/null; then
if __omz_test_cmd_args diff --color /dev/null; then
function diff {
command diff --color "$@"
}
fi
# Don't set ls coloring if disabled
[[ "$DISABLE_LS_COLORS" != true ]] || return 0
# Set up ls coloring. Done in a function so the early return below still
# reaches the cleanup at the end of this file.
() {
# Don't set ls coloring if disabled
[[ "$DISABLE_LS_COLORS" != true ]] || return 0
# Default coloring for BSD-based ls
export LSCOLORS="Gxfxcxdxbxegedabagacad"
# Default coloring for BSD-based ls
export LSCOLORS="Gxfxcxdxbxegedabagacad"
# Default coloring for GNU-based ls
if [[ -z "$LS_COLORS" ]]; then
# Define LS_COLORS via dircolors if available. Otherwise, set a default
# equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
if (( $+commands[dircolors] )); then
[[ -f "$HOME/.dircolors" ]] \
&& source <(dircolors -b "$HOME/.dircolors") \
|| source <(dircolors -b)
else
export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
# Default coloring for GNU-based ls
if [[ -z "$LS_COLORS" ]]; then
# Define LS_COLORS via dircolors if available. Otherwise, set a default
# equivalent to LSCOLORS (generated via https://geoff.greer.fm/lscolors)
if (( $+commands[dircolors] )); then
[[ -f "$HOME/.dircolors" ]] \
&& source <(dircolors -b "$HOME/.dircolors") \
|| source <(dircolors -b)
else
export LS_COLORS="di=1;36:ln=35:so=32:pi=33:ex=31:bd=34;46:cd=34;43:su=30;41:sg=30;46:tw=30;42:ow=30;43"
fi
fi
fi
function test-ls-args {
# Usage: test-ls-args cmd args...
# e.g. test-ls-args gls --color
command "$@" /dev/null &>/dev/null
# Find the option for using colors in ls, depending on the version
case "$OSTYPE" in
netbsd*)
# On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
__omz_test_cmd_args gls --color && alias ls='gls --color=tty'
;;
openbsd*)
# On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
# with color and multibyte support) are available from ports.
# `colorls` will be installed on purpose and can't be pulled in by installing
# coreutils (which might be installed for ), so prefer it to `gls`.
__omz_test_cmd_args gls --color && alias ls='gls --color=tty'
__omz_test_cmd_args colorls -G && alias ls='colorls -G'
;;
(darwin|freebsd)*)
# This alias works by default just using $LSCOLORS
__omz_test_cmd_args ls -G && alias ls='ls -G'
# Only use GNU ls if installed and there are user defaults for $LS_COLORS,
# as the default coloring scheme is not very pretty
zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
&& __omz_test_cmd_args gls --color \
&& alias ls='gls --color=tty'
;;
*)
if __omz_test_cmd_args ls --color; then
alias ls='ls --color=tty'
elif __omz_test_cmd_args ls -G; then
alias ls='ls -G'
fi
;;
esac
}
# Find the option for using colors in ls, depending on the version
case "$OSTYPE" in
netbsd*)
# On NetBSD, test if `gls` (GNU ls) is installed (this one supports colors);
# otherwise, leave ls as is, because NetBSD's ls doesn't support -G
test-ls-args gls --color && alias ls='gls --color=tty'
;;
openbsd*)
# On OpenBSD, `gls` (ls from GNU coreutils) and `colorls` (ls from base,
# with color and multibyte support) are available from ports.
# `colorls` will be installed on purpose and can't be pulled in by installing
# coreutils (which might be installed for ), so prefer it to `gls`.
test-ls-args gls --color && alias ls='gls --color=tty'
test-ls-args colorls -G && alias ls='colorls -G'
;;
(darwin|freebsd)*)
# This alias works by default just using $LSCOLORS
test-ls-args ls -G && alias ls='ls -G'
# Only use GNU ls if installed and there are user defaults for $LS_COLORS,
# as the default coloring scheme is not very pretty
zstyle -t ':omz:lib:theme-and-appearance' gnu-ls \
&& test-ls-args gls --color \
&& alias ls='gls --color=tty'
;;
*)
if test-ls-args ls --color; then
alias ls='ls --color=tty'
elif test-ls-args ls -G; then
alias ls='ls -G'
fi
;;
esac
unfunction test-ls-args
unfunction __omz_test_cmd_args
unset __omz_probes __omz_probe_cache __omz_probe_cached
+22 -1
View File
@@ -100,7 +100,28 @@ done
# Figure out the SHORT hostname
if [[ "$OSTYPE" = darwin* ]]; then
# macOS's $HOST changes with dhcp, etc. Use LocalHostName if possible.
SHORT_HOST=$(scutil --get LocalHostName 2>/dev/null) || SHORT_HOST="${HOST/.*/}"
# scutil costs a fork on every start, so remember its answer for a day
# (like lib/grep.zsh) and re-check sooner if $HOST changes.
__omz_host_cache="$ZSH_CACHE_DIR/localhostname"
__omz_host_cached=("$__omz_host_cache"(Nm-1))
__omz_host_key=
SHORT_HOST=
if [[ -n "$__omz_host_cached" ]]; then
if ! { read -r __omz_host_key && read -r SHORT_HOST } < "$__omz_host_cache"; then
__omz_host_key=
SHORT_HOST=
fi
fi
if [[ "$__omz_host_key" != "$HOST" || -z "$SHORT_HOST" ]]; then
# only cache what scutil actually answered, so a transient failure
# doesn't pin the fallback name for a day
if SHORT_HOST=$(scutil --get LocalHostName 2>/dev/null) && [[ -n "$SHORT_HOST" ]]; then
[[ ! -w "$ZSH_CACHE_DIR" ]] || print -rl -- "$HOST" "$SHORT_HOST" >| "$__omz_host_cache"
else
SHORT_HOST="${HOST/.*/}"
fi
fi
unset __omz_host_cache __omz_host_cached __omz_host_key
else
SHORT_HOST="${HOST/.*/}"
fi