github.com/cockroachdb/cockroach@v20.2.0-alpha.1+incompatible/scripts/log2html.sh (about) 1 #!/usr/bin/env bash 2 3 # Script that converts a log file to html, using cockroach-specific log syntax 4 # highlighting. Requires vim to be installed. 5 # 6 # Usage: log2html.sh [input-file [output-file]] 7 # input-file can be - for stdin. 8 # If not specified, stdin/stdout are used. 9 10 set -e 11 12 input="$1" 13 [ -z "$input" ] && input="-" 14 15 output="$2" 16 17 outfile="$output" 18 if [ -z "$output" ]; then 19 outfile=$(mktemp) 20 trap "rm -f $outfile" EXIT 21 fi 22 23 dir=$(dirname $0) 24 25 if ! $(which vim >/dev/null 2>/dev/null); then 26 >&2 echo "Error: vim needs to be installed." 27 >&2 echo " on Ubuntu: sudo apt-get install vim-gtk" 28 >&2 echo " on Mac: brew install vim" 29 exit 1 30 fi 31 32 # Check if vim supports the "--not-a-term" switch which suppresses a warning 33 # about the output not being a terminal. 34 EXTRA_OPTS="" 35 if vim --not-a-term --version >/dev/null 2>/dev/null; then 36 EXTRA_OPTS="--not-a-term" 37 fi 38 39 vim -X $EXTRA_OPTS -n -i NONE -u NORC \ 40 +"syn on" \ 41 +"colorscheme torte" \ 42 +"source $dir/crlog.vim" \ 43 +"let g:html_no_progress=1" \ 44 +"run! syntax/2html.vim" \ 45 +"saveas! $outfile" \ 46 +"qa!" \ 47 "$input" >/dev/null 48 49 if [ -z "$output" ]; then 50 cat $outfile 51 fi