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"
 | 
			
		||||
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
 | 
			
		||||
	content="$(cat "$1")"
 | 
			
		||||
	cat "$1"
 | 
			
		||||
@ -22,12 +37,47 @@ while test -n "$1"; do
 | 
			
		||||
		read -r command args
 | 
			
		||||
 | 
			
		||||
		case $command in
 | 
			
		||||
			"a")
 | 
			
		||||
				read -r append
 | 
			
		||||
				content="$(printf "%s\n%s" "$content" "$append")"
 | 
			
		||||
				;;
 | 
			
		||||
			"c")
 | 
			
		||||
				clear
 | 
			
		||||
				;;
 | 
			
		||||
			"d")
 | 
			
		||||
				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")
 | 
			
		||||
				printf "%s: i: Command not implemented.\n" "$argv0"
 | 
			
		||||
				;;
 | 
			
		||||
@ -50,7 +100,7 @@ while test -n "$1"; do
 | 
			
		||||
					break
 | 
			
		||||
				fi
 | 
			
		||||
				;;
 | 
			
		||||
			"s")
 | 
			
		||||
			"r")
 | 
			
		||||
				content="$(printf "%s" "$content" | sed "$args")"
 | 
			
		||||
				;;
 | 
			
		||||
			"w")
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user