diff --git a/README.md b/README.md index 1f9b818..58a750b 100644 --- a/README.md +++ b/README.md @@ -86,6 +86,7 @@ $ sudo make install ``` ## Requirements - OS: Linux or OSX +- Bash 4.3 or more - Tools: git, less, sed ##### Optional Requirements diff --git a/git-recall b/git-recall index 2f21e45..8b1a358 100644 --- a/git-recall +++ b/git-recall @@ -1,6 +1,7 @@ #!/usr/bin/env bash + # usage info usage() { cat </dev/null; then echo "abort: not a git repository." 1>&2 @@ -100,11 +107,6 @@ 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) @@ -117,7 +119,7 @@ if [[ $FETCH == true ]]; then echo "${GREEN}Fetching changes...${NORMAL}" git fetch --all &> /dev/null tput cuu1 - tput ed # clear screen + clear_screen fi # Log template. @@ -148,16 +150,21 @@ if [[ $NI = 0 ]]; then fi fi -# Set correct sed option according OS's type +# Check if lesskey is installed. +if command -v lesskey &> /dev/null; then + LESSKEY=true +fi + +# Set correct sed command according OS's type case "$OSTYPE" in - darwin*) SED_BIN="sed -E" ;; - *) SED_BIN="sed -r" ;; + 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" ;; esac # Create array with uncolred commits (removing escape sequences using sed) for elt in "${COMMITS[@]}" do - ELT="$(echo "$elt" | $SED_BIN "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" # remove colors escape codes + ELT="$(echo "$elt" | $SED_CMD)" # remove colors escape codes COMMITS_UNCOL+=("$ELT") done @@ -180,7 +187,7 @@ function get_diff() { DIFF_TIP=${ELT:0:7} DIFF_CMD="git show $DIFF_TIP --color=always" DIFF=$(eval ${DIFF_CMD} 2>/dev/null) - tmp_diff="$(echo "$DIFF" | $SED_BIN "s/\x1B\[([0-9]{1,2}(;[0-9]{1,2})?)?[m|K]//g")" + tmp_diff="$(echo "$DIFF" | $SED_CMD)" 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 )) @@ -195,10 +202,10 @@ function print_diff() { else echo "$DIFF" | less -r fi - tput ed # Clear screen + clear_screen else stop=false - tput ed + clear_screen for i in `seq 1 $TN` do echo -n "$NORMAL" @@ -220,7 +227,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 + OFFSET )) && clear_screen [[ $END = true ]] && tput cuu 1 fi } @@ -291,7 +298,7 @@ do [[ $TN != $(( SN - 1 )) ]] && tput cuu $(( TN + OFFSET_2 )) [[ $TN == $(( SN - 1 )) ]] && tput cuu $(( TN + EXT )) - [[ $SI != 1 ]] && tput ed # clear screen + [[ $SI != 1 ]] && clear_screen ;; "$ad" | "$ad_1") CP=$(( CP + 1 )) @@ -300,8 +307,8 @@ do [[ $TN != $(( SN - 1 )) ]] && tput cuu $(( TN + OFFSET_2 )) [[ $TN == $(( SN - 1 )) ]] && tput cuu $(( TN + EXT )) - [[ $SI != 1 ]] && tput ed # clear screen - [[ $SI = 1 ]] && [[ $CP = 1 ]] && tput ed # clear screen + [[ $SI != 1 ]] && clear_screen + [[ $SI = 1 ]] && [[ $CP = 1 ]] && clear_screen ;; "$nl" | "$nl_1") [[ $TN == $NI ]] && tput cuu $(( TN + OFFSET_2 ))