From 8945506c355c0e705ebe8a8f035a419d9459ca5f Mon Sep 17 00:00:00 2001 From: Moviuro Date: Sun, 12 Apr 2015 12:32:36 +0200 Subject: [PATCH] zshrc: we use getopts on salias() (cherry picked from commit 89722563578cb8d48678f9db57fb987278283be8) Closes #35 @ github --- etc/zsh/zshrc | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) 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}" -- 2.1.4