Merge pull request #1957 from gaelicWizard/plugin-less-pretty-cat
plugin/less-pretty-cat improvementspull/1885/head
commit
127cbbd4e3
|
|
@ -91,6 +91,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/percol.plugin.bash
|
plugins/available/percol.plugin.bash
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,23 @@
|
||||||
|
# shellcheck shell=bash
|
||||||
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 -v pygmentize &> /dev/null) ; then
|
_command_exists pygmentize || return
|
||||||
# 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
|
# 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
|
# especially cat'ed output in scripts gets mangled with pygemtized meta characters
|
||||||
function ccat()
|
function ccat() {
|
||||||
{
|
about 'runs pygmentize on each file passed in'
|
||||||
about 'runs either pygmentize or cat on each file passed in'
|
param '*: files to concatenate (as normally passed to cat)'
|
||||||
param '*: files to concatenate (as normally passed to cat)'
|
example 'ccat mysite/manage.py dir/text-file.txt'
|
||||||
example 'cat mysite/manage.py dir/text-file.txt'
|
|
||||||
for var;
|
|
||||||
do
|
|
||||||
pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$var" 2>/dev/null || "$CAT_BIN" "$var";
|
|
||||||
done
|
|
||||||
}
|
|
||||||
|
|
||||||
function cless()
|
pygmentize -f 256 -O style="${BASH_IT_CCAT_STYLE:-default}" -g "$@"
|
||||||
{
|
}
|
||||||
about 'it pigments the file passed in and passes it to less for pagination'
|
|
||||||
param '$1: the file to paginate with less'
|
function cless() {
|
||||||
example 'less mysite/manage.py'
|
about 'pigments the files passed in and passes to less for pagination'
|
||||||
pygmentize -f 256 -O style="$BASH_IT_CLESS_STYLE" -g $* | "$LESS_BIN" -R
|
param '*: the files to paginate with less'
|
||||||
}
|
example 'cless mysite/manage.py'
|
||||||
fi
|
|
||||||
|
pygmentize -f 256 -O style="${BASH_IT_CLESS_STYLE:-default}" -g "$@" | command less -R
|
||||||
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue