summaryrefslogtreecommitdiff
path: root/pexpect
diff options
context:
space:
mode:
authorThomas Kluyver <thomas@kluyver.me.uk>2016-07-09 22:41:41 +0100
committerThomas Kluyver <thomas@kluyver.me.uk>2016-07-09 22:41:41 +0100
commite2ac2dcf3768aa04f8a1eb4b656b3f0b5a49d945 (patch)
tree884e49dd23ca397fbd6c5f3f557805f2140d373f /pexpect
parentba20384b6168d3a99a66719894cf04306ac01302 (diff)
downloadpexpect-e2ac2dcf3768aa04f8a1eb4b656b3f0b5a49d945.tar.gz
Fix running 'env' in replwrap-ed bash
Diffstat (limited to 'pexpect')
-rw-r--r--pexpect/replwrap.py11
1 files changed, 10 insertions, 1 deletions
diff --git a/pexpect/replwrap.py b/pexpect/replwrap.py
index 6439b35..118aa9f 100644
--- a/pexpect/replwrap.py
+++ b/pexpect/replwrap.py
@@ -109,5 +109,14 @@ def bash(command="bash"):
bashrc = os.path.join(os.path.dirname(__file__), 'bashrc.sh')
child = pexpect.spawn(command, ['--rcfile', bashrc], echo=False,
encoding='utf-8')
- return REPLWrapper(child, u'\$', u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''",
+
+ # If the user runs 'env', the value of PS1 will be in the output. To avoid
+ # replwrap seeing that as the next prompt, we'll embed the marker characters
+ # for invisible characters in the prompt; these show up when inspecting the
+ # environment variable, but not when bash displays the prompt.
+ ps1 = PEXPECT_PROMPT[:5] + u'\[\]' + PEXPECT_PROMPT[5:]
+ ps2 = PEXPECT_CONTINUATION_PROMPT[:5] + u'\[\]' + PEXPECT_CONTINUATION_PROMPT[5:]
+ prompt_change = u"PS1='{0}' PS2='{1}' PROMPT_COMMAND=''".format(ps1, ps2)
+
+ return REPLWrapper(child, u'\$', prompt_change,
extra_init_cmd="export PAGER=cat")