From f5e8fe954e98284ca43291c1a1482f6fc5fb60e8 Mon Sep 17 00:00:00 2001 From: Pablo Santiago Blum de Aguiar Date: Thu, 15 Oct 2015 23:57:13 -0300 Subject: [PATCH] Improve the Fish Shell function making it faster It works now with no temp file involved, which makes it a lot faster. Also, `history --merge`, although only supported on Fish Shell 2.2+, merges the corrected entry back into history. Neat! Ref #89 --- thefuck/shells.py | 27 ++++++++++++++------------- 1 file changed, 14 insertions(+), 13 deletions(-) diff --git a/thefuck/shells.py b/thefuck/shells.py index 97d51a431..0bbe01177 100644 --- a/thefuck/shells.py +++ b/thefuck/shells.py @@ -126,19 +126,20 @@ def _get_overridden_aliases(self): return ['cd', 'grep', 'ls', 'man', 'open'] def app_alias(self, fuck): - return ("set TF_ALIAS {0}\n" - "function {0} -d 'Correct your previous console command'\n" - " set -l exit_code $status\n" - " set -l eval_script" - " (mktemp 2>/dev/null ; or mktemp -t 'thefuck')\n" - " set -l fucked_up_command $history[1]\n" - " thefuck $fucked_up_command > $eval_script\n" - " . $eval_script\n" - " /bin/rm $eval_script\n" - " if test $exit_code -ne 0\n" - " history --delete $fucked_up_command\n" - " end\n" - "end").format(fuck) + return ('function {0} -d "Correct your previous console command"\n' + ' set -l exit_code $status\n' + ' set -x TF_ALIAS {0}\n' + ' set -l fucked_up_command $history[1]\n' + ' thefuck $fucked_up_command | read -l unfucked_command\n' + ' if [ "$unfucked_command" != "" ]\n' + ' eval $unfucked_command\n' + ' if test $exit_code -ne 0\n' + ' history --delete $fucked_up_command\n' + ' history --merge ^ /dev/null\n' + ' return 0\n' + ' end\n' + ' end\n' + 'end').format(fuck) @memoize def get_aliases(self):