| 1 |
import time |
| 2 |
|
| 3 |
SHELL_ENV = { |
| 4 |
# disable readline's rcfile for bash |
| 5 |
'INPUTRC': '/dev/null', |
| 6 |
|
| 7 |
# set locale to C to ensure same ordering of options |
| 8 |
'LANG': 'C', |
| 9 |
'LC_CTYPE': 'C', |
| 10 |
'LC_NUMERIC': 'C', |
| 11 |
'LC_TIME': 'C', |
| 12 |
'LC_COLLATE': 'C', |
| 13 |
'LC_MONETARY': 'C', |
| 14 |
'LC_MESSAGES': 'C', |
| 15 |
'LC_PAPER': 'C', |
| 16 |
'LC_NAME': 'C', |
| 17 |
'LC_ADDRESS': 'C', |
| 18 |
'LC_TELEPHONE': 'C', |
| 19 |
'LC_MEASUREMENT': 'C', |
| 20 |
'LC_IDENTIFICATION': 'C', |
| 21 |
'LC_ALL': 'C' |
| 22 |
} |
| 23 |
|
| 24 |
def wait_for_prompt(terminal): |
| 25 |
terminal.wait_for_text('>', 5, 0.1) |
| 26 |
|
| 27 |
class ShellBase: |
| 28 |
def __init__(self, term): |
| 29 |
self.term = term |
| 30 |
|
| 31 |
def stop(self): |
| 32 |
self.term.stop() |
| 33 |
|
| 34 |
class BashShell(ShellBase): |
| 35 |
def start(self): |
| 36 |
self.term.start(['bash', '--norc', '--noprofile', '+o', 'history'], SHELL_ENV) |
| 37 |
|
| 38 |
def set_prompt(self): |
| 39 |
self.term.send_line("clear; PS1='> '") |
| 40 |
wait_for_prompt(self.term) |
| 41 |
|
| 42 |
def init_completion(self): |
| 43 |
self.term.send_line('source /usr/share/bash-completion/bash_completion') |
| 44 |
self.term.send_line('bind "set show-all-if-ambiguous on"') |
| 45 |
self.term.send_line('bind "set show-all-if-unmodified on"') |
| 46 |
self.term.send_line('clear') |
| 47 |
wait_for_prompt(self.term) |
| 48 |
|
| 49 |
def load_completion(self, file): |
| 50 |
self.term.send_line('clear; source %s' % file) |
| 51 |
wait_for_prompt(self.term) |
| 52 |
|
| 53 |
class FishShell(ShellBase): |
| 54 |
def start(self): |
| 55 |
self.term.start(['fish', '--no-config'], SHELL_ENV | {'fish_autosuggestion_enabled': 0}) |
| 56 |
|
| 57 |
def set_prompt(self): |
| 58 |
self.term.send_line("clear; function fish_prompt; printf '> '; end") |
| 59 |
wait_for_prompt(self.term) |
| 60 |
|
| 61 |
def init_completion(self): |
| 62 |
pass |
| 63 |
|
| 64 |
def load_completion(self, file): |
| 65 |
self.term.send_line('clear; source %s' % file) |
| 66 |
wait_for_prompt(self.term) |
| 67 |
|
| 68 |
class ZshShell(ShellBase): |
| 69 |
def start(self): |
| 70 |
self.term.start(['zsh', '--no-rcs'], SHELL_ENV) |
| 71 |
|
| 72 |
def set_prompt(self): |
| 73 |
self.term.send_line("clear; PROMPT='> '") |
| 74 |
wait_for_prompt(self.term) |
| 75 |
|
| 76 |
def init_completion(self): |
| 77 |
self.term.send_line('clear; autoload -U compinit && compinit') |
| 78 |
wait_for_prompt(self.term) |
| 79 |
|
| 80 |
def load_completion(self, file): |
| 81 |
self.term.send_line('clear; source %s' % file) |
| 82 |
wait_for_prompt(self.term) |