Add less and remove hard exit

pull/476/head
Miguel Morales 2015-05-24 18:04:42 -05:00
parent 6b1789e385
commit 6821b6c0dc
1 changed files with 12 additions and 4 deletions

View File

@ -5,20 +5,28 @@ if [ -z $(which pygmentize) ]
then then
echo "Pygments is required to use this plugin" echo "Pygments is required to use this plugin"
echo "Install it by doing 'pip install Pygments' as the superuser" echo "Install it by doing 'pip install Pygments' as the superuser"
exit 1
fi fi
# get the actual cat binary # get the full paths to binaries
CAT_BIN=$(which cat) CAT_BIN=$(which cat)
LESS_BIN=$(which less)
# replace the cat binary for a pygmentize if possible # pigmentize cat and less outputs
cat() 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'
for var; for var;
do do
pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var"; pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var";
done 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 "$1" | "$LESS_BIN" -R
}