#!/bin/bash help(){ cat <<-HELP checkpoint dumpvars getvar exit help listfunc liststate listtarget listtask settask task target state/:func ... setpriority task target priority ... unsettask task target runtask task target setvar var valeur [timestamp] unsetvar var setstate state unsetstate state lock unlock cleartasks clearvars HELP } commands(){ eval " case \$1 in $COMMANDS) return 0 ;; esac return 1 " } # A nice cheat to provide tab completion tab_setup(){ local DIR="$HOME/.ninacsh_tab" if [ ! -d "$DIR" ] ; then mkdir $DIR fi rm -Rf $HOME/.ninacsh_tab/* help | while read cmd args ; do touch $DIR/$cmd done cd $DIR } history_setup(){ HISTFILE="$HOME/.ninacsh_history" HISTFILESIZE=1000 test -s $HISTFILE || echo help >$HISTFILE history -r } # Some crazy incantation pulled off the net... history_remember(){ history -w history -s -- "$@" history -a history -c history -r } LOCK= while getopts ":l" opt ; do case $opt in l) LOCK=1 ;; esac done shift $(($OPTIND - 1)) if [ -n "$1" ] ; then exec 0<$1 || exit fi NINACCMD="/usr/bin/ninaccmd" COMMANDS=$(help | (while read cmd args ; do echo -n "$cmd|" ; done)) COMMANDS=${COMMANDS%|} test -t 0 && history_setup # test -t 0 && tab_setup { [ -n "$LOCK" ] && echo lock while read -e -p '> ' command args ; do [ -z $command ] && continue [ "${command:0:1}" = "#" ] && continue test -t 0 && history_remember $command $args case $command in exit) break ;; help) help ;; *) if commands $command ; then echo $command $args else echo "Unknown command '$command'." >&2 fi ;; esac done [ -n "$LOCK" ] && echo unlock } | $NINACCMD -f -