mirror of
https://github.com/paulirish/git-recent.git
synced 2026-09-10 07:26:16 -04:00
Accept count as '-X' as well, add usage and error handling
Also make shellcheck happy.
This commit is contained in:
parent
1985391134
commit
460a3e479c
43
git-recent
43
git-recent
|
|
@ -18,20 +18,43 @@ case $(uname -s) in
|
||||||
;;
|
;;
|
||||||
esac
|
esac
|
||||||
|
|
||||||
|
function ensure_integer() {
|
||||||
|
if ! [[ "$1" =~ ^[1-9][0-9]*$ ]]; then
|
||||||
|
echo "error: -n requires an integer argument."
|
||||||
|
exit 1
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
function usage() {
|
||||||
|
echo "Usage: git recent [-n <num> | -<num>]"
|
||||||
|
echo " List latest local git branches, formatted real fancy."
|
||||||
|
}
|
||||||
|
|
||||||
COUNT=0
|
COUNT=0
|
||||||
while getopts "n:" opt; do
|
while [[ $# -gt 0 ]]; do
|
||||||
case ${opt} in
|
case "$1" in
|
||||||
n )
|
-n )
|
||||||
if ! [[ $OPTARG =~ ^[0-9]{1,}$ ]]; then
|
COUNT="$2"
|
||||||
echo "-n should be an integer."
|
ensure_integer "$COUNT"
|
||||||
exit 1
|
|
||||||
fi
|
|
||||||
COUNT=${OPTARG}
|
|
||||||
shift
|
shift
|
||||||
;;
|
;;
|
||||||
|
-[1-9]* | -n[1-9]* )
|
||||||
|
COUNT="${1#-}"
|
||||||
|
COUNT="${COUNT#n}"
|
||||||
|
ensure_integer "$COUNT"
|
||||||
|
;;
|
||||||
|
-h | --h* )
|
||||||
|
usage
|
||||||
|
exit 0
|
||||||
|
;;
|
||||||
|
* )
|
||||||
|
echo "error: unknown argument '$1'"
|
||||||
|
usage
|
||||||
|
exit 1
|
||||||
|
;;
|
||||||
esac
|
esac
|
||||||
|
shift
|
||||||
done
|
done
|
||||||
shift $((OPTIND-1))
|
|
||||||
|
|
||||||
format="\
|
format="\
|
||||||
%(HEAD) \
|
%(HEAD) \
|
||||||
|
|
@ -48,7 +71,7 @@ lessopts="--tabs=4 --quit-if-one-screen --RAW-CONTROL-CHARS --no-init"
|
||||||
|
|
||||||
git for-each-ref \
|
git for-each-ref \
|
||||||
--color=always \
|
--color=always \
|
||||||
--count=$COUNT \
|
--count="$COUNT" \
|
||||||
--sort=-committerdate \
|
--sort=-committerdate \
|
||||||
"refs/heads/" \
|
"refs/heads/" \
|
||||||
--format="$format" \
|
--format="$format" \
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue