From 514bf95d27a74a945cb9d852616f6feb5caed542 Mon Sep 17 00:00:00 2001 From: Kevin Ramsunder Date: Thu, 11 Oct 2018 14:34:55 -0400 Subject: [PATCH] Add count parameter (-n) (#12) --- git-recent | 16 ++++++++++++++++ readme.md | 8 ++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/git-recent b/git-recent index bed275e..cb1fad7 100755 --- a/git-recent +++ b/git-recent @@ -18,6 +18,20 @@ case $(uname -s) in ;; esac +while getopts "n:" opt; do + case ${opt} in + n ) + if ! [[ $OPTARG =~ ^[0-9]{1,}$ ]]; then + echo "-n should be an integer." + exit 1 + fi + COUNT=${OPTARG} + shift + ;; + esac +done +shift $((OPTIND-1)) + format="\ %(HEAD) \ $branch|\ @@ -33,6 +47,7 @@ lessopts="--tabs=4 --quit-if-one-screen --RAW-CONTROL-CHARS --no-init" git for-each-ref \ --color=always \ + --count=$COUNT \ --sort=-committerdate \ "refs/heads/" \ --format="$format" \ @@ -42,6 +57,7 @@ git for-each-ref \ # The above command: # for all known branches, # (force coloring on this, especially since it's being piped) +# optionally, specify the number of branches you want to display # sort descending by last commit # show local branches (change to "" to include both local + remote branches) # apply the formatting template above diff --git a/readme.md b/readme.md index 16275d0..d900e2c 100644 --- a/readme.md +++ b/readme.md @@ -7,9 +7,13 @@ Type `git recent` to see your latest local git branches git recent +Optionally, add `-n` to see the most recent `` branches + + git recent -n5 + ![git-recent screenshot](https://cloud.githubusercontent.com/assets/39191/17446638/039d4cee-5aff-11e6-9e11-4294f0020513.png) -If you're a Windows user, you need to use [Git Bash](https://git-scm.com/downloads) or similar shell in order to effectively use this utility. +If you're a Windows user, you need to use [Git Bash](https://git-scm.com/downloads) or similar shell in order to effectively use this utility. ### Installation @@ -19,7 +23,7 @@ or copy `git-recent` into an existing included path like `/usr/local/bin` or `~/ You can use also `npm` to install the global binary: npm install --global git-recent - + On Mac, you can install with homebrew: brew install git-recent