From 5e7f99c2ed233b4d4dbb6eed3391b0579630748e Mon Sep 17 00:00:00 2001 From: wsq Date: Mon, 12 Aug 2019 17:13:08 +0800 Subject: [PATCH] fix gc and gcm --- zsh/functions.zsh | 44 +++++++++++++++++++++++++------------------- 1 file changed, 25 insertions(+), 19 deletions(-) diff --git a/zsh/functions.zsh b/zsh/functions.zsh index 4d0e4bb..0a2e781 100644 --- a/zsh/functions.zsh +++ b/zsh/functions.zsh @@ -350,29 +350,35 @@ function dc { function get_ip_of_ssh_hostname { ssh -G $1 | awk '/^hostname / { print $2 }' } -function gcn { +unalias gc +unalias gcm +function gc { while true;do - typeset -A users - users=('1' 'hophacker' '2' 'zhcalvin' '6' 'wsq') - for k in "${(@k)users}"; do - echo "$k || $users[$k]" + users=($GIT_USERS) + for ((i=1; i<=${#users[@]}; i++)) do + echo "$i | $users[$i]" done + echo 'please input your number or name:' read input - if [[ ! -z $users[$input] ]];then - name=$users[$input] - break - else - for k in "${(@k)users}"; do - if [[ $input == $users[$k] ]];then - name=$input + for ((i=1; i<=${#users[@]}; i++)) do + if [[ $input == $users[$i] ]];then + name=$input + index=$i + break 2 + elif [[ "$input" =~ '^[0-9]+$' ]];then + if [[ $input -gt 0 && $input -le ${#users[@]} ]];then + name=$users[$input] + index=$input break 2 fi - done - echo 'invalid option...' - fi + fi + done + echo 'invalid option...' done - typeset -A emails - emails=('hophacker' 'j' 'zhcalvin' 'c' 'wsq' 'wsq') - set -x - git commit --amend --author="$name<$emails[$name]@paiyou.co>" $* + emails=($GIT_EMAILS) + (git commit --verbose $*) || return + (git commit --amend --author="$name <$emails[$index]>") || return +} +function gcm { + (gc --message $*) || return }