Created
July 10, 2018 12:20
-
-
Save bluec0re/e99bf3f2d0fa1b5f8deef465d9e777ee to your computer and use it in GitHub Desktop.
Uses pygmentize and xclip to create pasteable (e.g. into Google docs, Word, Libreoffice, ...) code highlighting from the command line
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
style='paraiso-dark' | |
lang='' | |
preview='' | |
options='' | |
while getopts 's:l:po:' opt; | |
do | |
case $opt in | |
s) | |
style=$OPTARG | |
;; | |
l) | |
lang=$OPTARG | |
;; | |
p) | |
preview='true' | |
;; | |
o) | |
options=",$OPTARG" | |
;; | |
esac | |
done | |
if [ -z $lang ] | |
then | |
echo '[-] no language set with -l' | |
echo '[-] supported languages:' | |
pygmentize -L lexers | |
exit 1 | |
fi | |
if [ "$preview" == "true" ] | |
then | |
code=$(cat ${@:$OPTIND}) | |
pygmentize -L styles | grep '*' | sed 's/\(\* \)\|://g' |& while read style | |
do | |
echo $style | |
echo $code | pygmentize -l $lang -f terminal256 -O style=$style | |
done | |
else | |
pygmentize -l $lang -f html -O style=$style,noclasses$options "${@:$OPTIND}" | xclip -i -selection clipboard -t text/html | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment