mirror of
https://github.com/dcarrillo/prezto.git
synced 2025-06-14 08:41:43 +00:00
Added helper functions.
This commit is contained in:
@ -2,7 +2,7 @@ setopt correct # Correct commands.
|
||||
setopt correct_all # Correct all arguments.
|
||||
|
||||
# The 'ls' Family
|
||||
if [[ "$DISABLE_COLOR" != 'true' ]]; then
|
||||
if ! check-bool "$DISABLE_COLOR"; then
|
||||
if [[ -f "$HOME/.dir_colors" ]] && ( (( $+commands[dircolors] )) || ( (( $+plugins[(er)gnu-utils] )) && (( $+commands[gdircolors] )) ) ); then
|
||||
eval $("${commands[dircolors]:-$commands[gdircolors]}" "$HOME/.dir_colors")
|
||||
alias ls='ls -hF --group-directories-first --color=auto'
|
||||
@ -80,7 +80,7 @@ else
|
||||
fi
|
||||
|
||||
# Diff/Make
|
||||
if [[ "$DISABLE_COLOR" != 'true' ]]; then
|
||||
if ! check-bool "$DISABLE_COLOR"; then
|
||||
if (( $+commands[colordiff] )); then
|
||||
alias diff='colordiff -u'
|
||||
compdef colordiff=diff
|
||||
|
@ -64,7 +64,7 @@ export VISUAL="vim"
|
||||
export PAGER='less'
|
||||
|
||||
# Grep
|
||||
if [[ "$DISABLE_COLOR" != 'true' ]]; then
|
||||
if ! check-bool "$DISABLE_COLOR"; then
|
||||
export GREP_COLOR='37;45'
|
||||
export GREP_OPTIONS='--color=auto'
|
||||
fi
|
||||
@ -89,7 +89,7 @@ if (( $+commands[lesspipe.sh] )); then
|
||||
fi
|
||||
|
||||
# Termcap
|
||||
if [[ "$DISABLE_COLOR" != 'true' ]]; then
|
||||
if ! check-bool "$DISABLE_COLOR"; then
|
||||
export LESS_TERMCAP_mb=$'\E[01;31m' # begin blinking
|
||||
export LESS_TERMCAP_md=$'\E[01;31m' # begin bold
|
||||
export LESS_TERMCAP_me=$'\E[0m' # end mode
|
||||
|
50
functions/helper.zsh
Normal file
50
functions/helper.zsh
Normal file
@ -0,0 +1,50 @@
|
||||
# Checks if a file can be autoloaded by trying to load it in a subshell.
|
||||
function autoloadable() {
|
||||
( unfunction $1 ; autoload -U +X $1 ) &> /dev/null
|
||||
}
|
||||
|
||||
# Checks boolean variable for "true" (case insensitive "1", "y", "yes", "t", "true", "o", and "on").
|
||||
function check-bool {
|
||||
[[ -n "$1" && "$1" == (1|[Yy]([Ee][Ss]|)|[Tt]([Rr][Uu][Ee]|)|[Oo]([Nn]|)) ]]
|
||||
}
|
||||
|
||||
# Trap signals were generated with 'kill -l'.
|
||||
# DEBUG, EXIT, and ZERR are ZSH signals.
|
||||
TRAP_SIGNALS=(
|
||||
ABRT ALRM BUS CHLD CONT EMT FPE HUP ILL INFO INT IO KILL PIPE PROF QUIT
|
||||
SEGV STOP SYS TERM TRAP TSTP TTIN TTOU URG USR1 USR2 VTALRM WINCH XCPU XFSZ
|
||||
DEBUG EXIT ZERR
|
||||
)
|
||||
|
||||
# Adds a function to a list to be called when a trap is triggered.
|
||||
function add-zsh-trap {
|
||||
if (( $# < 2 )); then
|
||||
echo "Usage: $0 type function"
|
||||
return 1
|
||||
fi
|
||||
|
||||
if [[ -z "$TRAP_SIGNALS[(r)$1]" ]]; then
|
||||
echo "$0: unknown signal: $1"
|
||||
return 1
|
||||
fi
|
||||
|
||||
local trap_functions="TRAP${1}_FUNCTIONS"
|
||||
if (( ! ${(P)+trap_functions} )); then
|
||||
typeset -gaU "$trap_functions"
|
||||
fi
|
||||
eval "$trap_functions+="$2""
|
||||
|
||||
if (( ! $+functions[TRAP${1}] )); then
|
||||
eval "
|
||||
function TRAP${1}() {
|
||||
for trap_function in \"\$TRAP${1}_FUNCTIONS[@]\"; do
|
||||
if (( \$+functions[\$trap_function] )); then
|
||||
\"\$trap_function\" \"\$1\"
|
||||
fi
|
||||
done
|
||||
return \$(( 128 + \$1 ))
|
||||
}
|
||||
"
|
||||
fi
|
||||
}
|
||||
|
@ -14,7 +14,7 @@ fi
|
||||
# Partially supports Mac OS X Terminal since it can't set window and tab separately.
|
||||
# Usage: title "tab title" "window title"
|
||||
function terminal-title {
|
||||
if [[ "$DISABLE_AUTO_TITLE" != 'true' ]]; then
|
||||
if ! check-bool "$DISABLE_AUTO_TITLE"; then
|
||||
if [[ "$TERM" == screen* ]]; then
|
||||
# Set GNU Screen's hardstatus (usually truncated at 20 characters).
|
||||
printf "\ek%s\e\\" ${(V)1}
|
||||
|
Reference in New Issue
Block a user