From 0bdcf196aaaffbc2af4884570a05144831e012f3 Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Tue, 12 May 2015 11:30:49 -0500 Subject: [PATCH 1/6] Add pretty cat plugin for cat with syntax highlighting --- plugins/available/pretty-cat.plugin.bash | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 plugins/available/pretty-cat.plugin.bash diff --git a/plugins/available/pretty-cat.plugin.bash b/plugins/available/pretty-cat.plugin.bash new file mode 100644 index 00000000..6e5f57c9 --- /dev/null +++ b/plugins/available/pretty-cat.plugin.bash @@ -0,0 +1,21 @@ +cite about-plugin +about-plugin 'pygmentize instead of cat to terminal if possible' + +if [ -z $(which pygmentize) ] +then + echo "Pygments is required to use this pluging" + echo "Install it by doing 'pip install Pygments' as the superuser" + exit +fi + +# get the actual cat binary +CAT_BIN=$(which cat) + +# replace the cat binary for a pygmentize if possible +cat() +{ + for var; + do + pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var"; + done +} From af2f0304cbf8fe22ad3e29b1445879981e27fd19 Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Tue, 12 May 2015 15:57:39 -0500 Subject: [PATCH 2/6] Add proper exit code --- plugins/available/pretty-cat.plugin.bash | 30 ++++++++++++------------ 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/plugins/available/pretty-cat.plugin.bash b/plugins/available/pretty-cat.plugin.bash index 6e5f57c9..93d66c80 100644 --- a/plugins/available/pretty-cat.plugin.bash +++ b/plugins/available/pretty-cat.plugin.bash @@ -1,21 +1,21 @@ cite about-plugin about-plugin 'pygmentize instead of cat to terminal if possible' -if [ -z $(which pygmentize) ] -then - echo "Pygments is required to use this pluging" - echo "Install it by doing 'pip install Pygments' as the superuser" - exit -fi +if [ -z $(which pygmentize) ] +then + echo "Pygments is required to use this pluging" + echo "Install it by doing 'pip install Pygments' as the superuser" + exit 1 +fi -# get the actual cat binary -CAT_BIN=$(which cat) +# get the actual cat binary +CAT_BIN=$(which cat) -# replace the cat binary for a pygmentize if possible -cat() -{ - for var; - do - pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var"; - done +# replace the cat binary for a pygmentize if possible +cat() +{ + for var; + do + pygmentize "$var" 2>/dev/null || "$CAT_BIN" "$var"; + done } From 3f98e953cd5abfd6ef01d7fc8d4baf1d3f783a6d Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Tue, 12 May 2015 16:26:18 -0500 Subject: [PATCH 3/6] Fix typo --- plugins/available/pretty-cat.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/pretty-cat.plugin.bash b/plugins/available/pretty-cat.plugin.bash index 93d66c80..c9def54b 100644 --- a/plugins/available/pretty-cat.plugin.bash +++ b/plugins/available/pretty-cat.plugin.bash @@ -3,7 +3,7 @@ about-plugin 'pygmentize instead of cat to terminal if possible' if [ -z $(which pygmentize) ] then - echo "Pygments is required to use this pluging" + echo "Pygments is required to use this plugin" echo "Install it by doing 'pip install Pygments' as the superuser" exit 1 fi From 6b1789e385aa1d06ef8db5c583fa9d22076cefc2 Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Tue, 12 May 2015 16:36:07 -0500 Subject: [PATCH 4/6] Add cat function documentation --- plugins/available/pretty-cat.plugin.bash | 3 +++ 1 file changed, 3 insertions(+) diff --git a/plugins/available/pretty-cat.plugin.bash b/plugins/available/pretty-cat.plugin.bash index c9def54b..ab5bda62 100644 --- a/plugins/available/pretty-cat.plugin.bash +++ b/plugins/available/pretty-cat.plugin.bash @@ -14,6 +14,9 @@ CAT_BIN=$(which cat) # replace the cat binary for a pygmentize if possible 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"; From 6821b6c0dcc94f5b9a4c50ea0ef2db117bc9f8be Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Sun, 24 May 2015 18:04:42 -0500 Subject: [PATCH 5/6] 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 +} From e143d4f6969eb1774a0d83cf378c171967d0487f Mon Sep 17 00:00:00 2001 From: Miguel Morales Date: Tue, 9 Jun 2015 07:46:32 -0500 Subject: [PATCH 6/6] Allow for passing arguments to pygmentize --- plugins/available/less-pretty-cat.plugin.bash | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/plugins/available/less-pretty-cat.plugin.bash b/plugins/available/less-pretty-cat.plugin.bash index 7b1a280c..a68975e5 100644 --- a/plugins/available/less-pretty-cat.plugin.bash +++ b/plugins/available/less-pretty-cat.plugin.bash @@ -28,5 +28,5 @@ 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 + pygmentize "$*" | "$LESS_BIN" -R }