mirror of
https://github.com/Fakerr/git-recall.git
synced 2026-09-11 07:56:42 -04:00
Compare commits
No commits in common. "master" and "v1.1.12" have entirely different histories.
4
Makefile
4
Makefile
|
|
@ -1,5 +1,5 @@
|
|||
PREFIX ?= /usr/local
|
||||
BINPREFIX ?= "$(PREFIX)/bin"
|
||||
PREFIX = /usr/local
|
||||
BINPREFIX = "$(PREFIX)/bin"
|
||||
|
||||
LIB=git-recall
|
||||
|
||||
|
|
|
|||
19
README.md
19
README.md
|
|
@ -7,31 +7,25 @@
|
|||
## 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
|
||||
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 convenient way to recall what you've done from your terminal.
|
||||
|
||||
|
||||
## Usage
|
||||
|
||||
```sh
|
||||
$ git recall [-a <author name>]
|
||||
[-d <days-ago>]
|
||||
[-b <branch name>]
|
||||
[-p <paths>]
|
||||
$ git recall [-a <author name>]
|
||||
[-d <days-ago>]
|
||||
[-f]
|
||||
[-h]
|
||||
[-v]
|
||||
```
|
||||
|
||||
##### Options description:
|
||||
|
||||
- `-a` - Restrict search for a specific user (use -a "all" for all users)
|
||||
- `-d` - Display commits for the last n days
|
||||
- `-b` - Specify branch to display commits from
|
||||
- `-p` - Specify path/s or file/s to display commits from
|
||||
- `-f` - Fetch the latest changes
|
||||
- `-h` - Show help screen
|
||||
- `-v` - Show version
|
||||
|
||||
##### How to use:
|
||||
|
||||
|
|
@ -71,10 +65,10 @@ $ git recall -f
|
|||
|
||||
##### Without using tools
|
||||
|
||||
```
|
||||
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.
|
||||
|
||||
Make sure to run `chmod +x /usr/local/bin/git-recall` or the directory in which you copied it to.
|
||||
(e.g. /usr/local/bin) or create your own directory and add it to the 'PATH' variable.
|
||||
```
|
||||
|
||||
##### Using NPM
|
||||
Use `npm` to install the project.
|
||||
|
|
@ -92,7 +86,6 @@ $ sudo make install
|
|||
```
|
||||
## Requirements
|
||||
- OS: Linux or OSX
|
||||
- Bash 4.3 or more
|
||||
- Tools: git, less, sed
|
||||
|
||||
##### Optional Requirements
|
||||
|
|
|
|||
96
git-recall
96
git-recall
|
|
@ -7,9 +7,7 @@ usage() {
|
|||
Usage: git recall [options]
|
||||
Options:
|
||||
-d, --date Show logs for last n days.
|
||||
-a, --author Author name (use -a "all" for all users).
|
||||
-b, --branch Specify branch to display commits from.
|
||||
-p --path Specify path or filename to display commits from.
|
||||
-a, --author Author name.
|
||||
-f, --fetch fetch commits.
|
||||
-h, --help This message.
|
||||
-v, --version Show version.
|
||||
|
|
@ -18,7 +16,6 @@ EOF
|
|||
}
|
||||
|
||||
# Global variables
|
||||
orig_stty=$(stty -g) # Store original terminal settings
|
||||
AUTHOR=""
|
||||
FETCH=false
|
||||
GIT_FORMAT=""
|
||||
|
|
@ -26,11 +23,9 @@ GIT_LOG=""
|
|||
COMMITS=""
|
||||
SINCE="1 days ago" # show logs for last day by default
|
||||
COMMITS_UNCOL=() # commits without colors
|
||||
SED_CMD="" # Sed command to use according OS.
|
||||
SED_BIN="" # Sed option to use according OS.
|
||||
LESSKEY=false
|
||||
VERSION="1.2.4"
|
||||
BRANCH=""
|
||||
SEARCH_PATH=""
|
||||
VERSION="1.1.12"
|
||||
|
||||
# Set key bindings.
|
||||
au="`echo -e '\e[A'`" # arrow up
|
||||
|
|
@ -42,7 +37,7 @@ ad_1="j" # arrow down
|
|||
nl_1="e" # expand
|
||||
|
||||
# Colored output.
|
||||
function colored() {
|
||||
colored() {
|
||||
GREEN=$(tput setaf 4)
|
||||
YELLOW=$(tput setaf 3)
|
||||
NORMAL=$(tput sgr0)
|
||||
|
|
@ -50,19 +45,13 @@ function colored() {
|
|||
}
|
||||
|
||||
# Uncolored output.
|
||||
function uncolored() {
|
||||
uncolored() {
|
||||
GREEN=""
|
||||
YELLOW=""
|
||||
NORMAL=""
|
||||
REVERSE=""
|
||||
}
|
||||
|
||||
# Clear screen from cursor to end of screen
|
||||
function clear_screen() {
|
||||
echo -e "\E[J"
|
||||
tput cuu1
|
||||
}
|
||||
|
||||
# Are we in a git repo?
|
||||
if [[ ! -d ".git" ]] && ! git rev-parse --git-dir &>/dev/null; then
|
||||
echo "abort: not a git repository." 1>&2
|
||||
|
|
@ -91,14 +80,6 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
|
|||
usage
|
||||
exit
|
||||
;;
|
||||
-b | --branch )
|
||||
BRANCH="$2"
|
||||
shift
|
||||
;;
|
||||
-p | --path )
|
||||
SEARCH_PATH="$2"
|
||||
shift
|
||||
;;
|
||||
* )
|
||||
echo "abort: unknown argument" 1>&2
|
||||
exit 1
|
||||
|
|
@ -119,6 +100,11 @@ else
|
|||
uncolored
|
||||
fi
|
||||
|
||||
# Check if lesskey is installed.
|
||||
if command -v lesskey &> /dev/null; then
|
||||
LESSKEY=true
|
||||
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)
|
||||
|
|
@ -131,7 +117,7 @@ if [[ $FETCH == true ]]; then
|
|||
echo "${GREEN}Fetching changes...${NORMAL}"
|
||||
git fetch --all &> /dev/null
|
||||
tput cuu1
|
||||
clear_screen
|
||||
tput ed # clear screen
|
||||
fi
|
||||
|
||||
# Log template.
|
||||
|
|
@ -140,7 +126,7 @@ GIT_FORMAT="%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%a
|
|||
# Log command.
|
||||
GIT_LOG="git log --pretty=format:'${GIT_FORMAT}'
|
||||
--author \"$AUTHOR\"
|
||||
--since \"$SINCE\" --abbrev-commit --no-merges $BRANCH $SEARCH_PATH"
|
||||
--since \"$SINCE\" --abbrev-commit"
|
||||
|
||||
# Change temporary the IFS to store GIT_LOG's output into an array.
|
||||
IFS=$'\n'
|
||||
|
|
@ -162,21 +148,16 @@ if [[ $NI = 0 ]]; then
|
|||
fi
|
||||
fi
|
||||
|
||||
# Check if lesskey is installed.
|
||||
if command -v lesskey &> /dev/null; then
|
||||
LESSKEY=true
|
||||
fi
|
||||
|
||||
# Set correct sed command according OS's type
|
||||
# Set correct sed option according OS's type
|
||||
case "$OSTYPE" in
|
||||
darwin*) SED_CMD="sed -E s/"$'\E'"\[([0-9]{1,2}(;[0-9]{1,2})*)?m//g" ;;
|
||||
*) SED_CMD="sed -r s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g" ;;
|
||||
darwin*) SED_BIN="sed -E" ;;
|
||||
*) SED_BIN="sed -r" ;;
|
||||
esac
|
||||
|
||||
# Create array with uncolred commits (removing escape sequences using sed)
|
||||
for elt in "${COMMITS[@]}"
|
||||
do
|
||||
ELT="$(echo "$elt" | $SED_CMD)" # remove colors escape codes
|
||||
ELT="$(echo "$elt" | $SED_BIN "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes
|
||||
COMMITS_UNCOL+=("$ELT")
|
||||
done
|
||||
|
||||
|
|
@ -190,16 +171,16 @@ done
|
|||
|
||||
# Create a temporary lesskey file to change the keybindings so the user can use the TAB key to quit less. (more convenient)
|
||||
if [[ $LESSKEY = true ]]; then
|
||||
echo "\t quit" | lesskey -o /tmp/lsh_less_keys_tmp -- - &> /dev/null
|
||||
echo "\t quit" | lesskey -o $HOME/.lsh_less_keys_tmp -- - &> /dev/null
|
||||
fi
|
||||
|
||||
# Get commit's diff.
|
||||
function get_diff() {
|
||||
ELT="$(echo "${COMMITS_UNCOL[$CP-1]}")"
|
||||
DIFF_TIP=${ELT:0:7}
|
||||
DIFF_CMD="git show $DIFF_TIP --color=always $SEARCH_PATH"
|
||||
DIFF_CMD="git show $DIFF_TIP --color=always"
|
||||
DIFF=$(eval ${DIFF_CMD} 2>/dev/null)
|
||||
tmp_diff="$(echo "$DIFF" | $SED_CMD)"
|
||||
tmp_diff="$(echo "$DIFF" | $SED_BIN "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")"
|
||||
off=$(echo "$tmp_diff" | grep -c ".\{$CN\}") # Number of lines in the diff that are longer than terminal width.
|
||||
DIFF_LINES_NUMBER="$(echo "$DIFF" | wc -l)"
|
||||
DIFF_LINES_NUMBER=$(( DIFF_LINES_NUMBER + off ))
|
||||
|
|
@ -209,17 +190,15 @@ function get_diff() {
|
|||
function print_diff() {
|
||||
get_diff
|
||||
if [[ $(( TN + DIFF_LINES_NUMBER + OFFSET )) -ge $(( `tput lines` - 1 )) ]]; then
|
||||
trap - INT
|
||||
if [[ $LESSKEY = true ]]; then
|
||||
echo "$DIFF" | less -r -k /tmp/lsh_less_keys_tmp
|
||||
echo "$DIFF" | less -r -k $HOME/.lsh_less_keys_tmp
|
||||
else
|
||||
echo "$DIFF" | less -r
|
||||
fi
|
||||
trap cleanup_and_exit INT
|
||||
clear_screen
|
||||
tput ed # Clear screen
|
||||
else
|
||||
stop=false
|
||||
clear_screen
|
||||
tput ed
|
||||
for i in `seq 1 $TN`
|
||||
do
|
||||
echo -n "$NORMAL"
|
||||
|
|
@ -241,7 +220,8 @@ function print_diff() {
|
|||
;;
|
||||
esac
|
||||
done
|
||||
[[ $END = false ]] && tput cuu $(( TN + DIFF_LINES_NUMBER + OFFSET )) && clear_screen
|
||||
[[ $END = false ]] && tput cuu $(( TN + DIFF_LINES_NUMBER + OFFSET )) && tput ed
|
||||
[[ $END = true ]] && tput cuu 1
|
||||
fi
|
||||
}
|
||||
|
||||
|
|
@ -261,21 +241,6 @@ function calculate_offset {
|
|||
done
|
||||
}
|
||||
|
||||
# Reset changes made by this script before exiting
|
||||
function cleanup_and_exit() {
|
||||
# remove temporary less keybindings
|
||||
[[ $LESSKEY = true ]] && rm /tmp/lsh_less_keys_tmp
|
||||
|
||||
tput cuu 1 # move cursor up one line. (remove extra line)
|
||||
tput cnorm # unhide cursor
|
||||
echo "$NORMAL" # normal colors
|
||||
stty "$orig_stty" > /dev/null 2>&1
|
||||
exit
|
||||
}
|
||||
|
||||
# Catch a control-C interrupt and perform cleanup operations before exiting
|
||||
trap cleanup_and_exit INT
|
||||
|
||||
{ # capture stdout to stderr
|
||||
|
||||
tput civis # hide cursor.
|
||||
|
|
@ -326,7 +291,7 @@ do
|
|||
|
||||
[[ $TN != $(( SN - 1 )) ]] && tput cuu $(( TN + OFFSET_2 ))
|
||||
[[ $TN == $(( SN - 1 )) ]] && tput cuu $(( TN + EXT ))
|
||||
[[ $SI != 1 ]] && clear_screen
|
||||
[[ $SI != 1 ]] && tput ed # clear screen
|
||||
;;
|
||||
"$ad" | "$ad_1")
|
||||
CP=$(( CP + 1 ))
|
||||
|
|
@ -335,8 +300,8 @@ do
|
|||
|
||||
[[ $TN != $(( SN - 1 )) ]] && tput cuu $(( TN + OFFSET_2 ))
|
||||
[[ $TN == $(( SN - 1 )) ]] && tput cuu $(( TN + EXT ))
|
||||
[[ $SI != 1 ]] && clear_screen
|
||||
[[ $SI = 1 ]] && [[ $CP = 1 ]] && clear_screen
|
||||
[[ $SI != 1 ]] && tput ed # clear screen
|
||||
[[ $SI = 1 ]] && [[ $CP = 1 ]] && tput ed # clear screen
|
||||
;;
|
||||
"$nl" | "$nl_1")
|
||||
[[ $TN == $NI ]] && tput cuu $(( TN + OFFSET_2 ))
|
||||
|
|
@ -346,13 +311,18 @@ do
|
|||
"q")
|
||||
si=false
|
||||
END=true
|
||||
tput cuu 1 #move cursor up one line. (remove extra line)
|
||||
;;
|
||||
* )
|
||||
tput cuu $(( TN + OFFSET_2 ))
|
||||
esac
|
||||
done
|
||||
|
||||
cleanup_and_exit
|
||||
# remove temporary less keybindings
|
||||
[[ $LESSKEY = true ]] && rm $HOME/.lsh_less_keys_tmp
|
||||
|
||||
tput cnorm # unhide cursor
|
||||
echo "$NORMAL" # normal colors
|
||||
|
||||
} >&2 # END capture
|
||||
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
{
|
||||
"name": "git-recall",
|
||||
"version": "1.2.4",
|
||||
"version": "1.1.12",
|
||||
"description": "Simple and convenient Git tool to easily recall what you've done",
|
||||
"main": "",
|
||||
"scripts": {
|
||||
|
|
|
|||
Loading…
Reference in a new issue