integ/base/lshell/files/lshell-newline-escape-chara...

54 lines
2.0 KiB
Diff

---
lshell/shellcmd.py | 26 +++++++++++++++++++++++++-
1 file changed, 25 insertions(+), 1 deletion(-)
--- a/lshell/shellcmd.py
+++ b/lshell/shellcmd.py
@@ -74,6 +74,7 @@ class ShellCmd(cmd.Cmd, object):
self.promptbase = getuser()
self.prompt = '%s:~$ ' % self.promptbase
+ self.prompt2 = '> ' # PS2 prompt
self.intro = self.conf['intro']
@@ -670,6 +671,12 @@ class ShellCmd(cmd.Cmd, object):
self.stdout.write("%s\n" % self.intro)
if self.conf['login_script']:
self.loginCmdParse(self.conf['login_script'])
+
+ # for long commands, a user may escape the new line
+ # by giving a bash like '\' character at the end of
+ # the line. cmdloop() needs to recognize that and
+ # create an appended line before sending it to onecmd()
+ partial_line = ""
stop = None
while not stop:
if self.cmdqueue:
@@ -691,7 +698,24 @@ class ShellCmd(cmd.Cmd, object):
line = 'EOF'
else:
line = line[:-1] # chop \n
- line = self.precmd(line)
+
+ if len(line) > 1 and line.startswith('\\'):
+ # implying previous partial line
+ line = line[:1].replace('\\', '', 1)
+ if partial_line:
+ line = partial_line + line
+ if line.endswith('\\'):
+ # continuation character. First partial line.
+ # We shall expect the command to continue in
+ # a new line. Change to bash like PS2 prompt to
+ # indicate this continuation to the user
+ partial_line = line.strip('\\')
+ self.prompt = self.prompt2 # switching to PS2
+ continue
+ partial_line = ""
+
+ self.updateprompt(os.getcwd())
+ line = self.precmd(line)
stop = self.onecmd(line)
stop = self.postcmd(stop, line)
self.postloop()