zenu

Des menus dans votre terminal - retour accueil

git clone git://bebou.netlib.re/zenu
Log | Files | Refs | README |

build (947B)


      1 #!/bin/zsh -ue
      2 #!/bin/sh -ue
      3 
      4 usage() <<-% cat
      5 	usage:
      6 	* build a face (the file that becomes part of a menu)
      7 		$0 face file
      8 		$0 -f file
      9 	* build a script (the function to handle pressed keys)
     10 		$0 script file
     11 		$0 -f file
     12 %
     13 
     14 cmd="${1?command to run. -h for details}"
     15 :   "${2?file to parse. -h for details}"
     16 shift
     17 
     18 case "$cmd"
     19 in (-h|help|--help) usage
     20 ;; (face   | -f) sed -En '/^##/q;s/_(.)/\x1b[7m\1\x1b[m/g;s/^/ /p' "$@"
     21 # Avoid Quoting hell (QH) with aliases:
     22 # with QH 
     23 ;; (script | -s) <<-% cat
     24 		$( sed -En '/^## *pre */,/^##/p' "$@" )
     25 		read -sk1 zenu_key
     26 		case "\$zenu_key"
     27 		in (\$'q') zenu--
     28 		$( sed -En '/^## *react */,/^##/p' "$@" )
     29 		esac 2> \$zenu_store/err
     30 	%
     31 ;; (emph| -e)
     32 	sed -En '/^##/q;s/(.*)_((.).*)/\3 \1\2 /;p' "$@" | awk '
     33 			{line[i++]=$0}
     34 			(l=length)>m {m=l}
     35 			END { for (i=0; i<until ; ++i) printf "%-*s\n", m, line[i] }
     36 		' until=$(cat $to/until.txt)
     37 ;; (*)
     38 	>& echo "$cmd isn't a valid command"
     39 	false
     40 esac
     41 
     42