From c0ac3d8393bfe6328f3e10b09734dc2f2a94465c Mon Sep 17 00:00:00 2001 From: markusdd Date: Sat, 5 Oct 2019 15:50:59 +0200 Subject: [PATCH 1/2] Update less-pretty-cat plugin to support pygment style selection Pygments offers great styles and in dark terminals the default is unsatisfactory. Use two new env variables BASH_IT_CLESS_STYLE and BASH_IT_CCAT_STYLE to select pygment themes. Availables styles can be listes using pygmentize -L styles --- plugins/available/less-pretty-cat.plugin.bash | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index 841122ca..ce846868 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -13,9 +13,12 @@ if $(command -v pygmentize &> /dev/null) ; then about 'runs either pygmentize or cat on each file passed in' param '*: files to concatenate (as normally passed to cat)' example 'cat mysite/manage.py dir/text-file.txt' + if [ -z "$BASH_IT_CCAT_STYLE" ]; then + BASH_IT_CCAT_STYLE=default; + fi for var; do - pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var"; + pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$var" 2>/dev/null || "$CAT_BIN" "$var"; done } @@ -24,6 +27,9 @@ if $(command -v pygmentize &> /dev/null) ; then about 'it pigments the file passed in and passes it to less for pagination' param '$1: the file to paginate with less' example 'less mysite/manage.py' - pygmentize -g $* | "$LESS_BIN" -R + if [ -z "$BASH_IT_CLESS_STYLE" ]; then + BASH_IT_CLESS_STYLE=default; + fi + pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g $* | "$LESS_BIN" -R } fi From c9054e25a9c847eee4a8af27e47af2deec75bf28 Mon Sep 17 00:00:00 2001 From: markusdd Date: Mon, 7 Oct 2019 14:19:38 +0200 Subject: [PATCH 2/2] implement feedback --- plugins/available/less-pretty-cat.plugin.bash | 8 ++------ 1 file changed, 2 insertions(+), 6 deletions(-) diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index ce846868..b6b9d1f0 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -5,6 +5,8 @@ if $(command -v pygmentize &> /dev/null) ; then # get the full paths to binaries CAT_BIN=$(which cat) LESS_BIN=$(which less) + BASH_IT_CCAT_STYLE="${BASH_IT_CCAT_STYLE:=default}" + BASH_IT_CLESS_STYLE="${BASH_IT_CLESS_STYLE:=default}" # pigmentize cat and less outputs - call them ccat and cless to avoid that # especially cat'ed output in scripts gets mangled with pygemtized meta characters @@ -13,9 +15,6 @@ if $(command -v pygmentize &> /dev/null) ; then about 'runs either pygmentize or cat on each file passed in' param '*: files to concatenate (as normally passed to cat)' example 'cat mysite/manage.py dir/text-file.txt' - if [ -z "$BASH_IT_CCAT_STYLE" ]; then - BASH_IT_CCAT_STYLE=default; - fi for var; do pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$var" 2>/dev/null || "$CAT_BIN" "$var"; @@ -27,9 +26,6 @@ if $(command -v pygmentize &> /dev/null) ; then about 'it pigments the file passed in and passes it to less for pagination' param '$1: the file to paginate with less' example 'less mysite/manage.py' - if [ -z "$BASH_IT_CLESS_STYLE" ]; then - BASH_IT_CLESS_STYLE=default; - fi pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g $* | "$LESS_BIN" -R } fi