Commit Graph

696 Commits

Author SHA1 Message Date
Alexander b02582d7b9 Add generic binary-help subcommand resolver
Consult a PATH-resolved binary's own --help (mtime-cached, LC_ALL=C,
2s timeout with kill) when a segment's first non-flag token is not a
listed subcommand, and splice the unique close match (ratio >= 0.8,
same first character). Ambiguity, sudo heads, flat-fallback artifact
heads, valid subcommands and nested levels all decline to the rest of
the chain; only <binary> --help is ever run.
2026-09-13 20:51:01 +02:00
Alexander a9e45d0186 Fix mistyped command heads in every pipe segment 2026-09-13 20:49:04 +02:00
Alexander 624938c284 Fix nushell history newline and multiline entries
put_to_history wrote entries without a trailing newline, so fixed
commands concatenated onto one line, and backslash-continued
multiline entries were read back as broken fragments. Join
continuations when reading and terminate entries with a newline,
matching the fish adapter convention.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-13 20:42:30 +02:00
Alexander a5c675cdea Add shell AST core with pos-splice round-trip
parse() turns a script into pipeline command segments via bashlex,
keeping byte-true char offsets for every word (quotes included as
typed, redirects and env assignments excluded from words), and
splice() rebuilds a corrected script from (start, end, text)
replacements applied right-to-left. When bashlex is missing or
rejects the script, a flat split(' ') segment keeps the old view.
2026-09-13 20:39:08 +02:00
Alexander f7d3b10288 Add bashlex dependency with import fallback
bashlex (GPL-3+) powers upcoming structural command analysis: parsing
pipelines into segments with word offsets so a typo anywhere in a
command can be fixed as confidently as one at the start. Because the
license is incompatible with distributing the MIT-licensed app, the
dependency is import-guarded: thefuck/shell_ast.py exposes
AST_AVAILABLE, which is False when bashlex is missing or under python 2
(the py2.7 CI requirements.txt deliberately omits it), so all new
behavior must gate on it and the fork stays personal-use only.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-13 20:31:51 +02:00
Alexander 78f4636a61 Fix order-dependent failure in TestGetValidHistoryWithoutCurrent
tests/entrypoints/test_fix_command.py sets TF_HISTORY, which makes the
real _get_raw_command call get_all_executables() and memoize the
machine's actual PATH. TestGetValidHistoryWithoutCurrent then mocks
thefuck.utils.Path to plant a fake café binary, but gets the stale
memoized list, so the café history line is filtered out and the four
parametrized cases fail whenever the entrypoint tests ran first.
Use the existing no_memoize fixture, like the neighboring
executables tests already do.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-13 20:01:27 +02:00
Alexander 1d3e4b7e8a Guess mistyped commands from $PATH before asking the user
When no learned correction matches, fuzzy-match the mistyped token
against executables from $PATH and shell aliases. A guess is auto-run
and recorded into the learned-corrections db only when it is
unambiguous: the token is not an existing executable, contains no
path separators or extensions, shares its first character with the
candidate, has similarity of at least 0.8, and exactly one candidate
survives. Asking the user stays the last resort.

Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent)

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-13 20:01:22 +02:00
Alexander 8d2f7d13c7 Add dynamic learning from accepted corrections
Record user-accepted corrections in a shelve-backed store and replay
them on future matching mistakes, bypassing rule evaluation entirely.

