Merge branch 'master' into dev

This commit is contained in:
Fakerr 2017-02-04 18:42:18 +01:00
commit 57db517df9
3 changed files with 29 additions and 12 deletions

View file

@ -85,7 +85,11 @@ $ cd git-recall
$ sudo make install
```
## Requirements
- Linux or OSX
- OS: Linux or OSX
- Tools: git, less, sed
##### Optional Requirements
- For a better UX, it's recommended to have installed the `lesskey` program.
## Contribution
Pull requests are welcome, along with any feedback or ideas.

View file

@ -22,10 +22,11 @@ FETCH=false
GIT_FORMAT=""
GIT_LOG=""
COMMITS=""
VERSION="1.1.1"
LESSKEY=false
VERSION="1.1.3"
# Are we in a git repo?
if [[ ! -d ".git" ]]; then
if [[ ! -d ".git" ]] && ! git rev-parse --git-dir &>/dev/null; then
echo "abort: not a git repository." 1>&2
exit 1
fi
@ -89,10 +90,9 @@ else
uncolored
fi
# Check if lesskey is correctly installed.
if ! which lesskey &>/dev/null; then
echo "abort: the program lesskey is not installed. Make sure to install it before running git-recall" 1>&2
exit 1
# 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".
@ -156,11 +156,18 @@ 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 -- - &> /dev/null
if [[ $LESSKEY = true ]]; then
echo "\t quit" | lesskey -o $HOME/.lsh_less_keys_tmp -- - &> /dev/null
fi
## Get commit's diff.
function get_diff() {
ELT="$(echo "${COMMITS[$CP-1]}" | sed -r "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes
case "$OSTYPE" in
darwin*) SED_BIN="sed -E" ;;
*) SED_BIN="sed -r" ;;
esac
ELT="$(echo "${COMMITS[$CP-1]}" | $SED_BIN "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes
DIFF_TIP=${ELT:0:7}
DIFF_CMD="git show $DIFF_TIP --color=always"
DIFF=$(eval ${DIFF_CMD} 2>/dev/null)
@ -173,7 +180,11 @@ function print_diff() {
get_diff
if [[ $(( TN + DIFF_LINES_NUMBER )) -ge $(( `tput lines` - 1 )) ]]; then
echo -e "$REVERSE ${COMMITS[$CP - 1]}\n\n $DIFF" | less -r -k $HOME/.lsh_less_keys_tmp
if [[ $LESSKEY = true ]]; then
echo "$REVERSE ${COMMITS[$CP - 1]}\n\n $DIFF" | less -r -k $HOME/.lsh_less_keys_tmp
else
echo "$REVERSE ${COMMITS[$CP - 1]}\n\n $DIFF" | less -r
fi
else
stop=false
tput ed
@ -299,7 +310,9 @@ do
done
rm $HOME/.lsh_less_keys_tmp # remove temporary less keybindings
# remove temporary less keybindings
[[ $LESSKEY = true ]] && rm $HOME/.lsh_less_keys_tmp
tput cnorm # unhide cursor
echo "$NORMAL" # normal colors

View file

@ -1,6 +1,6 @@
{
"name": "git-recall",
"version": "1.1.1",
"version": "1.1.3",
"description": "Simple and convenient Git tool to easily recall what you've done",
"main": "",
"scripts": {