diff --git a/thefuck/shells/bash.py b/thefuck/shells/bash.py index fa7a2072..73093008 100644 --- a/thefuck/shells/bash.py +++ b/thefuck/shells/bash.py @@ -65,6 +65,9 @@ class Bash(Generic): return dict(self._parse_alias(alias) for alias in raw_aliases if alias and '=' in alias) + def can_edit(self): + return True + def _get_history_file_name(self): return os.environ.get("HISTFILE", os.path.expanduser('~/.bash_history')) diff --git a/thefuck/shells/generic.py b/thefuck/shells/generic.py index 2b44a745..2c81860b 100644 --- a/thefuck/shells/generic.py +++ b/thefuck/shells/generic.py @@ -125,8 +125,24 @@ class Generic(object): return False def edit_command(self, command): - """Return the shell editable command""" - return command + """Spawn default editor (or `vi` if not set) and edit command in a buffer""" + # Create a temporary file and write some default text + # mktemp somewhere + file_path = "The Fuck: Command Edit" + with open(file_path, "w") as file_handle: + file_handle.write(command) + + editor = os.getenv("EDITOR", "vi") + + os.system(u"{} '{}' >/dev/tty".format(editor, file_path)) + + data = None + with open(file_path, "r") as file_handle: + data = file_handle.read() + + os.remove(file_path) + + return data def get_builtin_commands(self): """Returns shells builtin commands.""" diff --git a/thefuck/shells/zsh.py b/thefuck/shells/zsh.py index e1fdf207..4a2da32b 100644 --- a/thefuck/shells/zsh.py +++ b/thefuck/shells/zsh.py @@ -64,6 +64,9 @@ class Zsh(Generic): value = value[1:-1] return name, value + def can_edit(self): + return True + @memoize def get_aliases(self): raw_aliases = os.environ.get('TF_SHELL_ALIASES', '').split('\n')