From cbe11aa654dd53f621076532c61f5a24609e06ec Mon Sep 17 00:00:00 2001 From: Moviuro Date: Sun, 12 Apr 2015 12:33:06 +0200 Subject: [PATCH] zshrc: bk(): better usage/help handling (cherry picked from commit d5c988cdc11d6fc07146e25058f182ee1f94a4a4) Closes #36 @ github --- etc/zsh/zshrc | 24 +++++++++++------------- 1 file changed, 11 insertions(+), 13 deletions(-) diff --git a/etc/zsh/zshrc b/etc/zsh/zshrc index 1b8648d..2e0cafa 100644 --- a/etc/zsh/zshrc +++ b/etc/zsh/zshrc @@ -3027,8 +3027,15 @@ bk() { local current_date=$(date -u "+%Y-%m-%dT%H:%M:%SZ") local clean keep move verbose result all setopt extended_glob - usage() { - cat << EOT + keep=1 + while getopts ":hacmrv" opt; do + case $opt in + a) (( all++ ));; + c) unset move clean && (( ++keep ));; + m) unset keep clean && (( ++move ));; + r) unset move keep && (( ++clean ));; + v) verbose="-v";; + h) cat << EOT bk [-hcmv] FILE [FILE ...] bk -r [-av] [FILE [FILE ...]] Backup a file or folder in place and append the timestamp @@ -3048,17 +3055,8 @@ the last one is used. The return code is the sum of all cp/mv/rm return codes. EOT - } - keep=1 - while getopts ":hacmrv" opt; do - case $opt in - a) (( all++ ));; - c) unset move clean && (( ++keep ));; - m) unset keep clean && (( ++move ));; - r) unset move keep && (( ++clean ));; - v) verbose="-v";; - h) usage;; - \?) usage >&2; return 1;; +; return 0;; + \?) bk -h >&2; return 1;; esac done shift "$((OPTIND-1))" -- 2.1.4