1
0
mirror of https://github.com/dcarrillo/prezto.git synced 2024-12-23 01:17:59 +00:00

Standardized error messages.

This commit is contained in:
Sorin Ionescu 2012-01-19 02:28:01 -05:00
parent 28da8f916b
commit 95c29bada8
10 changed files with 33 additions and 29 deletions

View File

@ -19,7 +19,7 @@ TRAP_SIGNALS=(
# Adds a function to a list to be called when a trap is triggered. # Adds a function to a list to be called when a trap is triggered.
function add-zsh-trap() { function add-zsh-trap() {
if (( $# < 2 )); then if (( $# < 2 )); then
print "Usage: $0 type function" print "usage: $0 type function"
return 1 return 1
fi fi

View File

@ -3,7 +3,7 @@
# Check for the minimum supported version. # Check for the minimum supported version.
min_zsh_version='4.3.10' min_zsh_version='4.3.10'
if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then if ! autoload -Uz is-at-least || ! is-at-least "$min_zsh_version"; then
print "omz: The minimum supported Zsh version is $min_zsh_version." print "omz: too old shell version detected, minimum required: $min_zsh_version"
fi fi
unset min_zsh_version unset min_zsh_version

View File

@ -4,12 +4,14 @@ local file_name
local extract_dir local extract_dir
if (( $# == 0 )); then if (( $# == 0 )); then
print "Usage: extract [-option] [file ...]" cat >&2 <<EOF
print usage: $0 [-option] [file ...]
print "Options:"
print " -r, --remove Remove archive." options:
print -r, --remove remove archive
print "Report bugs to <sorin.ionescu@gmail.com>."
Report bugs to <sorin.ionescu@gmail.com>.
EOF
fi fi
remove_archive=1 remove_archive=1
@ -20,7 +22,7 @@ fi
while (( $# > 0 )); do while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then if [[ ! -f "$1" ]]; then
print "extract: '$1' is not a valid file" 1>&2 print "$0: file not valid: $1" >&2
shift shift
continue continue
fi fi
@ -56,7 +58,7 @@ while (( $# > 0 )); do
cd .. cd ..
;; ;;
(*) (*)
print "extract: '$1' cannot be extracted" 1>&2 print "$0: cannot extract: $1" >&2
success=1 success=1
;; ;;
esac esac

View File

@ -1,12 +1,14 @@
local verbose local verbose
if (( $# == 0 )); then if (( $# == 0 )); then
print "Usage: extract [-option] [file ...]" cat >&2 <<EOF
print usage: $0 [-option] [file ...]
print "Options:"
print " -v, --verbose Verbose archive listing." options:
print -v, --verbose verbose archive listing
print "Report bugs to <sorin.ionescu@gmail.com>."
Report bugs to <sorin.ionescu@gmail.com>.
EOF
fi fi
if [[ "$1" == "-v" ]] || [[ "$1" == "--verbose" ]]; then if [[ "$1" == "-v" ]] || [[ "$1" == "--verbose" ]]; then
@ -16,7 +18,7 @@ fi
while (( $# > 0 )); do while (( $# > 0 )); do
if [[ ! -f "$1" ]]; then if [[ ! -f "$1" ]]; then
print "extract: '$1' is not a valid file" 1>&2 print "$0: file not valid: $1" >&2
shift shift
continue continue
fi fi
@ -35,7 +37,7 @@ while (( $# > 0 )); do
(*.rar) unrar ${${verbose:+v}:-l} "$1" ;; (*.rar) unrar ${${verbose:+v}:-l} "$1" ;;
(*.7z) 7za l "$1" ;; (*.7z) 7za l "$1" ;;
(*) (*)
print "ls-archive: '$1' cannot be listed" 1>&2 print "$0: cannot list: $1" >&2
success=1 success=1
;; ;;
esac esac

View File

@ -30,11 +30,11 @@ if [[ -n "$url" ]]; then
"$BROWSER" "$url" "$BROWSER" "$url"
return 0 return 0
else else
print "fatal: Browser not set or set to a non-existent browser." >&2 print "$0: browser not set or set to a non-existent browser" >&2
return 1 return 1
fi fi
else else
print "fatal: Not a Git repository or origin remote not set." >&2 print "$0: not a Git repository or remote origin not set" >&2
return 1 return 1
fi fi

View File

@ -64,7 +64,7 @@ function _git-info-abort() {
return 1 return 1
fi fi
cat > /dev/stderr <<END cat >&2 <<EOF
Gathering status for certain repositories is time intensive. Gathering status for certain repositories is time intensive.
@ -74,7 +74,7 @@ for this repository.
To revert, execute: To revert, execute:
git-info on git-info on
END EOF
unset _git_info_executing unset _git_info_executing
git config --bool prompt.showinfo false git config --bool prompt.showinfo false
@ -156,7 +156,7 @@ function git-info() {
elif [[ "$1" == [Oo][Ff][Ff] ]]; then elif [[ "$1" == [Oo][Ff][Ff] ]]; then
git config --bool prompt.showinfo false git config --bool prompt.showinfo false
else else
print "Usage: $0 [ on | off ]" print "usage: $0 [ on | off ]" >&2
fi fi
return 0 return 0
fi fi

View File

@ -149,7 +149,7 @@ if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
{ {
# Load Zsh module zsh/zleparameter, needed to override user defined widgets. # Load Zsh module zsh/zleparameter, needed to override user defined widgets.
zmodload zsh/zleparameter 2>/dev/null || { zmodload zsh/zleparameter 2>/dev/null || {
print 'zsh-syntax-highlighting: failed loading zsh/zleparameter.' >&2 print 'history-substring-search: failed loading: zsh/zleparameter' >&2
return 1 return 1
} }
@ -176,7 +176,7 @@ if [[ $+functions[_zsh_highlight] -eq 0 ]]; then
zle -N $cur_widget _zsh_highlight_widget_$cur_widget";; zle -N $cur_widget _zsh_highlight_widget_$cur_widget";;
# Default: unhandled case. # Default: unhandled case.
*) print "zsh-syntax-highlighting: unhandled ZLE widget '$cur_widget'" >&2 ;; *) print "history-substring-search: unhandled ZLE widget: $cur_widget" >&2 ;;
esac esac
done done
} }

View File

@ -1,6 +1,6 @@
# Perl Global Substitution # Perl Global Substitution
if (( $# < 2 )); then if (( $# < 2 )); then
print "Usage: $0 find replace [file ...]" >&2 print "usage: $0 find replace [file ...]" >&2
return 1 return 1
fi fi

View File

@ -1,6 +1,6 @@
# Perl grep since 'grep -P' is terrible. # Perl grep since 'grep -P' is terrible.
if (( $# < 1 )) ; then if (( $# < 1 )) ; then
print "Usage: $0 pattern [file ...]" >&2 print "usage: $0 pattern [file ...]" >&2
return 1 return 1
fi fi

View File

@ -1,11 +1,11 @@
local config_file="$HOME/.wakeonlan/$1" local config_file="$HOME/.wakeonlan/$1"
if [[ ! -f "$config_file" ]]; then if [[ ! -f "$config_file" ]]; then
print "$0: $1: There is no such device file." >&2 print "$0: no such device file: $1" >&2
return 1 return 1
fi fi
if (( ! $+commands[wakeonlan] )); then if (( ! $+commands[wakeonlan] )); then
print "$0: Can't find wakeonlan. Is it installed?" >&2 print "$0: command not found: wakeonlan" >&2
return 1 return 1
fi fi