-
-
Save meganlkm/4fc7774bff042ee8b7ab64ce5ea3ee27 to your computer and use it in GitHub Desktop.
catp: The cat command with syntax highlighting.
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
#!/usr/bin/env bash | |
## Install ####################################### | |
# pip install Pygments pygments-markdown-lexer | |
# cp catp ~/.catp | |
# echo "source .catp" >> .bash_profile | |
## Usage ######################################### | |
# > catp filename.foo | |
################################################## | |
hash pygmentize &>/dev/null; | |
if [ $? -eq 0 ]; then | |
function catp() { | |
fullfile=$(basename "${1}") | |
extension="${fullfile##*.}" | |
lex="text" | |
case $extension in | |
*.yml.j2) lex="salt" ;; | |
vimrc|vim|exrc|gvimrc) lex="vim" ;; | |
fancypack|fy|notes) lex="fancy" ;; | |
c|h|idc) lex="c" ;; | |
mu) lex="mupad" ;; | |
TODO|todo|todotxt) lex="todotxt" ;; | |
http) lex="http" ;; | |
j2) lex="jinja" ;; | |
fish) lex="fish" ;; | |
doscon) lex="doscon" ;; | |
powershell) lex="powershell" ;; | |
csh|tcsh) lex="tcsh" ;; | |
tcl) lex="tcl" ;; | |
moo) lex="moocode" ;; | |
lua|wlua) lex="lua" ;; | |
resource) lex="resource" ;; | |
ttl) lex="turtle" ;; | |
Rout) lex="rconsole" ;; | |
rd) lex="Rd" ;; | |
qvto) lex="qvto" ;; | |
pycon|pyshell) lex="pycon" ;; | |
dg) lex="dg" ;; | |
g|gd|gi|gap) lex="gap" ;; | |
pyx) lex="cython" ;; | |
logtalk) lex="logtalk" ;; | |
tap) lex="tap" ;; | |
praat) lex="praat" ;; | |
pawn) lex="pawn" ;; | |
awk) lex="awk" ;; | |
delphi) lex="delphi" ;; | |
java) lex="java" ;; | |
pl|pm|nqp|p6|6pl|p6l|pl6|6pm|p6m|pm6|t) lex="perl" ;; | |
antlr) lex="antlr" ;; | |
psi|psl) lex="parasail" ;; | |
ooc) lex="ooc" ;; | |
swift) lex="swift" ;; | |
h|m) lex="objectivec" ;; | |
x|xi|xm|xmi) lex="logos" ;; | |
cp|cps) lex="cp" ;; | |
nix) lex="nix" ;; | |
nit) lex="nit" ;; | |
nim|nimrod) lex="nimrod" ;; | |
sml) lex="sml" ;; | |
opa) lex="opa" ;; | |
mll|ml|mli|mly) lex="ocaml" ;; | |
css) lex="css" ;; | |
less) lex="less" ;; | |
sass) lex="sass" ;; | |
scss) lex="scss" ;; | |
diff|patch) lex="diff" ;; | |
proto) lex="proto" ;; | |
pp) lex="puppet" ;; | |
thrift) lex="thrift" ;; | |
elm) lex="elm" ;; | |
io) lex="io" ;; | |
coffee) lex="coffee" ;; | |
dart) lex="dart" ;; | |
jade) lex="jade" ;; | |
htm|html|xhtml) lex="html" ;; | |
xslt) lex="xslt" ;; | |
cfg|gitconfig|gitignore|ignore|ini) lex="ini" ;; | |
js|jsm) lex="javascript" ;; | |
json|sublime-project) lex="json" ;; | |
mak|mk|makefile|Makefile|GNUmakefile) lex="makefile" ;; | |
php|php[345]|inc) lex="php" ;; | |
py|pip|pyw|sc|SConstruct|SConscript|tac|sage) lex="python" ;; | |
pytb) lex="pytb" ;; | |
rb|rbw|Rakefile|rake|gemspec|rbx|duby|Gemfile) lex="ruby" ;; | |
md|README|LICENSE) lex="md" ;; | |
ex|exs) lex="elixir" ;; | |
erl|hrl|es|escript) lex="erlang" ;; | |
erl-sh) lex="erl" ;; | |
b|bf) lex="brainfuck" ;; | |
rst|rest) lex="rst" ;; | |
go) lex="go" ;; | |
rs|rust) lex="rust" ;; | |
applescript) lex="applescript" ;; | |
chai) lex="chai" ;; | |
plot|plt) lex="gnuplot" ;; | |
ps|eps) lex="postscript" ;; | |
hs) lex="haskell" ;; | |
dtd) lex="dtd" ;; | |
haml) lex="haml" ;; | |
env|profile|sh|st3|venv|ksh|ebuild|eclass|exheres-0|exlib|PKGBUILD|bash*|env*) lex="shell" ;; | |
xml) lex="xml" ;; | |
sql) lex="sql" ;; | |
vala) lex="vala" ;; | |
scala) lex="scala" ;; | |
vapi) lex="vapi" ;; | |
docker) lex="docker" ;; | |
el) lex="emacs" ;; | |
tex|aux|toc) lex="latex" ;; | |
scm|ss) lex="scheme" ;; | |
cl|lisp) lex="lisp" ;; | |
clj) lex="clojure" ;; | |
cljs) lex="clojurescript" ;; | |
feature) lex="gherkin" ;; | |
groovy|gradle) lex="groovy" ;; | |
yml|yaml) lex="yaml" ;; | |
*rc) lex="shell" ;; | |
*) lex="text" ;; | |
esac | |
case $fullfile in | |
Rakefile|Vagrantfile) lex="ruby" ;; | |
sources.list) lex="debsources" ;; | |
Dockerfile) lex="docker" ;; | |
control) lex="debcontrol" ;; | |
composer) lex="php" ;; | |
*.rs.in) lex="rust" ;; | |
*-session) lex="console" ;; | |
todo.txt) lex="todotxt" ;; | |
esac | |
pygmentize -l $lex $1 | |
} | |
fi; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment