From: Moviuro Date: Sun, 12 Apr 2015 10:32:36 +0000 (+0200) Subject: zshrc: we use getopts on salias() X-Git-Tag: v0.12.0~15 X-Git-Url: http://git.grml.org/?p=grml-etc-core.git;a=commitdiff_plain;h=8945506c355c0e705ebe8a8f035a419d9459ca5f zshrc: we use getopts on salias() (cherry picked from commit 89722563578cb8d48678f9db57fb987278283be8) Closes #35 @ github --- diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 33524bd..1b8648d 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -418,23 +418,22 @@ salias() { emulate -L zsh local only=0 ; local multi=0 local key val - while [[ $1 == -* ]] ; do - case $1 in - (-o) only=1 ;; - (-a) multi=1 ;; - (--) shift ; break ;; - (-h) - printf 'usage: salias [-h|-o|-a] \n' + while getopts ":hao" opt; do + case $opt in + o) only=1 ;; + a) multi=1 ;; + h) + printf 'usage: salias [-hoa] \n' printf ' -h shows this help text.\n' printf ' -a replace '\'' ; '\'' sequences with '\'' ; sudo '\''.\n' printf ' be careful using this option.\n' printf ' -o only sets an alias if a preceding sudo would be needed.\n' return 0 ;; - (*) printf "unkown option: '%s'\n" "$1" ; return 1 ;; + *) salias -h >&2; return 1 ;; esac - shift done + shift "$((OPTIND-1))" if (( ${#argv} > 1 )) ; then printf 'Too many arguments %s\n' "${#argv}"