From f1e5702f0f568aded35e424e988a534bdbb31fb6 Mon Sep 17 00:00:00 2001 From: Mykyta Solomko Date: Mon, 7 Dec 2020 19:52:23 +0000 Subject: [PATCH] highlight sources using less --- .bash_profile | 36 ++++++++++++++++++++++++++---------- 1 file changed, 26 insertions(+), 10 deletions(-) diff --git a/.bash_profile b/.bash_profile index 075262b..c03cbd1 100644 --- a/.bash_profile +++ b/.bash_profile @@ -56,16 +56,6 @@ __export_pager() # Export existing pager if [ -n "${___pager}" ]; then export PAGER="${___pager}" - - export LESS='-r' - # Add colours for less - export LESS_TERMCAP_mb=$'\E[01;31m' - export LESS_TERMCAP_md=$'\E[01;31m' - export LESS_TERMCAP_me=$'\E[0m' - export LESS_TERMCAP_se=$'\E[0m' - export LESS_TERMCAP_so=$'\E[01;44;33m' - export LESS_TERMCAP_ue=$'\E[0m' - export LESS_TERMCAP_us=$'\E[01;32m' fi } @@ -126,6 +116,30 @@ __export_ls_colors() fi } +__export_lesspipe_opts() { + + # Enable lesspipe colouring if set as default pager + if [[ ${PAGER} =~ .*/less$ ]]; then + + # Requires source-highlight package to be installed + if [[ -x /usr/bin/src-hilite-lesspipe.sh ]]; then + export LESSOPEN="| /usr/bin/src-hilite-lesspipe.sh %s" + export LESS=' -R ' + else + export LESS='-r' + fi + + # Add colours for less + export LESS_TERMCAP_mb=$'\E[01;31m' + export LESS_TERMCAP_md=$'\E[01;31m' + export LESS_TERMCAP_me=$'\E[0m' + export LESS_TERMCAP_se=$'\E[0m' + export LESS_TERMCAP_so=$'\E[01;44;33m' + export LESS_TERMCAP_ue=$'\E[0m' + export LESS_TERMCAP_us=$'\E[01;32m' + fi +} + # --- SSH agent --- # agent() { @@ -295,6 +309,8 @@ __export_ls_colors # shellcheck disable=SC2119 __export_pager # shellcheck disable=SC2119 +__export_lesspipe_opts +# shellcheck disable=SC2119 __export_editor # shellcheck disable=SC2119 __export_browser -- 2.17.6