From 0ac730ca3c4a4440daf867c99cb26d76a64f0b01 Mon Sep 17 00:00:00 2001 From: Jonathan Hodgson Date: Tue, 22 Dec 2020 08:58:53 +0000 Subject: [PATCH] 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 --- inc/file-management | 2 +- kb | 8 ++++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/inc/file-management b/inc/file-management index 788b1ca..a8f968b 100644 --- a/inc/file-management +++ b/inc/file-management @@ -117,6 +117,6 @@ viewFile(){ filename="$(findFile "$id")" - bat --color=always --style=full "$filename" + "$pager" "$filename" } diff --git a/kb b/kb index 030a443..7084458 100755 --- a/kb +++ b/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 The knowledgebase data dir --sqlite The sqlite file (default to /knowledgebase.sqlite3 + --editor The editor to use (default $EDITOR or vim) + --pager 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'." ;;