Skip to content

Instantly share code, notes, and snippets.

@pieterdavid
Last active February 4, 2019 09:51
Show Gist options
  • Save pieterdavid/b58c586e333ab0ac00b7b7499e4a487e to your computer and use it in GitHub Desktop.
Save pieterdavid/b58c586e333ab0ac00b7b7499e4a487e to your computer and use it in GitHub Desktop.
Git grep tricks for CMSSW
#!/bin/sh
# Shell script to start Vim with less.vim.
# Read stdin if no arguments were given and stdin was redirected.
## modified by Pieter David, June 2017: take a filename-like argument to deduct the filetype from, but always read from stdin
## suggested git alias: view = "!v() { git show $1 | ~/.vim/macros/filetypeless.sh $1; }; v"
if test -t 1; then
if test $# = 0; then
echo "Missing filename" 1>&2
exit
else
ftcmd=$(vim -es --cmd "filetype on" "${1}" -c ':exec ":set filetype?" | exec ":q!"')
vim -R --cmd 'let no_plugin_maps = 1' -c "set ${ftcmd}" -c 'runtime! macros/less.vim' -
fi
else
# Output is not a terminal, cat arguments or stdin
if test $# = 0; then
if test -t 0; then
echo "Missing filename" 1>&2
exit
fi
cat
else
cat "$@"
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment