plugins/less-pretty-cat: simplify code flow

Convert from indented if-block to return then unindented code. This should have basically one line change at the top, one line removed at the bottom, and then all whitespace.
This commit is contained in:
John D Pell
2021-09-22 14:16:23 -07:00
parent 55be49e887
commit 5857648377
2 changed files with 25 additions and 25 deletions

View File

@@ -90,6 +90,7 @@ plugins/available/history-substring-search.plugin.bash
plugins/available/history.plugin.bash plugins/available/history.plugin.bash
plugins/available/hub.plugin.bash plugins/available/hub.plugin.bash
plugins/available/jump.plugin.bash plugins/available/jump.plugin.bash
plugins/available/less-pretty-cat.plugin.bash
plugins/available/node.plugin.bash plugins/available/node.plugin.bash
plugins/available/nodenv.plugin.bash plugins/available/nodenv.plugin.bash
plugins/available/plenv.plugin.bash plugins/available/plenv.plugin.bash

View File

@@ -2,30 +2,29 @@
cite about-plugin cite about-plugin
about-plugin 'pygmentize instead of cat to terminal if possible' about-plugin 'pygmentize instead of cat to terminal if possible'
if _command_exists pygmentize _command_exists pygmentize || return
then
# 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
function ccat()
{
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'
local file
: "${BASH_IT_CCAT_STYLE:=default}"
for file in "$@" # pigmentize cat and less outputs - call them ccat and cless to avoid that
do # especially cat'ed output in scripts gets mangled with pygemtized meta characters
pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$file" 2>/dev/null || command cat "$file"; function ccat() {
done about 'runs either pygmentize or cat on each file passed in'
} param '*: files to concatenate (as normally passed to cat)'
example 'ccat mysite/manage.py dir/text-file.txt'
function cless() local file
{ : "${BASH_IT_CCAT_STYLE:=default}"
about 'pigments the file passed in and passes it to less for pagination'
param '$1: the file to paginate with less' for file in "$@"; do
example 'less mysite/manage.py' pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$file" 2> /dev/null || command cat "$file"
: "${BASH_IT_CLESS_STYLE:=default}" done
pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g "$@" | command less -R }
}
fi function cless() {
about 'pigments the file passed in and passes it to less for pagination'
param '1: the file to paginate with less'
example 'cless mysite/manage.py'
: "${BASH_IT_CLESS_STYLE:=default}"
pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g "$@" | command less -R
}