remove empty lines

This commit is contained in:
Fakerr 2017-05-06 15:31:16 +01:00
parent 9b528b6413
commit bf550a3d22

View file

@ -28,7 +28,6 @@ LESSKEY=false
SED_BIN="" # Sed option to use according OS. SED_BIN="" # Sed option to use according OS.
VERSION="1.1.11" VERSION="1.1.11"
# Set keys. # Set keys.
au="`echo -e '\e[A'`" # arrow up au="`echo -e '\e[A'`" # arrow up
ad="`echo -e '\e[B'`" # arrow down ad="`echo -e '\e[B'`" # arrow down
@ -45,7 +44,6 @@ if [[ ! -d ".git" ]] && ! git rev-parse --git-dir &>/dev/null; then
exit 1 exit 1
fi fi
# Parse options # Parse options
while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
case $1 in case $1 in
@ -76,7 +74,6 @@ while [[ "$1" =~ ^- && ! "$1" == "--" ]]; do
done done
if [[ "$1" == "--" ]]; then shift; fi if [[ "$1" == "--" ]]; then shift; fi
# Colored output. # Colored output.
function colored() { function colored() {
GREEN=$(tput setaf 4) GREEN=$(tput setaf 4)
@ -93,7 +90,6 @@ function uncolored() {
REVERSE="" REVERSE=""
} }
# Enable colors if supported by terminal. # Enable colors if supported by terminal.
if [[ -t 1 ]] && [[ -n "$TERM" ]] && which tput &>/dev/null && tput colors &>/dev/null; then if [[ -t 1 ]] && [[ -n "$TERM" ]] && which tput &>/dev/null && tput colors &>/dev/null; then
ncolors=$(tput colors) ncolors=$(tput colors)
@ -106,13 +102,11 @@ else
uncolored uncolored
fi fi
# Check if lesskey is installed. # Check if lesskey is installed.
if command -v lesskey &> /dev/null; then if command -v lesskey &> /dev/null; then
LESSKEY=true LESSKEY=true
fi fi
# Set AUTHOR to current user if no param passed or display for all users if param equal to "all". # Set AUTHOR to current user if no param passed or display for all users if param equal to "all".
if [[ ! -n $AUTHOR ]]; then if [[ ! -n $AUTHOR ]]; then
AUTHOR=$(git config user.name 2>/dev/null) AUTHOR=$(git config user.name 2>/dev/null)
@ -120,7 +114,6 @@ elif [[ $AUTHOR = "all" ]]; then
AUTHOR=".*" AUTHOR=".*"
fi fi
# Fetch changes before. # Fetch changes before.
if [[ $FETCH == true ]]; then if [[ $FETCH == true ]]; then
echo "${GREEN}Fetching changes...${NORMAL}" echo "${GREEN}Fetching changes...${NORMAL}"
@ -129,7 +122,6 @@ if [[ $FETCH == true ]]; then
tput ed # clear screen tput ed # clear screen
fi fi
# Log template. # Log template.
GIT_FORMAT="%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset" GIT_FORMAT="%Cred%h%Creset -%C(yellow)%d%Creset %s %Cgreen(%cr) %C(bold blue)<%an>%Creset"
@ -138,7 +130,6 @@ GIT_LOG="git log --pretty=format:'${GIT_FORMAT}'
--author \"$AUTHOR\" --author \"$AUTHOR\"
--since \"$SINCE\" --abbrev-commit" --since \"$SINCE\" --abbrev-commit"
# Change temporary the IFS to store GIT_LOG's output into an array. # Change temporary the IFS to store GIT_LOG's output into an array.
IFS=$'\n' IFS=$'\n'
COMMITS=($(eval ${GIT_LOG} 2>/dev/null)) COMMITS=($(eval ${GIT_LOG} 2>/dev/null))
@ -150,7 +141,6 @@ CN=$(tput cols) # Screen's number of columns.
TN=$(( $NI < $((SN -1)) ? $NI : $((SN -1)))) # Number of lines that we will display. TN=$(( $NI < $((SN -1)) ? $NI : $((SN -1)))) # Number of lines that we will display.
OFFSET=0 #Incremented by one each time a commit's length is higher than teminal width. OFFSET=0 #Incremented by one each time a commit's length is higher than teminal width.
# If there is no items, exit. # If there is no items, exit.
if [[ $NI = 0 ]]; then if [[ $NI = 0 ]]; then
if [[ $AUTHOR = ".*" ]]; then if [[ $AUTHOR = ".*" ]]; then
@ -160,14 +150,12 @@ if [[ $NI = 0 ]]; then
fi fi
fi fi
# Set correct sed option according OS's type # Set correct sed option according OS's type
case "$OSTYPE" in case "$OSTYPE" in
darwin*) SED_BIN="sed -E" ;; darwin*) SED_BIN="sed -E" ;;
*) SED_BIN="sed -r" ;; *) SED_BIN="sed -r" ;;
esac esac
# Create array with uncolred commits (removing escape sequences using sed) # Create array with uncolred commits (removing escape sequences using sed)
for elt in "${COMMITS[@]}" for elt in "${COMMITS[@]}"
do do
@ -183,13 +171,11 @@ do
fi fi
done done
# Create a temporary lesskey file to change the keybindings so the user can use the TAB key to quit less. (more convenient) # 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 if [[ $LESSKEY = true ]]; then
echo "\t quit" | lesskey -o $HOME/.lsh_less_keys_tmp -- - &> /dev/null echo "\t quit" | lesskey -o $HOME/.lsh_less_keys_tmp -- - &> /dev/null
fi fi
## Get commit's diff. ## Get commit's diff.
function get_diff() { function get_diff() {
ELT="$(echo "${COMMITS_UNCOL[$CP-1]}")" ELT="$(echo "${COMMITS_UNCOL[$CP-1]}")"
@ -202,7 +188,6 @@ function get_diff() {
DIFF_LINES_NUMBER=$(( DIFF_LINES_NUMBER + off )) DIFF_LINES_NUMBER=$(( DIFF_LINES_NUMBER + off ))
} }
## This function will print the diff according the commit's tip. If the diff is too long, the result will be displayed using 'less'. ## This function will print the diff according the commit's tip. If the diff is too long, the result will be displayed using 'less'.
function print_diff() { function print_diff() {
get_diff # get commit's diff get_diff # get commit's diff
@ -242,7 +227,6 @@ function print_diff() {
fi fi
} }
# Calculate OFFSET to avoid bad redraw. # Calculate OFFSET to avoid bad redraw.
function calculate_offset { function calculate_offset {
tmp=1 tmp=1
@ -259,7 +243,6 @@ function calculate_offset {
done done
} }
{ # capture stdout to stderr { # capture stdout to stderr
tput civis # hide cursor. tput civis # hide cursor.