1
0
Fork 0

shortmapped commands will now only be executed while within a git repository

master
Mike Gerwitz 2011-10-18 17:15:35 -04:00
parent 2b2452dda9
commit 8dd10a69bb
No known key found for this signature in database
GPG Key ID: F22BB8158EE30EAB
1 changed files with 21 additions and 4 deletions

View File

@ -32,19 +32,36 @@ __git-short_shortmap ()
$( awk "/^$1 / { print \$2 }" <<< "$__git_short_maps" ) $( awk "/^$1 / { print \$2 }" <<< "$__git_short_maps" )
} }
__git-short_shortalias ()
{
cmd=$1
shift
# if we're not within a git dir, fall back to an actual command of this name
__gitdir >/dev/null || {
" $cmd $@"
return $?
}
# execute the command
$( grep "^$cmd" <<< "$__git_short_maps" | cut -d' ' -f3- ) "$@"
}
# load shortmaps from cwd (or provided path) and home dir (if available) # load shortmaps from cwd (or provided path) and home dir (if available)
__git_short_maps=$( cat ${1:-./shortmaps} ~/.git-shortmaps 2>/dev/null ) __git_short_maps=$(
cat ${1:-./shortmaps} ~/.git-shortmaps 2>/dev/null \
| sed 's/^\([^ ]\+ [^ ]\+\) :/\1 git /'
)
# register each shortmap # register each shortmap
IFS=$'\n' IFS=$'\n'
for line in $__git_short_maps; do for line in $__git_short_maps; do
IFS=$' ' IFS=$' '
set -- $line set -- $line
short=$1
[ -z "$1" ] && continue [ -z "$1" ] && continue
__git-short_docomplete "$1" __git-short_shortmap __git-short_docomplete "$1" __git-short_shortmap
shift 2 alias $1="__git-short_shortalias $1"
alias $short="$( sed 's/^:/git /' <<< "$@" )"
done done