From 6821b6c0dcc94f5b9a4c50ea0ef2db117bc9f8be Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Sun, 24 May 2015 18:04:42 -0500 Subject: [PATCH] Add less and remove hard exit --- ...t.plugin.bash => less-pretty-cat.plugin.bash} | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) rename plugins/available/{pretty-cat.plugin.bash => less-pretty-cat.plugin.bash} (62%) diff --git a/plugins/available/pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash similarity index 62% rename from plugins/available/pretty-cat.plugin.bash rename to plugins/available/less-pretty-cat.plugin.bash index ab5bda62..7b1a280c 100644 --- a/plugins/available/pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -5,20 +5,28 @@ if [ -z $(which pygmentize) ] then echo "Pygments is required to use this plugin" echo "Install it by doing 'pip install Pygments' as the superuser" - exit 1 fi -# get the actual cat binary +# get the full paths to binaries CAT_BIN=$(which cat) +LESS_BIN=$(which less) -# replace the cat binary for a pygmentize if possible +# 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' + 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 "$1" | "$LESS_BIN" -R +}