Commit Graph

1664 Commits

Author SHA1 Message Date
Alexander 8d2f2fa11c Accept single-edit typos in correction gates
difflib's SequenceMatcher underrates adjacent transpositions, so the
flagship examples (gti->git 0.667, greo->grep 0.75, psuh->push 0.75)
fell below the 0.8 ratio gates and were declined. Per the plan
amendment, the token and candidate gates in the history resolver,
guess_from_path and the help resolver additionally accept a
first-char-equal single edit (one substitution, insertion, deletion
or adjacent transposition; new thefuck/typo.py), with the ratio
cutoffs, the exact-one-candidate rule and the 0.79 boundary (edit
distance >= 2) unchanged.
2026-09-13 21:00:20 +02:00
Alexander 572d301bfe Run resolvers before rules with recording
Before consulting rules, fix_command now walks the resolver chain in
the fixed order learned-db -> history -> /nix/store/zc6fy62c341aibk36p4ywff7rf9wn4wx-ripgrep-15.2.0/bin:/run/wrappers/bin:/home/fujin/.nix-profile/bin:/nix/profile/bin:/home/fujin/.local/state/nix/profile/bin:/etc/profiles/per-user/fujin/bin:/nix/var/nix/profiles/default/bin:/run/current-system/sw/bin:/home/fujin/.local/share/JetBrains/Toolbox/scripts:/nix/store/rm982p6i9ry7rwq5jn638kdpv0a2331f-binutils-wrapper-2.46/bin:/nix/store/xabfaf6i4ry9r7jdg8rn7z56j34fjfgm-hyprland-qtutils-0.1.5/bin:/nix/store/mjgd7lbvp8rli365likrg9m4a5mmi5w4-pciutils-3.15.0/bin:/nix/store/paknc34adnxagnadmx2pg4c90hss8amv-pkgconf-wrapper-2.5.1/bin guess -> binary help:
history similarity runs before the disk-wide program-name guess per
the user requirement, and the binary's own --help is the last
automatic option before asking. Whichever resolver yields a script
is logged with its source, recorded via record(), and run through
the existing priority-0 CorrectedCommand block, so every automatic
fix is remembered; declines and aborts still record nothing and the
ask path is unchanged.
2026-09-13 20:59:16 +02:00
Alexander d12f4326ab Add history-similarity resolver with correction-only gates
get_history_correction aligns a failed script with near-identical
history commands segment by segment (shell_ast words with byte-true
offsets) and splices the corrected tokens back in place. It only
returns a fix when exactly one candidate matches the structure with
at most two diverged tokens, each at least 80 percent similar;
looser or ambiguous matches decline so the asking history rule
stays in charge of them.

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

Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
2026-09-13 20:51:16 +02:00
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 7cac5ac870 Fix nushell 2026-04-15 12:28:30 +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
Alexander c1145c95d9 Add Nushell shell support and Nix flake packaging
Tests / test (macos-latest, 3.10) (push) Has been cancelled
Tests / test (macos-latest, 3.11) (push) Has been cancelled
Tests / test (macos-latest, 3.12-dev) (push) Has been cancelled
Tests / test (macos-latest, 3.7) (push) Has been cancelled
Tests / test (macos-latest, 3.8) (push) Has been cancelled
Tests / test (macos-latest, 3.9) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.10) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.11) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.12-dev) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.7) (push) Has been cancelled
Tests / test (windows-latest, 3.10) (push) Has been cancelled
Tests / test (windows-latest, 3.11) (push) Has been cancelled
Tests / test (windows-latest, 3.12-dev) (push) Has been cancelled
Tests / test (windows-latest, 3.7) (push) Has been cancelled
Tests / test (windows-latest, 3.8) (push) Has been cancelled
Tests / test (windows-latest, 3.9) (push) Has been cancelled
Tests / test-deprecated (2.7) (push) Has been cancelled
Tests / test-deprecated (3.6) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.8) (push) Has been cancelled
Tests / test (ubuntu-latest, 3.9) (push) Has been cancelled
Implement Nushell shell adapter (from nvbn/thefuck#1442) with alias
resolution, history management, and subprocess-based command execution.

Add uv2nix-based Nix flake for reproducible builds with Python 3.11,
pinned setuptools<71 for pkg_resources compatibility, and dev shell
with uv for local development.
2026-04-06 14:53:36 +02:00
Alan Gabbianelli c7e7e1d884 Fix typos in README.md 2024-01-25 20:52:35 +01: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
Gerardo Grignoli 3cd187a3bb #1329: Add support for Windows CMD and easier setup for Powershell
* feat: Added nicer support for Windows CMD & Powershell

* Fix  typo

* Fix CMD console color after thefuck Ctrl-C

* Update setup.py

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

* Update setup.py

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

* Addressed PR comments

* fix spacing and newline issues

---------

Co-authored-by: Pablo Aguiar <scorphus@gmail.com>
2023-07-10 15:09:27 +02:00
Pablo Santiago Blum de Aguiar 0420442e77 #1248: Use imp only when importlib.util not available
The imp module is deprecated and will be removed in Python 12.
2023-07-10 14:43:45 +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
Pablo Santiago Blum de Aguiar d81929f294 #1248: Move deprecated Python versions to separate workflow job 2023-07-10 14:22:23 +02:00
Pablo Santiago Blum de Aguiar b03e0913d3 #1248: Run workflows on push and pull_request 2023-07-10 14:20:40 +02:00
Hugo van Kemenade b79e104df8 Add support for Python 3.11 2023-07-09 13:03:32 +02:00
Hugo van Kemenade 3f71959b1b Add python_requires to help pip 2023-07-09 13:03:32 +02:00
Hugo van Kemenade 51b82c5377 Update min Python 3 version required in README 2023-07-09 13:03:32 +02:00
Hugo van Kemenade 5f562a185c Drop the dot https://twitter.com/pytestdotorg/status/753767547866972160 2023-07-09 13:03:27 +02:00
Hugo van Kemenade 1a242c7daa Test on Python 3.10 final 2023-07-09 13:01:48 +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
Pablo Aguiar 77627a3140 #N/A: Define branches in workflow (#1328) 2022-09-07 21:33:40 +02:00
Pablo Santiago Blum de Aguiar 03a032295d #N/A: Change workflow triggers 2022-08-31 22:36:44 +02:00
Dan 56c16b737f Added Arch based installation (#1319)
Co-authored-by: Dan <dan@arch.localdomain>
2022-08-31 20:42:41 +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
Pablo Santiago Blum de Aguiar 1a1b5200a9 #N/A: Lock pyte<=0.8.0 for Python 2 2022-06-08 23:39:19 +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
Anupam Patil 925e562d96 Updated license date to 2022 2022-01-20 22:01:21 +01:00
Pablo Santiago Blum de Aguiar 841e3f9e13 Bump to 3.32 2022-01-02 22:45:09 +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
Benjamin Rood c719712b62 Use --user with pip, not sudo pip
`sudo` with `pip` is [considered unsafe](https://stackoverflow.com/a/22517157/2469559).

Instead, run such commands with the `--user` argument to get the same result _safely._
2021-09-05 16:58:35 +02: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
Lars Alexander Blumberg 8fa10b1049 #868: Fix outdated link to homebrew for Linux (#1226) 2021-08-07 13:12:12 +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