Two-level matching: exact full-command lookup, then word-level
reconstruction that generalises to different arguments (e.g. learning
'git psuh origin main' also fixes 'git psuh origin dev').
2026-04-15 12:06:41 +02:00
Pablo Santiago Blum de Aguiar 62e0767c50 #N/A: Fix a couple of issues after new flake8 release 2023-07-30 22:22:37 +02:00
Pablo Santiago Blum de Aguiar 617aaa1fd0 #1248: Skip a failing test when running on Windows 2023-07-10 14:40:45 +02:00
Pablo Santiago Blum de Aguiar cf0921be4a #1248: Check for multiple patterns in functional tests 2023-07-10 14:39:58 +02:00
Pablo Santiago Blum de Aguiar ef1ea4b4dd #1248: Check container status before test functions 2023-07-10 14:36:42 +02:00
Pablo Santiago Blum de Aguiar 2cadcca904 #1248: Reuse Docker images in functional tests 2023-07-10 14:34:46 +02:00
Hugo van Kemenade 5f562a185c Drop the dot https://twitter.com/pytestdotorg/status/753767547866972160 2023-07-09 13:03:27 +02:00
josepdaniel ceeaeab94b Add terraform 'no command' rule (#1317)
* Add terraform 'no command' rule

* Feedback from PR

Co-authored-by: Joseph Daniel <jdn@logpoint.com>
2022-09-25 21:37:47 +02:00
Miguel Guthridge f9768cf929 #1302: Add new git_clone_missing rule
* Add git clone missing rule

* Clean up tests and improve matching

* Make rules behave correctly?

* Improve tests and redo matcher

* Remove unnecessary tests

* Improvements as per code review

* Remove dead tests

* Improve match function for git clone missing

* Improve tests

* Fix more tests

* Fix failing test

* Add Macos's /bin/sh command output to match

* Add output for lines uncovered by tests

Co-authored-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
2022-07-03 13:22:36 +02:00
Peter ed40463105 #1299: Update output for brew_install and cleanup (#1316)
* fix: Update output for brew_install test: fixed

* chore: fixing flake8 styles

* feat: show more suggestions

* test: new functions added and multi suggestions

* refactor: rename to _get_suggestions
2022-07-02 15:06:00 +02:00
Peter f1b7d879bd #1290: Update output for brew_update_formula
* fix: brew_update_formula change output string

* fix: regex removed, test: backtick added

* Update tests/rules/test_brew_update_formula.py

* Update thefuck/rules/brew_update_formula.py

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
2022-06-28 18:28:38 +02:00
Nikos Kakonas 5198b34f24 #1282: Keep quotes in the script on no_command rule
Co-authored-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
2022-06-13 23:29:15 +02:00
0xphk 06cb50b1e3 #1308: Add updatedb (mlocate) pattern to sudo rule
* added updatedb(mlocate) to sudo rules

* Add test

Co-authored-by: phk <phk@terminal21.de>
Co-authored-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
2022-06-05 22:58:31 +02:00
Oļegs Čapligins 16eb823066 #1261: Add two more patterns to sudo rule (#1307)
* macos shutdown sudo fix

* Update tests/rules/test_sudo.py

* Update thefuck/rules/sudo.py

* Update tests/rules/test_sudo.py

* Update thefuck/rules/sudo.py

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
2022-05-29 21:40:31 +02:00
Tagada d8ddf5a2be #1279: Add pikaur AUR manager to Arch Linux's commands
* Add pikaur AUR manager to Arch Linux's commands

* Update README.md

* Update test_pacman_not_found.py

* Update pacman_not_found.py

* Update README.md

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
2022-03-27 22:06:40 +02:00
Marek Šuppa cf1beb6b89 fix: Add missing comma
* Add missing comma in a test
2022-01-30 22:34:38 +01:00
Joris Hartog 0f4a523dc4 Encapsulate force_command in _get_raw_command
Using the `force_command` argument will run into issues as the
`_get_raw_command` method simply returns the value of `force_command`
(which is a string) while it should actually return a list.

Fix #1240
2021-12-20 00:05:47 +01:00
Pablo Santiago Blum de Aguiar 51e4e87280 #1227: Make git_support support output-independent rules
Fix #1227
2021-08-17 15:41:54 +02:00
Pablo Santiago Blum de Aguiar 7b7c150bb7 #697: Encode expanded script on Python 2
Fix #697
2021-08-17 15:40:56 +02:00
Yotam Salmon 2a166a7dec #977: Add wrong_hyphen_before_subcommand rule
Co-authored-by: user <avi.salmon@intel.com>
Co-authored-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
2021-08-07 23:26:36 +02:00
Pablo Santiago Blum de Aguiar 7f3442747e #579: Ignore commands of len 1 in missing_space_before_subcommand 2021-08-01 22:24:29 +02:00
Pablo Santiago Blum de Aguiar dbc435c040 #618: Fix git_push_without_commits rule
The rule was in a non-working state. And the tests needed some bit of
simplification. Certain degree of repetition is oftentimes a good thing.
2021-07-29 22:11:34 +02:00
Pablo Santiago Blum de Aguiar 8e8c80c227 #1188: Remove only leading whitespace chars from script
Fix #1188
2021-07-29 21:43:24 +02:00
Pablo Santiago Blum de Aguiar c2df71caed #994: Replace decoding errors with the replacement marker
Fix #994

Reference: https://docs.python.org/3/library/codecs.html#error-handlers
2021-07-29 21:37:19 +02:00
Pablo Santiago Blum de Aguiar eb05b28c5b #N/A: Replace only exact words when expanding a Git alias 2021-07-29 21:36:15 +02:00
Pablo Santiago Blum de Aguiar 58ddd4338a #1215: Initiate settings before printing the alias 2021-07-21 13:09:19 +02:00
Pablo Santiago Blum de Aguiar 0668822abb #1215: Remove redirection to stderr with the ^ character
Redirection to standard error with the `^` character is disabled by
default since Fish Shell version 3.3[1].

Fix #1214

[1]: https://github.com/fish-shell/fish-shell/blob/master/CHANGELOG.rst#deprecations-and-removed-features-1
2021-07-18 15:10:48 +02:00
Pablo Santiago Blum de Aguiar 711feb4df5 #1184: Improve + fix git_main_master rule 2021-07-09 16:13:25 +02:00
Dave Storey 70a42b54ab #1184: Add new rule for main / master Git branches 2021-04-06 14:50:43 +01:00
Pablo Santiago Blum de Aguiar 11b70526f7 #1131: Improve git_commit_add rule
Add more capabilities to the rule, remove its priority and fix tests
2021-07-08 21:43:35 +02:00
Sergei Haller 55922e4dbe #1131: Add rule for Git commit with no added files 2020-09-08 11:47:05 +02:00
Pablo Santiago Blum de Aguiar 799f4127ca #942: Improve git_branch_0flag rule - with a new name 2021-07-13 15:36:11 +02:00
Ryan Delaney fe1942866b #1133: Match commands with path prefixes in @for_app decorations
* Resolve paths before checking app identity

Commands entered with a path do not match is_app. I encountered this
when working with a test for the rm_dir rule. This rule did not use the
@for_app decorator, but when I migrated it, the test for "./bin/hdfs.."
failed because 'hdfs' was recognized as a command, while "./bin/hdfs"
was not.

This commit addresses the false negative by resolving path names in the
command, via os.path.basename.

* Remove paths from for_app invocations in rules

I presume that the `./` in `./gradlew` was used here because thefuck
would not find an app match on just `gradlew`, and thus no fucks would
be given on the most common and idiomatic way of invoking gradlew.

After 8faf9b1, thefuck does not distinguish between commands with
paths and those without. Therefore, the tests for this rule are now
broken because thefuck strips paths from the _user_'s command, but not
from the for_app decoration.

This commit addresses that problem by changing the for_app decoration to
this rule.
2021-07-07 23:05:55 +02:00
Abraham Chan 6111523034 #1210: Add rule 'rails_migrations_pending'
* Add rule 'rails_migrations_pending'

* Update thefuck/rules/rails_migrations_pending.py

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>

* Add initial command to corrected command

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
2021-07-06 12:52:54 +02:00
ProfessorTom 24576b30b2 #942: Add new git_branch_0v_to_dash_v rule
* fix fuckup `branch 0v` by...

...deleting branch `0v` and running `git branch -v` as the user intended

* use quotes consistently

* provide new  solution implementation based on feedback on PR

* rename files to more accurately reflect their more generic contents

* update import statement to match new file name

* update command name in README.md

* separate out matching tests so the pattern is clear for those who add matches in the future
2021-07-01 23:07:38 +02:00
Divy Jain 54253027e3 #1123: Update composer_not_command rule (#1135)
Fix #1123
2021-06-30 23:10:06 +02:00
theslimshaney 9201ce79cf #1039: Remove all leading $ not just one 2021-06-30 22:46:20 +02:00
Abraham Chan 2f4adcf3cb #N/A: Fix yield_fixture deprecation (#1211) 2021-06-29 21:26:13 +02:00
Stuart Leeks 6da0bc557f Add excluded_search_path_prefixes setting (#1165)
Improves performance in WSL

Fix #1036

* Add excluded_search_path_prefixes setting

Allows filtering the paths used to search for commands
Can be useful to filter out /mnt/ in WSL for performance

* Add test for excluded_search_path_prefixes

* Apply suggestions from code review

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
2021-04-21 19:43:21 +02:00
Sid Shardanand 4c7479b3ad #N/A: Add cd_cs rule (#1167)
* 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 <scorphus@gmail.com>

* 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 <scorphus@gmail.com>

Co-authored-by: SID SHARDANAND <sshardan@deakin.edu.au>
Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
2021-03-22 20:55:45 +01:00
Pablo Santiago Blum de Aguiar c2cc95db88 #1117: Mock Popen in go_unknown_command test
Instead of ignoring it whenever `go` is unavailable
2021-02-22 22:54:45 +01:00
Georgios Kontosis 0e34c2343e #/N/A: Extend pyenv rule to include goenv, nodenv and rbenv (#1100)
Co-authored-by: Pablo Santiago Blum de Aguiar <scorphus@gmail.com>
Co-authored-by: Divy Jain <dkj@somaiya.edu>
2021-02-11 12:48:20 +01:00
Connor Martin fd90e69ceb #N/A: Add conda rule (#1138)
* add conda rules

* revert

* add conda

* add to readme and flake

* consistency with quotes and use for_app

* Update thefuck/rules/conda_mistype.py

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
2021-02-08 13:04:59 +01:00