1
0
mirror of https://github.com/nvbn/thefuck.git synced 2025-02-21 20:38:54 +00:00

Fix the unzip rules and filenames with spaces

This commit is contained in:
mcarton 2015-10-28 15:13:33 +01:00
parent 0a6a3db65d
commit 280751b36e
2 changed files with 5 additions and 2 deletions

View File

@ -43,6 +43,8 @@ def test_side_effect(zip_error, script):
@pytest.mark.parametrize('script,fixed', [ @pytest.mark.parametrize('script,fixed', [
('unzip foo', 'unzip foo -d foo'), ('unzip foo', 'unzip foo -d foo'),
(R"unzip foo\ bar.zip", R"unzip foo\ bar.zip -d 'foo bar'"),
(R"unzip 'foo bar.zip'", R"unzip 'foo bar.zip' -d 'foo bar'"),
('unzip foo.zip', 'unzip foo.zip -d foo')]) ('unzip foo.zip', 'unzip foo.zip -d foo')])
def test_get_new_command(zip_error, script, fixed): def test_get_new_command(zip_error, script, fixed):
assert get_new_command(Command(script=script)) == fixed assert get_new_command(Command(script=script)) == fixed

View File

@ -1,6 +1,7 @@
import os import os
import zipfile import zipfile
from thefuck.utils import for_app from thefuck.utils import for_app
from thefuck.shells import quote
def _is_bad_zip(file): def _is_bad_zip(file):
@ -13,7 +14,7 @@ def _zip_file(command):
# unzip [-flags] file[.zip] [file(s) ...] [-x file(s) ...] # unzip [-flags] file[.zip] [file(s) ...] [-x file(s) ...]
# ^ ^ files to unzip from the archive # ^ ^ files to unzip from the archive
# archive to unzip # archive to unzip
for c in command.script.split()[1:]: for c in command.split_script[1:]:
if not c.startswith('-'): if not c.startswith('-'):
if c.endswith('.zip'): if c.endswith('.zip'):
return c return c
@ -28,7 +29,7 @@ def match(command):
def get_new_command(command): def get_new_command(command):
return '{} -d {}'.format(command.script, _zip_file(command)[:-4]) return '{} -d {}'.format(command.script, quote(_zip_file(command)[:-4]))
def side_effect(old_cmd, command): def side_effect(old_cmd, command):