-
Notifications
You must be signed in to change notification settings - Fork 0
/
pygmentize.plugins.bash
executable file
·33 lines (29 loc) · 1.1 KB
/
pygmentize.plugins.bash
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# shellcheck shell=bash
cite about-plugin
about-plugin 'pygmentize instead of cat to terminal if possible'
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
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'
for var;
do
pygmentize -f 256 -O style="$BASH_IT_CCAT_STYLE" -g "$var" 2>/dev/null || "$CAT_BIN" "$var";
done
}
cless()
{
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 -f 256 -O style="$BASH_IT_CLESS_STYLE" -g $* | "$LESS_BIN" -R
}
fi