diff options
| author | Jeff Quast <contact@jeffquast.com> | 2014-11-22 12:31:21 -0800 |
|---|---|---|
| committer | Jeff Quast <contact@jeffquast.com> | 2014-11-22 12:31:21 -0800 |
| commit | 040a715ef4b2b74a6748f503322a6acdf56e8b9e (patch) | |
| tree | fd31c82312ec59b530f75557e8f5a20da961c063 /pexpect | |
| parent | 54ab1daf7bef87ee840019c1148d007c323f4a38 (diff) | |
| parent | 35a920e0f933929c6d37fffbb448212c27b92480 (diff) | |
| download | pexpect-040a715ef4b2b74a6748f503322a6acdf56e8b9e.tar.gz | |
Merge pull request #115 from takluyver/replwrap-bash-robustness
Make replwrap.bash() robust against custom prompts in bashrc
Diffstat (limited to 'pexpect')
| -rw-r--r-- | pexpect/bashrc.sh | 5 | ||||
| -rw-r--r-- | pexpect/replwrap.py | 7 |
2 files changed, 10 insertions, 2 deletions
diff --git a/pexpect/bashrc.sh b/pexpect/bashrc.sh new file mode 100644 index 0000000..99a3ac2 --- /dev/null +++ b/pexpect/bashrc.sh @@ -0,0 +1,5 @@ +source /etc/bash.bashrc +source ~/.bashrc + +# Reset PS1 so pexpect can find it +PS1="$" diff --git a/pexpect/replwrap.py b/pexpect/replwrap.py index 2e50286..0c879ff 100644 --- a/pexpect/replwrap.py +++ b/pexpect/replwrap.py @@ -1,5 +1,6 @@ """Generic wrapper for read-eval-print-loops, a.k.a. interactive shells """ +import os.path import signal import sys import re @@ -104,7 +105,9 @@ def python(command="python"): """Start a Python shell and return a :class:`REPLWrapper` object.""" return REPLWrapper(command, u(">>> "), u("import sys; sys.ps1={0!r}; sys.ps2={1!r}")) -def bash(command="bash", orig_prompt=re.compile('[$#]')): +def bash(command="bash"): """Start a bash shell and return a :class:`REPLWrapper` object.""" - return REPLWrapper(command, orig_prompt, u("PS1='{0}' PS2='{1}' PROMPT_COMMAND=''"), + bashrc = os.path.join(os.path.dirname(__file__), 'bashrc.sh') + child = pexpect.spawnu(command, ['--rcfile', bashrc]) + return REPLWrapper(child, u'\$', u("PS1='{0}' PS2='{1}' PROMPT_COMMAND=''"), extra_init_cmd="export PAGER=cat") |
