nvimodes

Modes-like system for nvi2
git clone git://git.konyahin.xyz/nvimodes
Log | Files | Refs | LICENSE

ttxt (841B)


      1 #!/usr/bin/env sh
      2 
      3 set -eu
      4 
      5 if [ "$#" -lt 1 ]; then
      6     printf "Usage: ttxt <command>\nYour todo line should be send to stdin of ttxt.\n"
      7     exit 1
      8 fi
      9 
     10 # remove pattern string
     11 remove () {
     12     echo "$2" | sed "s/ $1//"
     13 }
     14 
     15 # remove all lists from string
     16 remove_lists () {
     17     lists="+maybe +todo +active"
     18     line="$1"
     19 
     20     for list in $lists
     21     do
     22         line=$(remove "$list" "$line")
     23     done
     24 
     25     echo "$line"
     26 }
     27 
     28 read -r LINE
     29 case "$1" in
     30     todo)
     31         LINE=$(remove_lists "$LINE")
     32         echo "$LINE +todo"
     33         ;;
     34     maybe)
     35         LINE=$(remove_lists "$LINE")
     36         echo "$LINE +maybe"
     37         ;;
     38     active)
     39         LINE=$(remove_lists "$LINE")
     40         echo "$LINE +active"
     41         ;;
     42     done)
     43         echo "x $(date +%Y-%m-%d) $LINE"
     44         ;;
     45     *)
     46         echo "Unknown command: $1"
     47         exit 1
     48         ;;
     49 esac
     50