#!/bin/sh # clikan.sh -- CLI Kanban ver='2017-06-20 Y.Bonetti' conf="${CLIKANCONF:-$HOME/.clikanconf}" defkanban="$HOME/clikanban.md" editor="${CLIKANEDIT:-$VISUAL}" editor="${editor:-$EDITOR}" editor="${editor:-ed}" tmpf=$HOME/.clikan.tmp 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 |< # 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 cat <"$defkanban" # my kanban file * learn to use clikan - improve clikan + install clikan 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` #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 case $1 in d*) f='*' ;; w*) f='-' ;; a*) f='+' ;; *) f='' ;; esac echo echo " $1" cat "$kbs" | getlines "$f" | showselect "$f " } # 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