From afce604605df4a91b4ebbf548812f147c1d235ed Mon Sep 17 00:00:00 2001 From: Tom Ryder Date: Mon, 19 Dec 2016 17:36:19 +1300 Subject: Attempt at properly escaping non-printing chars This is supposed to be the equivalent of \[ \] in Bash PS1... >Note that since the command line editors try to figure out how long the >prompt is (so they know how far it is to edge of the screen), escape >codes in the prompt tend to mess things up. You can tell the shell not >to count certain sequences (such as escape codes) by prefixing your >prompt with a non-printing char- acter (such as control-A) followed by >a carriage return and then delimiting the escape codes with this >non-printing character. If you don't have any non-printing characters, >you're out of luck... BTW, don't blame me for this hack; it's in the >original ksh. --- ksh/kshrc.d/prompt.ksh | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) (limited to 'ksh') diff --git a/ksh/kshrc.d/prompt.ksh b/ksh/kshrc.d/prompt.ksh index 8b460136..2ebe1099 100644 --- a/ksh/kshrc.d/prompt.ksh +++ b/ksh/kshrc.d/prompt.ksh @@ -81,8 +81,13 @@ function prompt { } >/dev/null 2>&1 + # Play ball with ksh's way of escaping non-printing characters + typeset es nl + es=$(printf '\00') + nl=$(printf '\n') + # String it all together - PS1="${format}${PS1}${reset}"' ' + PS1="${es}${nl}${es}${format}${es}${PS1}${es}${reset}${es}"' ' PS2='> ' PS3='? ' PS4='+<$?> $LINENO:' -- cgit v1.2.3