Fixed error handling in less-pretty-cat plugin
When pygmentize is not installed, the functions less/cat are not defined, the native commands will be used instead. Also removed the error message that was shown when the command was not found. Using `command -v` instead of `which` to check for the existence of the executable - this works better as it does not print an error message if the executable is not found.pull/533/head
parent
77d82a43d7
commit
d12d78ddaf
|
|
@ -1,19 +1,14 @@
|
||||||
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 [ -z $(which pygmentize) ]
|
if $(command -v pygmentize &> /dev/null) ; then
|
||||||
then
|
# get the full paths to binaries
|
||||||
echo "Pygments is required to use this plugin"
|
CAT_BIN=$(which cat)
|
||||||
echo "Install it by doing 'pip install Pygments' as the superuser"
|
LESS_BIN=$(which less)
|
||||||
fi
|
|
||||||
|
|
||||||
# get the full paths to binaries
|
# pigmentize cat and less outputs
|
||||||
CAT_BIN=$(which cat)
|
function cat()
|
||||||
LESS_BIN=$(which less)
|
{
|
||||||
|
|
||||||
# pigmentize cat and less outputs
|
|
||||||
cat()
|
|
||||||
{
|
|
||||||
about 'runs either pygmentize or cat 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 'cat mysite/manage.py dir/text-file.txt'
|
example 'cat mysite/manage.py dir/text-file.txt'
|
||||||
|
|
@ -21,12 +16,13 @@ cat()
|
||||||
do
|
do
|
||||||
pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var";
|
pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var";
|
||||||
done
|
done
|
||||||
}
|
}
|
||||||
|
|
||||||
less()
|
function less()
|
||||||
{
|
{
|
||||||
about 'it pigments the file passed in and passes it to less for pagination'
|
about 'it pigments the file passed in and passes it to less for pagination'
|
||||||
param '$1: the file to paginate with less'
|
param '$1: the file to paginate with less'
|
||||||
example 'less mysite/manage.py'
|
example 'less mysite/manage.py'
|
||||||
pygmentize "$*" | "$LESS_BIN" -R
|
pygmentize "$*" | "$LESS_BIN" -R
|
||||||
}
|
}
|
||||||
|
fi
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue