mirror of
https://github.com/nvbn/thefuck.git
synced 2025-03-14 06:38:32 +00:00
#N/A: Edit commands using the default editor
This PR to implement a feature that would allow you to edit the suggested command in the editor that is set in $EDITOR
This commit is contained in:
parent
15372fcb90
commit
f96406cd71
@ -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'))
|
||||
|
@ -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."""
|
||||
|
@ -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')
|
||||
|
Loading…
x
Reference in New Issue
Block a user