Skip to content

Instantly share code, notes, and snippets.

@ohpauleez
Last active September 9, 2016 15:24
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ohpauleez/8fce064d8813e738998d to your computer and use it in GitHub Desktop.
Save ohpauleez/8fce064d8813e738998d to your computer and use it in GitHub Desktop.
Capture blocks of Clojure code in the paste buffer for making Keynote presentations
#!/usr/bin/env bash
## Given a Clojure source file, 'example.clj'
## Where the contents are captured by START and END comments like:
##
## ;;START SomeTagName
## (println (inc 2))
## ;;END
##
## Run this script: colorblock.sh example.clj SomeTagName
# Awk version
#awk -F "START $2" '{print $2}' RS=';;END' $1 | awk 'NF > 0' | pygmentize -f rtf -O "style=friendly,fontface=Inconsolata,fontsize=62" -l clojure | pbcopy
# Sed version
sed -n "/START $2/,/END/p" $1 | sed '1d;$d' | pygmentize -f rtf -O "style=friendly,fontface=Inconsolata,fontsize=62" -l clojure | pbcopy
@ohpauleez
Copy link
Author

ohpauleez commented Jul 14, 2016

Here's a version that also works on Linux and also allows one to toggle the output format

#!/usr/bin/env bash

## Given a Clojure source file, 'example.clj'
##  Where the contents are captured by START and END comments like:
##
## ;;START SomeTagName
## (println (inc 2))
## ;;END
##
## Run this script: colorblock.sh example.clj SomeTagName
##
## Optionally change the output formatter:
## colorblock.sh example.clj SomeTagName text
## colorblock.sh example.clj SomeTagName terminal

USAGE="USAGE:\ncolorblock example.clj SomeTagName\ncolorblock example.clj SomeTagName [OUTPUT FORMAT]\n"

if [ $# -eq 0 ]; then
    echo -e $USAGE
    exit 1;
fi
if [ $1 = "-h" ] || [ $1 = "--help" ]; then
    echo -e $USAGE
    exit 0;
fi

if command -v pbcopy 2>/dev/null; then
    PBCOPY=pbcopy
else
    PBCOPY='xclip -selection clipboard'
fi

if [ -z $3 ]; then
    FORMAT=rtf
else
    FORMAT=$3
fi

# Awk version
#awk -F "START $2" '{print $2}' RS=';;END' $1 | awk 'NF > 0' | pygmentize -f $FORMAT -O "style=friendly,fontface=Inconsolata,fontsize=62" -l clojure | $PBCOPY

# Sed version
sed -n "/START $2/,/END/p" $1 | sed '1d;$d' | pygmentize -f $FORMAT -O "style=friendly,fontface=Inconsolata,fontsize=62" -l clojure | $PBCOPY

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment