mirror of
https://github.com/Fakerr/git-recall.git
synced 2026-09-10 07:26:42 -04:00
commit
103fb21cfa
|
|
@ -86,6 +86,7 @@ $ sudo make install
|
|||
```
|
||||
## Requirements
|
||||
- OS: Linux or OSX
|
||||
- Bash 4.3 or more
|
||||
- Tools: git, less, sed
|
||||
|
||||
##### Optional Requirements
|
||||
|
|
|
|||
49
git-recall
49
git-recall
|
|
@ -1,6 +1,7 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
|
||||
|
||||
# usage info
|
||||
usage() {
|
||||
cat <<EOF
|
||||
|
|
@ -23,9 +24,9 @@ GIT_LOG=""
|
|||
COMMITS=""
|
||||
SINCE="1 days ago" # show logs for last day by default
|
||||
COMMITS_UNCOL=() # commits without colors
|
||||
SED_BIN="" # Sed option to use according OS.
|
||||
SED_CMD="" # Sed command to use according OS.
|
||||
LESSKEY=false
|
||||
VERSION="1.1.12"
|
||||
VERSION="1.2.0"
|
||||
|
||||
# Set key bindings.
|
||||
au="`echo -e '\e[A'`" # arrow up
|
||||
|
|
@ -37,7 +38,7 @@ ad_1="j" # arrow down
|
|||
nl_1="e" # expand
|
||||
|
||||
# Colored output.
|
||||
colored() {
|
||||
function colored() {
|
||||
GREEN=$(tput setaf 4)
|
||||
YELLOW=$(tput setaf 3)
|
||||
NORMAL=$(tput sgr0)
|
||||
|
|
@ -45,13 +46,19 @@ colored() {
|
|||
}
|
||||
|
||||
# Uncolored output.
|
||||
uncolored() {
|
||||
function 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
|
||||
|
|
@ -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 ))
|
||||
|
|
|
|||
Loading…
Reference in a new issue