From 4c7479b3adcf8715a93d0c48e1ece83a35cda50d Mon Sep 17 00:00:00 2001 From: Sid Shardanand <51441497+s1ddly@users.noreply.github.com> Date: Tue, 23 Mar 2021 06:55:45 +1100 Subject: [PATCH] #N/A: Add `cd_cs` rule (#1167) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * adding in files for the cd-cs feature * Updated thefuck/rules/cd_cs.py comments to be more verbose Thanks Scorphus! Co-authored-by: Pablo Aguiar * Updating the rules file to exclude the \xe2 character This character(–) has lead to the commit failing some of the tests. I am removing it from the code and we should see the tests pass now. * Setting the encoding in thefuck/rules/cd_cs.py Co-authored-by: Pablo Aguiar Co-authored-by: SID SHARDANAND Co-authored-by: Pablo Aguiar --- README.md | 1 + tests/rules/test_cd_cs.py | 11 +++++++++++ thefuck/rules/cd_cs.py | 21 +++++++++++++++++++++ 3 files changed, 33 insertions(+) create mode 100644 tests/rules/test_cd_cs.py create mode 100644 thefuck/rules/cd_cs.py diff --git a/README.md b/README.md index 26cdc700..46a1d24b 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,7 @@ following rules are enabled by default: * `cargo_no_command` – fixes wrongs commands like `cargo buid`; * `cat_dir` – replaces `cat` with `ls` when you try to `cat` a directory; * `cd_correction` – spellchecks and correct failed cd commands; +* `cd_cs` – changes `cs` to `cd`; * `cd_mkdir` – creates directories before cd'ing into them; * `cd_parent` – changes `cd..` to `cd ..`; * `chmod_x` – add execution bit; diff --git a/tests/rules/test_cd_cs.py b/tests/rules/test_cd_cs.py new file mode 100644 index 00000000..204c651d --- /dev/null +++ b/tests/rules/test_cd_cs.py @@ -0,0 +1,11 @@ +from thefuck.rules.cd_cs import match, get_new_command +from thefuck.types import Command + + +def test_match(): + assert match(Command('cs', 'cs: command not found')) + assert match(Command('cs /etc/', 'cs: command not found')) + + +def test_get_new_command(): + assert get_new_command(Command('cs /etc/', 'cs: command not found')) == 'cd /etc/' diff --git a/thefuck/rules/cd_cs.py b/thefuck/rules/cd_cs.py new file mode 100644 index 00000000..f95415d9 --- /dev/null +++ b/thefuck/rules/cd_cs.py @@ -0,0 +1,21 @@ +# -*- encoding: utf-8 -*- + +# Redirects cs to cd when there is a typo +# Due to the proximity of the keys - d and s - this seems like a common typo +# ~ > cs /etc/ +# cs: command not found +# ~ > fuck +# cd /etc/ [enter/↑/↓/ctrl+c] +# /etc > + + +def match(command): + if command.script_parts[0] == 'cs': + return True + + +def get_new_command(command): + return 'cd' + ''.join(command.script[2:]) + + +priority = 900