Shell scripts minimizing machine time, maximizing tao time.

git clone git://watertao.xyz/programs/tao_shells.git

tao_notes.sh (1277B)


      1 #!/bin/sh
      2 
      3 # A lightning fast notes program
      4 # Requirements: dmenu and a terminal emulator
      5 
      6 # following config normally lives in included conf file,
      7 # but for the sake of simplicity in sharing these shell scripts
      8 # I included the relevant definitions here, dmenu and term
      9 
     10 cmdf(){ command -v "$1" >/dev/null 2>&1; }
     11 
     12 # dmenu command
     13 if [ -z "$DMENU" ]
     14 then
     15 	a="dmenu sxmo_dmenu.sh bemenu rofi"
     16 	for i in $a; do cmdf "$i" && export DMENU="$i" && break; done
     17 fi
     18 
     19 # term command
     20 if [ -z "$TERMINAL" ]
     21 then
     22 	a="st urxvt xterm sxmo_terminal.sh"
     23 	for i in $a; do cmdf "$i" && export TERMINAL="$i" && break; done
     24 fi
     25 
     26 # dmenu config
     27 if [ -z "$DMENU_OPTS" ]
     28 then
     29 	a="$HOME/.config/tao/tao_dmenu.conf" && [ -f "$a" ] && \
     30 		DMENU_OPTS=$(<"$a" sed -n '1p' | tr -d "\n")
     31 	export DMENU_OPTS="${DMENU_OPTS:-""}"
     32 fi
     33 
     34 cu(){ exit 1; }; trap cu INT
     35 
     36 d=$HOME/.local/share/tao/notes
     37 [ ! -d "$d" ] && mkdir -p "$d"
     38 
     39 notesel(){
     40 	ls -1 "$d" | \
     41 	"$DMENU" $DMENU_OPTS -p "Tao Notes" || return 1
     42 }
     43 
     44 fnote(){
     45 	a=$(notesel) && [ -n "$a" ] || return 1
     46 	printf "%s\n" "$a" | while IFS= read -r f; do
     47 		if [ "${f##*::}" = "r" ]; then
     48 			g="$d/${f%::r}"
     49 			[ -f "$g" ] && rm "$g"
     50 			return 0
     51 		else
     52 			"$TERMINAL" -- "$EDITOR" "$d/$f"
     53 			return 1
     54 		fi
     55 	done && return 0 || return 1
     56 }
     57 
     58 while fnote; do :; done