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