added append and help mode
This commit is contained in:
parent
dadfad0650
commit
a61ae5ab77
52
en
52
en
@ -13,6 +13,21 @@ if test -z "$1"; then
|
|||||||
printf "Usage: %s file...\n" "$argv0"
|
printf "Usage: %s file...\n" "$argv0"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
help="Commands:\n\
|
||||||
|
a – appends a line to the current buffer.\n\
|
||||||
|
c – clears the screen.\n\
|
||||||
|
d – deletes a line.\n\
|
||||||
|
e – evaluates a command in the shell environment.\n\
|
||||||
|
h – displays this help message.\n\
|
||||||
|
i – inserts a line into the buffer at position line.\n\
|
||||||
|
p – prints the current buffer.\n\
|
||||||
|
q – terminates editing.\n\
|
||||||
|
r – applies a regular expression to the current buffer.\n\
|
||||||
|
w – writes the current buffer to the file.\n\
|
||||||
|
\n\
|
||||||
|
To learn more about a command verb, type \`h verb'.
|
||||||
|
"
|
||||||
|
|
||||||
while test -n "$1"; do
|
while test -n "$1"; do
|
||||||
content="$(cat "$1")"
|
content="$(cat "$1")"
|
||||||
cat "$1"
|
cat "$1"
|
||||||
@ -22,12 +37,47 @@ while test -n "$1"; do
|
|||||||
read -r command args
|
read -r command args
|
||||||
|
|
||||||
case $command in
|
case $command in
|
||||||
|
"a")
|
||||||
|
read -r append
|
||||||
|
content="$(printf "%s\n%s" "$content" "$append")"
|
||||||
|
;;
|
||||||
"c")
|
"c")
|
||||||
clear
|
clear
|
||||||
;;
|
;;
|
||||||
"d")
|
"d")
|
||||||
printf "%s: d: Command not implemented.\n" "$argv0"
|
printf "%s: d: Command not implemented.\n" "$argv0"
|
||||||
;;
|
;;
|
||||||
|
"e")
|
||||||
|
eval "$args"
|
||||||
|
;;
|
||||||
|
"h")
|
||||||
|
if test -z "$args"; then
|
||||||
|
printf "$help\n"
|
||||||
|
else
|
||||||
|
printf "%s: Command-specific help not implemented.\n" "$argv0"
|
||||||
|
continue
|
||||||
|
case $args in
|
||||||
|
"c")
|
||||||
|
;;
|
||||||
|
"d")
|
||||||
|
;;
|
||||||
|
"e")
|
||||||
|
;;
|
||||||
|
"h")
|
||||||
|
;;
|
||||||
|
"i")
|
||||||
|
;;
|
||||||
|
"p")
|
||||||
|
;;
|
||||||
|
"q")
|
||||||
|
;;
|
||||||
|
"r")
|
||||||
|
;;
|
||||||
|
"w")
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
fi
|
||||||
|
;;
|
||||||
"i")
|
"i")
|
||||||
printf "%s: i: Command not implemented.\n" "$argv0"
|
printf "%s: i: Command not implemented.\n" "$argv0"
|
||||||
;;
|
;;
|
||||||
@ -50,7 +100,7 @@ while test -n "$1"; do
|
|||||||
break
|
break
|
||||||
fi
|
fi
|
||||||
;;
|
;;
|
||||||
"s")
|
"r")
|
||||||
content="$(printf "%s" "$content" | sed "$args")"
|
content="$(printf "%s" "$content" | sed "$args")"
|
||||||
;;
|
;;
|
||||||
"w")
|
"w")
|
||||||
|
Loading…
Reference in New Issue
Block a user