Adds pager option and uses $PAGER environment variable

Due to bat also reading the $PAGER environment variable, I first look to
see if bat is available. If it is, I use that. If it isn't, I use the
$PAGER environment variable. If that's not available, I use cat.

I also added the --editor flag to the help output which had clearly been
missed

Close #12
master
Jonathan Hodgson 3 years ago
parent 90cef0d7c0
commit 0ac730ca3c
  1. 2
      inc/file-management
  2. 8
      kb

@ -117,6 +117,6 @@ viewFile(){
filename="$(findFile "$id")"
bat --color=always --style=full "$filename"
"$pager" "$filename"
}

8
kb

@ -89,6 +89,11 @@ args=()
dataDir="${XDG_DATA_HOME:=$HOME/.local/share}/kb/"
sqliteFile=""
editor="${EDITOR:=vim}"
if type -p bat > /dev/null 2>&1; then
pager="bat"
else
pager="${PAGER:=cat}"
fi
# Check for Dependencies
# -----------------------------------
@ -373,6 +378,8 @@ usage() {
-h, --help Display this help and exit
--data <directory> The knowledgebase data dir
--sqlite <file> The sqlite file (default to <data>/knowledgebase.sqlite3
--editor <editor> The editor to use (default $EDITOR or vim)
--pager <editor> The pager to use (default bat or $PAGER or cat)
--nogit Don't run git commands
--version Output version information and exit
@ -446,6 +453,7 @@ while [[ $1 = -?* ]]; do
--data) dataDir="$2"; shift ;;
--sqlite) sqliteFile="$2"; shift ;;
--editor) editor="$2"; shift ;;
--pager) pager="$2"; shift ;;
--nogit) dogit=0 ;;
--) shift; break ;;
*) die "invalid option: '$1'." ;;

Loading…
Cancel
Save