Skip to content

Instantly share code, notes, and snippets.

@rkumar
Created November 14, 2011 07:48
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save rkumar/1363473 to your computer and use it in GitHub Desktop.
Save rkumar/1363473 to your computer and use it in GitHub Desktop.
print my bugs and issues from sqlite3 table using bash
#
# quickly report data from sqldatabase avoiding ruby's load time
# also colorize file
# colorize can only do a line, whereas sed allows us to do parts. but using ansi
# its not easy to do both lines and part, so it sucks
# most allows us to page horizontally
# less does not
# colorize only does basic colors, in bash we can do 256.
#
cd ~/work/projects/rbcurse/examples
file="t.sqlit"
out="t2.sqlit"
export END="\x1b[0m"
export ON_GRAY="\x1b[48;5;234m"
echo "${ON_GRAY} Bugs ${END}" > $out
echo ".mode column" > $file
echo "select id, title, priority, status from bugs where status != 'closed' order by priority , id;" >> $file
sqlite3 bugzy.sqlite < $file >> $out
# this is the gray scale 232-256
#cat <<ZZZ > colorize.cfg
#/ cancel/ black
#/ closed / black
#/ started / blue on_yellow
#/ P1 / reverse
#/ P2 / bold white on_blue
#/ P3 / yellow
#/ P4 / magenta
#/ P5 / bold blue
#ZZZ
#colorize --config=./colorize.cfg $out | less
. ~/bin/colormap.sh
text=$(sed "\
s/\(.* started .*\)/${BLUE}${ON_WHITE}\1${DEFAULT}/g;\
s/\(.* canceled .*\)/${BLACK}\1${DEFAULT}/g;\
s/\(.*P1.*\)/${BLACK}${ON_YELLOW}\1${DEFAULT}/g;\
s/\(.*P2.*\)/${YELLOW}${ON_GRAY236}\1${DEFAULT}/g;\
s/\(.*P3.*\)/${CYAN}${ON_GRAY235}\1${DEFAULT}/g;\
s/\(.*P4.*\)/${GREEN}${ON_GRAY234}\1${DEFAULT}/g;\
s/\(.*P5.*\)/${BLUE}\1${DEFAULT}/g;\
" $out)
echo "$text" | less
#s/P3/${LIGHT_CYAN}P3${DEFAULT}/g; \
#s/#fix/${LIGHT_RED}${ON_YELLOW}#fix${DEFAULT}/g; \
#s/#\([^ ]*\)/${BLACK}${ON_GREEN}#\1${DEFAULT}/g; \
#s/%\([^ ]*\)/${WHITE}${ON_BLUE}%\1${DEFAULT}/g; \
#s/clean/${UNDERLINE}clean${DEFAULT}/g; \
#most $out
rm $file $out
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment