#!/bin/sh # clikan.sh -- CLI Kanban ver='2017-06-22 Y.Bonetti' conf="${CLIKANCONF:-$HOME/.clikanconf}" defkanban="$HOME/clikanban.md" editor="${CLIKANEDIT:-$VISUAL}" editor="${editor:-$EDITOR}" editor="${editor:-ed}" tmpf=`mktemp -t clikanXXXXXX` || tmpf=${TMPDIR:-/tmp}/clikan$$`date +%S%M%d` : >$tmpf chmod 600 $tmpf if test ! -f "$conf" then cat <"$conf" # configuration file for $0 # (autogenerated at `date`) # file name can be defined by env.var CLIKANCONF # # prompt is displayed when waiting for command prompt |< # maxshow defines the maximum number of cards/lines to be displayed maxshow 15 # kanban defines a kanban file, may be given several times # kanban /some/path/to/jobkanban.txt # kanban /another/path/to/privatekanban.md kanban $defkanban EOT if test -f "$defkanban" then cp "$defkanban" "$defkanban.bak" echo found existing $defkanban, echo saved as backup $defkanban.bak fi cat <"$defkanban" # my kanban file * learn to use clikan - improve clikan + install clikan ### titles work as comments # might be a future card you don't yet want in waiting EOT fi # get lines beginning with a value, and remove that column # note SPC&TAB in patterns: make sure there is a SPC, # and that the value is complete getlines(){ sed -e 's/$/ /' | grep "^$1[ ]" | { while read _ values # remove trailing added TAB do echo "${values% }" done } } # display selection, and put selection list in tempfile, # input through stdin, with lines prepended with index number, TAB and arg1 showselect(){ local i i=1 : >$tmpf while read l do echo $i: $l echo "$i $1$l" >>$tmpf i=$(( $i+1 )) done } # get input from selection (showselect must be called before) getselect(){ if test "$1" != "" then echo "choice? (default: $1)" >&2 else echo "choice?" >&2 fi read i if test "$i" = "" then echo "$1" else getlines $i <$tmpf fi } kbs="`getlines kanban <"$conf"`" currkan="`echo "$kbs" | head -n 1`" prompt=`getlines prompt <"$conf" | head -n 1` maxshow=`getlines maxshow <"$conf" | head -n 1` maxshow=${maxshow:-22} #echo conf=$conf #echo kbs=$kbs #echo currkan=$currkan showprompt(){ if test "$prompt" != "" then echo -n $prompt '' fi } # display all 'something' cards showall(){ local f t case $1 in d*) f='*' ;; w*) f='-' ;; a*) f='+' ;; *) f='' ;; esac echo echo " $1" { cat $kbs | getlines "$f" if test "$f" = "*" # for "doing", also display '- ...(MM-DD)...' calendar entries then t=`date +%m-%d` cat $kbs | grep "^[*+-] .*($t)" | sed -e 's/^. //' fi } | showselect "$f " | head -n $maxshow } # replace lines (in any kanban) containing some ed pattern # arg.1=pattern, remainder=new line contents repline(){ local patt newl patt="$1" shift newl="$*" for ff in $kbs do cat </dev/null 2>&1 %g/$patt/c\\ $newl\\ . w q EOC done } showhelp(){ cat <>$currkan fi showall doing ;; ec) echo calling "$editor $conf" ... "$editor" "$conf" echo please quit and restart to reload config ;; ek) echo calling "$editor $currkan" ... "$editor" "$currkan" echo welcome back ;; *) showhelp showall doing ;; esac showprompt done echo /bin/rm -f $tmpf