mirror of
https://github.com/nvbn/thefuck.git
synced 2025-02-20 20:09:07 +00:00
#534: Improve open
rule by creating the file or dir
This commit is contained in:
parent
a169575b0f
commit
b6b15bf0d1
@ -202,7 +202,7 @@ using the matched rule and runs it. Rules enabled by default are as follows:
|
||||
* `npm_wrong_command` – fixes wrong npm commands like `npm urgrade`;
|
||||
* `no_command` – fixes wrong console commands, for example `vom/vim`;
|
||||
* `no_such_file` – creates missing directories with `mv` and `cp` commands;
|
||||
* `open` – prepends `http` to address passed to `open`;
|
||||
* `open` – either prepends `http://` to address passed to `open` or create a new file or directory and passes it to `open`;
|
||||
* `pip_unknown_command` – fixes wrong `pip` commands, for example `pip instatl/pip install`;
|
||||
* `python_command` – prepends `python` when you trying to run not executable/without `./` python script;
|
||||
* `python_execute` – appends missing `.py` when executing Python files;
|
||||
|
@ -32,15 +32,18 @@ def test_not_is_arg_url(script):
|
||||
'open foo.com',
|
||||
'xdg-open foo.com',
|
||||
'gnome-open foo.com',
|
||||
'kde-open foo.com'])
|
||||
'kde-open foo.com',
|
||||
'open nonest'])
|
||||
def test_match(script, stderr):
|
||||
assert match(Command(script, stderr=stderr))
|
||||
|
||||
|
||||
@pytest.mark.parametrize('script, new_command', [
|
||||
('open foo.io', 'open http://foo.io'),
|
||||
('xdg-open foo.io', 'xdg-open http://foo.io'),
|
||||
('gnome-open foo.io', 'gnome-open http://foo.io'),
|
||||
('kde-open foo.io', 'kde-open http://foo.io')])
|
||||
('open foo.io', ['open http://foo.io']),
|
||||
('xdg-open foo.io', ['xdg-open http://foo.io']),
|
||||
('gnome-open foo.io', ['gnome-open http://foo.io']),
|
||||
('kde-open foo.io', ['kde-open http://foo.io']),
|
||||
('open nonest', ['touch nonest && open nonest',
|
||||
'mkdir nonest && open nonest'])])
|
||||
def test_get_new_command(script, new_command, stderr):
|
||||
assert get_new_command(Command(script, stderr=stderr)) == new_command
|
||||
|
@ -24,8 +24,17 @@ def is_arg_url(command):
|
||||
|
||||
@for_app('open', 'xdg-open', 'gnome-open', 'kde-open')
|
||||
def match(command):
|
||||
return is_arg_url(command)
|
||||
return (is_arg_url(command) or
|
||||
command.stderr.strip().startswith('The file ') and
|
||||
command.stderr.strip().endswith(' does not exist.'))
|
||||
|
||||
|
||||
@eager
|
||||
def get_new_command(command):
|
||||
return command.script.replace('open ', 'open http://')
|
||||
stderr = command.stderr.strip()
|
||||
if is_arg_url(command):
|
||||
yield command.script.replace('open ', 'open http://')
|
||||
elif stderr.startswith('The file ') and stderr.endswith(' does not exist.'):
|
||||
arg = command.script.split(' ', 1)[1]
|
||||
for option in ['touch', 'mkdir']:
|
||||
yield shell.and_(u'{} {}'.format(option, arg), command.script)
|
||||
|
Loading…
x
Reference in New Issue
Block a user