diff --git a/thefuck/rules/git_commit_amend.py b/thefuck/rules/git_commit_amend.py index dd0ae6db..027bf7c7 100644 --- a/thefuck/rules/git_commit_amend.py +++ b/thefuck/rules/git_commit_amend.py @@ -3,7 +3,7 @@ from thefuck.specific.git import git_support @git_support def match(command): - return ('commit' in command.script_parts) + return ('commit' in command.script_parts and 0 == command.status_code) @git_support diff --git a/thefuck/shells/bash.py b/thefuck/shells/bash.py index fa7a2072..81a534d5 100644 --- a/thefuck/shells/bash.py +++ b/thefuck/shells/bash.py @@ -17,6 +17,7 @@ class Bash(Generic): function {name} () {{ TF_PYTHONIOENCODING=$PYTHONIOENCODING; export TF_SHELL=bash; + export TF_STATUS=$?; export TF_ALIAS={name}; export TF_SHELL_ALIASES=$(alias); export TF_HISTORY=$(fc -ln -10); diff --git a/thefuck/shells/fish.py b/thefuck/shells/fish.py index 51478192..19e94162 100644 --- a/thefuck/shells/fish.py +++ b/thefuck/shells/fish.py @@ -58,7 +58,7 @@ class Fish(Generic): # It is VERY important to have the variables declared WITHIN the alias return ('function {0} -d "Correct your previous console command"\n' ' set -l fucked_up_command $history[1]\n' - ' env TF_SHELL=fish TF_ALIAS={0} PYTHONIOENCODING=utf-8' + ' env TF_SHELL=fish TF_ALIAS={0} TF_STATUS=$status PYTHONIOENCODING=utf-8' ' thefuck $fucked_up_command {2} $argv | read -l unfucked_command\n' ' if [ "$unfucked_command" != "" ]\n' ' eval $unfucked_command\n{1}' diff --git a/thefuck/types.py b/thefuck/types.py index 8c5770f4..a0c7b762 100644 --- a/thefuck/types.py +++ b/thefuck/types.py @@ -23,6 +23,10 @@ class Command(object): self.script = script self.output = output + @property + def status_code(self): + return int(os.environ.get('TF_STATUS_CODE', 1)) + @property def stdout(self): logs.warn('`stdout` is deprecated, please use `output` instead') @@ -52,8 +56,8 @@ class Command(object): return False def __repr__(self): - return u'Command(script={}, output={})'.format( - self.script, self.output) + return u'Command(script={}, output={}, status_code={})'.format( + self.script, self.output, self.status_code) def update(self, **kwargs): """Returns new command with replaced fields.