From 7b29b54ac7ceffcbff966eb5685dec1f81cf399a Mon Sep 17 00:00:00 2001 From: Hugh Macdonald Date: Wed, 13 May 2015 15:55:33 +0100 Subject: [PATCH] Add initial tcsh support. Still require better history support --- README.md | 5 +++++ thefuck/shells.py | 27 ++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 63092266..e548f918 100644 --- a/README.md +++ b/README.md @@ -118,6 +118,11 @@ Or in your `.zshrc`: alias fuck='eval $(thefuck $(fc -ln -1 | tail -n 1)); fc -R' ``` +If you are using `tcsh`: +```tcsh +alias fuck 'set fuckedCmd=`history -h 2 | head -n 1` && eval `thefuck ${fuckedCmd}`' +``` + Alternatively, you can redirect the output of `thefuck-alias`: ```bash diff --git a/thefuck/shells.py b/thefuck/shells.py index 7b3aafd2..940f196f 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -92,9 +92,34 @@ class Zsh(Generic): return u': {}:0;{}\n'.format(int(time()), command_script) +class Tcsh(Generic): + def app_alias(self): + return "\nalias fuck 'set fucked_cmd=`history -h 2 | head -n 1` && eval `thefuck ${fucked_cmd}`'\n" + + def _parse_alias(self, alias): + name, value = alias.split("\t", 1) + return name, value + + def _get_aliases(self): + proc = Popen('tcsh -ic alias', stdout=PIPE, stderr=DEVNULL, shell=True) + return dict( + self._parse_alias(alias) + for alias in proc.stdout.read().decode('utf-8').split('\n') + if alias and '\t' in alias) + + def _get_history_file_name(self): + return os.environ.get("HISTFILE", + os.path.expanduser('~/.history')) + + def _get_history_line(self, command_script): + return u'#+{}\n{}\n'.format(int(time()), command_script) + + shells = defaultdict(lambda: Generic(), { 'bash': Bash(), - 'zsh': Zsh()}) + 'zsh': Zsh(), + '-csh': Tcsh(), + 'tcsh': Tcsh()}) def _get_shell():