tj.git-extras/bin/git-alias
spacewander 98a1820d39 abort git-alias when too many arguments given.
Avoid incorrect usage probably because of the missing quotes, like "git
alias cm checkout master"
2015-08-09 19:27:49 +08:00

17 lines
489 B
Bash
Executable file

#!/usr/bin/env bash
usage() {
cat <<HERE
usage: git alias # list all aliases
or: git alias <search-pattern> # show aliases matching pattern
or: git alias <alias-name> <command> # alias a command
HERE
}
case $# in
0) git config --get-regexp 'alias.*' | sed 's/^alias\.//' | sed 's/[ ]/ = /' | sort ;;
1) git alias | grep -e "$1" ;;
2) git config --global alias."$1" "$2" ;;
*) >&2 echo "error: too many arguments." && usage && exit 1 ;;
esac