Merge pull request #533 from nwinkler/less-pretty-cat-check

Fixed error handling in less-pretty-cat plugin
pull/534/head
Nils Winkler 2015-07-28 15:51:43 +02:00
commit 6531938ade
1 changed files with 26 additions and 30 deletions

View File

@ -1,32 +1,28 @@
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)
# pigmentize cat and less outputs
function cat()
{
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 "$var" 2>/dev/null || "$CAT_BIN" "$var";
done
}
function less()
{
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 "$*" | "$LESS_BIN" -R
}
fi fi
# get the full paths to binaries
CAT_BIN=$(which cat)
LESS_BIN=$(which less)
# pigmentize cat and less outputs
cat()
{
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 "$var" 2>/dev/null || "$CAT_BIN" "$var";
done
}
less()
{
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 "$*" | "$LESS_BIN" -R
}