diff --git a/Makefile b/Makefile index 8c779a3..5f47754 100644 --- a/Makefile +++ b/Makefile @@ -1,7 +1,7 @@ PREFIX = /usr/local BINPREFIX = "$(PREFIX)/bin" -LIB=git-hlog +LIB=git-recall .PHONY: all install uninstall diff --git a/README.md b/README.md index 16a9487..1952399 100644 --- a/README.md +++ b/README.md @@ -1,53 +1,63 @@ -# log-so-handy -> A convenient tool to easily jump between commits diff. +# git-recall +> Simple and handy tool to easily recall what you've done + +![git recall](http://imgur.com/zuw2LqW.gif) + +## Purpose + +`git-recall` is a simple tool that allows you to easily go through your commits and +check what you or other contributors in your team did. It doesn't aim to be a replacement for the +`git log` command, but just to be a handy way to recall what you've done from your terminal. -![git hlog](http://imgur.com/bq9kRez.gif) ## Usage ```sh -$ git hlog [-a ] - [-d ] - [-f] - [-h] +$ git recall [-a ] + [-d ] + [-f] + [-h] ``` ##### Options description: -- `-a` - Restrict search for a specific user +- `-a` - Restrict search for a specific user (use -a "all" for all users) - `-d` - Display commits for the last n days - `-f` - Fetch the latest changes - `-h` - Show help screen ##### How to use: -Once the commits are displayed, you can use the `arrow keys` to switch between commits, +Once the commits are displayed, you can use either the `arrow keys` or `j/k` to switch between commits, press `TAB` to `expand/reduce` the commit's diff or `q` to quit. -**Note** that when the commit's diff is too long, the result will be displayed using the [`less`](http://www.tutorialspoint.com/unix_commands/less.htm) program. You can use either -`TAB` or `q` to return to the commits list. +##### Limitations: + +when the number of lines between the commits list and a commit's diff is higher than the current terminal session's number of lines, +the result will be displayed using the [`less`](http://www.tutorialspoint.com/unix_commands/less.htm) program which will open the diff in a separate screen. +You can still use either `TAB` or `q` to return to the commits list. ## Examples ```sh -$ git hlog +$ git recall # By default (without options), the command will display commits from yesterday and # for the current user. ``` ```sh -$ git hlog -d 5 -a "Doge" +$ git recall -d 5 -a "Doge" # The command will show all Doge's commits from 5 days ago. -$ git hlog -d 5 -a "all" +$ git recall -d 5 -a "all" # The command will show commits of all contributors from 5 days ago. ``` ```sh -$ git hlog -f +$ git recall -f # Fetch commits beforehand. ``` @@ -56,7 +66,7 @@ $ git hlog -f ##### Without using tools ``` -You can install it by simply copying the `git-hlog` script into any existing path +You can install it by simply copying the `git-recall` script into any existing path (e.g. /usr/local/bin) or create your own directory and add it to the 'PATH' variable. ``` @@ -64,14 +74,14 @@ You can install it by simply copying the `git-hlog` script into any existing pat Use `npm` to install the project. ```sh -npm install --global log-so-handy +npm install --global git-recall ``` ##### Manual install Clone the project and install it using make install. ```sh -$ git clone https://github.com/Fakerr/log-so-handy.git -$ cd log-so-handy +$ git clone https://github.com/Fakerr/git-recall.git +$ cd git-recall $ sudo make install ``` ## Requirements diff --git a/git-recall b/git-recall index 75b0a8d..1daaac9 100644 --- a/git-recall +++ b/git-recall @@ -124,19 +124,8 @@ COMMITS=($(eval ${GIT_LOG} 2>/dev/null)) unset IFS NI=${#COMMITS[@]} # Total number of items. -SN=$(( `tput lines` - 1 )) # Screen's number of lines. -CN=$(tput cols) # Screen's number of columns. +SN=$(( `tput lines` - 1 )) # Screen number of lines. TN=$(( $NI < $((SN -1)) ? $NI : $((SN -1)))) # Number of lines that we will display. -OFFSET=0 - -# Add +1 to OFFSET if a commit's length is bigger than the current terminal session's width. (This is to fix a redraw issue) -for C in "${COMMITS[@]}" -do - ELT="$(echo "$C" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes - if [[ ${#ELT} -gt $CN ]]; then - OFFSET=$(( OFFSET + 1 )) - fi -done # If there is no items, exit. if [[ $NI = 0 ]]; then @@ -201,7 +190,7 @@ function print_diff() { ;; esac done - [[ $END = false ]] && tput cuu $(( TN + DIFF_LINES_NUMBER + OFFSET )) && tput ed + [[ $END = false ]] && tput cuu $(( TN + DIFF_LINES_NUMBER )) && tput ed [[ $END = true ]] && tput cuu 1 fi } @@ -218,7 +207,7 @@ END=false # end while loop while ! $END do - for i in `seq $SI $(( $TN - $OFFSET + $SI -1 ))` + for i in `seq $SI $(( $TN + $SI -1 ))` do echo -n "$NORMAL" [[ $CP == $i ]] && echo -n "$REVERSE" @@ -239,7 +228,7 @@ do [[ $CP == 0 ]] && [[ $SI=1 ]] && [[ $TN == $(( SN - 1 )) ]] && CP=$NI && SI=$(( NI - SN + 2 )) [[ $CP == 0 ]] && [[ $SI=1 ]] && [[ $TN == $NI ]] && CP=$TN [[ $CP == $(( SI - 1 )) ]] && [[ $SI != 1 ]] && SI=$(( SI - 1 )) - tput cuu $(( TN + OFFSET )) + tput cuu $TN [[ $SI != 1 ]] && tput ed # clear screen ;; @@ -247,13 +236,13 @@ do CP=$(( CP + 1 )) [[ $CP == $(( NI + 1 )) ]] && CP=1 && SI=1 [[ $CP == $(( SN + SI - 1)) ]] && [[ $TN == $(( SN - 1 )) ]] && SI=$(( SI + 1 )) - tput cuu $(( TN + OFFSET )) + tput cuu $TN [[ $SI != 1 ]] && tput ed # clear screen [[ $SI = 1 ]] && [[ $CP = 1 ]] && tput ed # clear screen ;; "$nl") - tput cuu $(( TN + OFFSET )) + tput cuu $TN print_diff ;; diff --git a/git-hlog b/git-recall~HEAD similarity index 79% rename from git-hlog rename to git-recall~HEAD index 7d34bf1..75b0a8d 100644 --- a/git-hlog +++ b/git-recall~HEAD @@ -4,7 +4,7 @@ # usage info usage() { cat </dev/null; then + echo "abort: the program lesskey is not installed. Make sure to install it before running git-recall" 1>&2 + exit 1 +fi + # Set AUTHOR to current user if no param passed or display for all users if param equal to "all". if [[ ! -n $AUTHOR ]]; then AUTHOR=$(git config user.name 2>/dev/null) @@ -118,20 +124,39 @@ COMMITS=($(eval ${GIT_LOG} 2>/dev/null)) unset IFS NI=${#COMMITS[@]} # Total number of items. -SN=$(( `tput lines` - 1 )) # Screen number of lines. +SN=$(( `tput lines` - 1 )) # Screen's number of lines. +CN=$(tput cols) # Screen's number of columns. TN=$(( $NI < $((SN -1)) ? $NI : $((SN -1)))) # Number of lines that we will display. +OFFSET=0 + +# Add +1 to OFFSET if a commit's length is bigger than the current terminal session's width. (This is to fix a redraw issue) +for C in "${COMMITS[@]}" +do + ELT="$(echo "$C" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes + if [[ ${#ELT} -gt $CN ]]; then + OFFSET=$(( OFFSET + 1 )) + fi +done # If there is no items, exit. -[[ $NI = 0 ]] && echo "${YELLOW}The contributor \"${AUTHOR}\" did nothing during this period.${NORMAL}" && exit 0 +if [[ $NI = 0 ]]; then + if [[ $AUTHOR = ".*" ]]; then + echo "${YELLOW}All contributors did nothing during this period.${NORMAL}" && exit 0 + else + echo "${YELLOW}The contributor \"${AUTHOR}\" did nothing during this period.${NORMAL}" && exit 0 + fi +fi # Set keys. au="`echo -e '\e[A'`" # arrow up +au_1="k" # arrow up ad="`echo -e '\e[B'`" # arrow down +ad_1="j" # arrow down ec="`echo -e '\e'`" # escape nl="`echo -e '\n'`" # newline # Create a temporary lesskey file to change the keybindings so the user can use the TAB key to quit less. (more convenient) -echo "\t quit" | lesskey -o $HOME/.lsh_less_keys_tmp -- - +echo "\t quit" | lesskey -o $HOME/.lsh_less_keys_tmp -- - &> /dev/null ## Get commit's diff. function get_diff() { @@ -156,7 +181,6 @@ function print_diff() { do echo -n "$NORMAL" [[ $CP == $i ]] && echo -n "$REVERSE" - echo "${COMMITS[$i - 1]}" if [[ $CP == $i ]]; then @@ -177,7 +201,7 @@ function print_diff() { ;; esac done - [[ $END = false ]] && tput cuu $(( TN + DIFF_LINES_NUMBER )) && tput ed + [[ $END = false ]] && tput cuu $(( TN + DIFF_LINES_NUMBER + OFFSET )) && tput ed [[ $END = true ]] && tput cuu 1 fi } @@ -194,11 +218,10 @@ END=false # end while loop while ! $END do - for i in `seq $SI $(( $TN + $SI -1 ))` + for i in `seq $SI $(( $TN - $OFFSET + $SI -1 ))` do echo -n "$NORMAL" [[ $CP == $i ]] && echo -n "$REVERSE" - echo "${COMMITS[$i - 1]}" done @@ -211,26 +234,26 @@ do case "$key" in - "$au") + "$au" | "$au_1") CP=$(( CP - 1 )) [[ $CP == 0 ]] && [[ $SI=1 ]] && [[ $TN == $(( SN - 1 )) ]] && CP=$NI && SI=$(( NI - SN + 2 )) [[ $CP == 0 ]] && [[ $SI=1 ]] && [[ $TN == $NI ]] && CP=$TN [[ $CP == $(( SI - 1 )) ]] && [[ $SI != 1 ]] && SI=$(( SI - 1 )) - tput cuu $TN + tput cuu $(( TN + OFFSET )) [[ $SI != 1 ]] && tput ed # clear screen ;; - "$ad") + "$ad" | "$ad_1") CP=$(( CP + 1 )) [[ $CP == $(( NI + 1 )) ]] && CP=1 && SI=1 [[ $CP == $(( SN + SI - 1)) ]] && [[ $TN == $(( SN - 1 )) ]] && SI=$(( SI + 1 )) - tput cuu $TN + tput cuu $(( TN + OFFSET )) [[ $SI != 1 ]] && tput ed # clear screen [[ $SI = 1 ]] && [[ $CP = 1 ]] && tput ed # clear screen ;; "$nl") - tput cuu $TN + tput cuu $(( TN + OFFSET )) print_diff ;; diff --git a/package.json b/package.json index 3872f69..f84d8d1 100644 --- a/package.json +++ b/package.json @@ -1,17 +1,17 @@ { - "name": "log-so-handy", - "version": "1.0.3", - "description": "Convenient log for git", + "name": "git-recall", + "version": "1.1.1", + "description": "Simple and convenient Git tool to easily recall what you've done", "main": "", "scripts": { "test": "echo \"Error: no test specified\" && exit 1" }, "repository": { "type": "git", - "url": "https://github.com/Fakerr/log-so-handy.git" + "url": "https://github.com/Fakerr/git-recall.git" }, "bin": { - "git-hlog": "./git-hlog" + "git-recall": "./git-recall" }, "keywords": [ "git", @@ -20,5 +20,5 @@ ], "author": "Walid Berrahal", "license": "MIT", - "homepage": "https://github.com/Fakerr/log-so-handy" + "homepage": "https://github.com/Fakerr/git-recall" }