|
|
1.1 ! root 1: #!/bin/sh ! 2: # ! 3: if [ $# != "1" ]; then ! 4: echo usage: editentry filename ! 5: exit 1 ! 6: fi ! 7: ! 8: F=T ! 9: while test -z "$EDITOR" ! 10: do ! 11: if [ $F = "T" ]; then ! 12: echo 'You do not have the shell variable $EDITOR set.' ! 13: F=F ! 14: fi ! 15: echo '' ! 16: echo -n 'Enter the name of an editor: ' ! 17: read EDITOR rubbish ! 18: ! 19: if [ ! -x "$EDITOR" ]; then ! 20: IFSS="$IFS" ! 21: IFS=: F="$EDITOR" ! 22: EDITOR= ! 23: for D in $PATH; do ! 24: if [ -x "$D/$F" ]; then ! 25: EDITOR="$D/$F" ! 26: break ! 27: fi ! 28: done ! 29: if [ -z "$EDITOR" ]; then ! 30: echo "$F not found, please try again..." ! 31: fi ! 32: IFS="$IFSS" ! 33: fi ! 34: done ! 35: ! 36: cp $1 $1.tmp ! 37: ! 38: E=T ! 39: while true ! 40: do ! 41: if [ $E = "T" ]; then ! 42: if $EDITOR $1; then ! 43: if cmp -s $1 $1.tmp; then ! 44: mess="No changes to draft entry - shall I continue? " ! 45: else ! 46: mess="Are you sure you want to make these changes? " ! 47: fi ! 48: else ! 49: echo 'Edit aborted...' ! 50: rm -f $1.tmp ! 51: exit 1 ! 52: fi ! 53: fi ! 54: ! 55: echo -n "$mess" ! 56: read YN rubbish ! 57: case "$YN" in ! 58: y|yes|Y|YES) ! 59: rm -f $1.tmp ! 60: exit 0 ! 61: ;; ! 62: ! 63: n|no|N|NO) ! 64: mv $1.tmp $1 ! 65: exit 1 ! 66: ;; ! 67: ! 68: e|edit|E|EDIT) ! 69: cp $1 $1.tmp ! 70: if [ ! -z "$rubbish" ] ! 71: then ! 72: EDITOR="$rubbish" ! 73: fi ! 74: E=T ! 75: ;; ! 76: ! 77: u|undo|U|UNDO) ! 78: cp $1.tmp $1 ! 79: E=T ! 80: ;; ! 81: ! 82: *) ! 83: case "$YN" in ! 84: \?|""|h|help|H|HELP) ! 85: mess='Options are:' ! 86: ;; ! 87: ! 88: *) ! 89: mess="\"$YN\" not understood -- use one of:" ! 90: ;; ! 91: esac ! 92: echo "$mess" ! 93: echo ' yes - to commit' ! 94: echo ' no - to abort' ! 95: echo ' edit - to continue editing' ! 96: echo ' undo - to undo last edit and edit some more' ! 97: mess='Try again: ' ! 98: E=F ! 99: ;; ! 100: esac ! 101: done
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.