From 756044e08716f371710129f852d02eeb02fa302a Mon Sep 17 00:00:00 2001 From: Joseph Frazier <1212jtraceur@gmail.com> Date: Mon, 10 Oct 2016 14:55:45 -0400 Subject: [PATCH] Suggest `ls -A` when `ls` has no output --- README.md | 1 + tests/rules/test_ls_all.py | 12 ++++++++++++ thefuck/rules/ls_all.py | 10 ++++++++++ 3 files changed, 23 insertions(+) create mode 100644 tests/rules/test_ls_all.py create mode 100644 thefuck/rules/ls_all.py diff --git a/README.md b/README.md index f2676077..89dd7307 100644 --- a/README.md +++ b/README.md @@ -202,6 +202,7 @@ using the matched rule and runs it. Rules enabled by default are as follows: * `lein_not_task` – fixes wrong `lein` tasks like `lein rpl`; * `ln_no_hard_link` – catches hard link creation on directories, suggest symbolic link; * `ln_s_order` – fixes `ln -s` arguments order; +* `ls_all` – adds `-A` to `ls` when output is empty; * `ls_lah` – adds `-lah` to `ls`; * `man` – changes manual section; * `man_no_space` – fixes man commands without spaces, for example `mandiff`; diff --git a/tests/rules/test_ls_all.py b/tests/rules/test_ls_all.py new file mode 100644 index 00000000..475f4e9c --- /dev/null +++ b/tests/rules/test_ls_all.py @@ -0,0 +1,12 @@ +from thefuck.rules.ls_all import match, get_new_command +from tests.utils import Command + + +def test_match(): + assert match(Command(script='ls')) + assert not match(Command(script='ls', stdout='file.py\n')) + + +def test_get_new_command(): + assert get_new_command(Command(script='ls empty_dir')) == 'ls -A empty_dir' + assert get_new_command(Command(script='ls')) == 'ls -A' diff --git a/thefuck/rules/ls_all.py b/thefuck/rules/ls_all.py new file mode 100644 index 00000000..e898d17d --- /dev/null +++ b/thefuck/rules/ls_all.py @@ -0,0 +1,10 @@ +from thefuck.utils import for_app + + +@for_app('ls') +def match(command): + return command.stdout.strip() == '' + + +def get_new_command(command): + return ' '.join(['ls', '-A'] + command.script_parts[1:])