repo
stringlengths
7
90
file_url
stringlengths
81
315
file_path
stringlengths
4
228
content
stringlengths
0
32.8k
language
stringclasses
1 value
license
stringclasses
7 values
commit_sha
stringlengths
40
40
retrieved_at
stringdate
2026-01-04 14:38:15
2026-01-05 02:33:18
truncated
bool
2 classes
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/brew_uninstall.py
thefuck/rules/brew_uninstall.py
from thefuck.utils import for_app @for_app('brew', at_least=2) def match(command): return (command.script_parts[1] in ['uninstall', 'rm', 'remove'] and "brew uninstall --force" in command.output) def get_new_command(command): command_parts = command.script_parts[:] command_parts[1] = 'uninstall' command_parts.insert(2, '--force') return ' '.join(command_parts)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/whois.py
thefuck/rules/whois.py
# -*- encoding: utf-8 -*- from six.moves.urllib.parse import urlparse from thefuck.utils import for_app @for_app('whois', at_least=1) def match(command): """ What the `whois` command returns depends on the 'Whois server' it contacted and is not consistent through different servers. But there can be only two types of errors I can think of with `whois`: - `whois https://en.wikipedia.org/` → `whois en.wikipedia.org`; - `whois en.wikipedia.org` → `whois wikipedia.org`. So we match any `whois` command and then: - if there is a slash: keep only the FQDN; - if there is no slash but there is a point: removes the left-most subdomain. We cannot either remove all subdomains because we cannot know which part is the subdomains and which is the domain, consider: - www.google.fr → subdomain: www, domain: 'google.fr'; - google.co.uk → subdomain: None, domain; 'google.co.uk'. """ return True def get_new_command(command): url = command.script_parts[1] if '/' in command.script: return 'whois ' + urlparse(url).netloc elif '.' in command.script: path = urlparse(url).path.split('.') return ['whois ' + '.'.join(path[n:]) for n in range(1, len(path))]
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/wrong_hyphen_before_subcommand.py
thefuck/rules/wrong_hyphen_before_subcommand.py
from thefuck.utils import get_all_executables from thefuck.specific.sudo import sudo_support @sudo_support def match(command): first_part = command.script_parts[0] if "-" not in first_part or first_part in get_all_executables(): return False cmd, _ = first_part.split("-", 1) return cmd in get_all_executables() @sudo_support def get_new_command(command): return command.script.replace("-", " ", 1) priority = 4500 requires_output = False
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_diff_no_index.py
thefuck/rules/git_diff_no_index.py
from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): files = [arg for arg in command.script_parts[2:] if not arg.startswith('-')] return ('diff' in command.script and '--no-index' not in command.script and len(files) == 2) @git_support def get_new_command(command): return replace_argument(command.script, 'diff', 'diff --no-index')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/sl_ls.py
thefuck/rules/sl_ls.py
""" This happens way too often When typing really fast cause I'm a 1337 H4X0R, I often fuck up 'ls' and type 'sl'. No more! """ def match(command): return command.script == 'sl' def get_new_command(command): return 'ls'
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/history.py
thefuck/rules/history.py
from thefuck.utils import get_close_matches, get_closest, \ get_valid_history_without_current def match(command): return len(get_close_matches(command.script, get_valid_history_without_current(command))) def get_new_command(command): return get_closest(command.script, get_valid_history_without_current(command)) priority = 9999
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/brew_cask_dependency.py
thefuck/rules/brew_cask_dependency.py
from thefuck.utils import for_app, eager from thefuck.shells import shell from thefuck.specific.brew import brew_available @for_app('brew') def match(command): return (u'install' in command.script_parts and u'brew cask install' in command.output) @eager def _get_cask_install_lines(output): for line in output.split('\n'): line = line.strip() if line.startswith('brew cask install'): yield line def _get_script_for_brew_cask(output): cask_install_lines = _get_cask_install_lines(output) if len(cask_install_lines) > 1: return shell.and_(*cask_install_lines) else: return cask_install_lines[0] def get_new_command(command): brew_cask_script = _get_script_for_brew_cask(command.output) return shell.and_(brew_cask_script, command.script) enabled_by_default = brew_available
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/gradle_no_task.py
thefuck/rules/gradle_no_task.py
import re from subprocess import Popen, PIPE from thefuck.utils import for_app, eager, replace_command regex = re.compile(r"Task '(.*)' (is ambiguous|not found)") @for_app('gradle', 'gradlew') def match(command): return regex.findall(command.output) @eager def _get_all_tasks(gradle): proc = Popen([gradle, 'tasks'], stdout=PIPE) should_yield = False for line in proc.stdout.readlines(): line = line.decode().strip() if line.startswith('----'): should_yield = True continue if not line.strip(): should_yield = False continue if should_yield and not line.startswith('All tasks runnable from root project'): yield line.split(' ')[0] def get_new_command(command): wrong_task = regex.findall(command.output)[0][0] all_tasks = _get_all_tasks(command.script_parts[0]) return replace_command(command, wrong_task, all_tasks)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/adb_unknown_command.py
thefuck/rules/adb_unknown_command.py
from thefuck.utils import is_app, get_closest, replace_argument _ADB_COMMANDS = ( 'backup', 'bugreport', 'connect', 'devices', 'disable-verity', 'disconnect', 'enable-verity', 'emu', 'forward', 'get-devpath', 'get-serialno', 'get-state', 'install', 'install-multiple', 'jdwp', 'keygen', 'kill-server', 'logcat', 'pull', 'push', 'reboot', 'reconnect', 'restore', 'reverse', 'root', 'run-as', 'shell', 'sideload', 'start-server', 'sync', 'tcpip', 'uninstall', 'unroot', 'usb', 'wait-for', ) def match(command): return (is_app(command, 'adb') and command.output.startswith('Android Debug Bridge version')) def get_new_command(command): for idx, arg in enumerate(command.script_parts[1:]): # allowed params to ADB are a/d/e/s/H/P/L where s, H, P and L take additional args # for example 'adb -s 111 logcat' or 'adb -e logcat' if not arg[0] == '-' and not command.script_parts[idx] in ('-s', '-H', '-P', '-L'): adb_cmd = get_closest(arg, _ADB_COMMANDS) return replace_argument(command.script, arg, adb_cmd)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/pacman_invalid_option.py
thefuck/rules/pacman_invalid_option.py
from thefuck.specific.archlinux import archlinux_env from thefuck.specific.sudo import sudo_support from thefuck.utils import for_app import re @sudo_support @for_app("pacman") def match(command): return command.output.startswith("error: invalid option '-") and any( " -{}".format(option) in command.script for option in "surqfdvt" ) def get_new_command(command): option = re.findall(r" -[dfqrstuv]", command.script)[0] return re.sub(option, option.upper(), command.script) enabled_by_default = archlinux_env()
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/sudo_command_from_user_path.py
thefuck/rules/sudo_command_from_user_path.py
import re from thefuck.utils import for_app, which, replace_argument def _get_command_name(command): found = re.findall(r'sudo: (.*): command not found', command.output) if found: return found[0] @for_app('sudo') def match(command): if 'command not found' in command.output: command_name = _get_command_name(command) return which(command_name) def get_new_command(command): command_name = _get_command_name(command) return replace_argument(command.script, command_name, u'env "PATH=$PATH" {}'.format(command_name))
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_branch_delete_checked_out.py
thefuck/rules/git_branch_delete_checked_out.py
from thefuck.shells import shell from thefuck.specific.git import git_support from thefuck.utils import replace_argument @git_support def match(command): return ( ("branch -d" in command.script or "branch -D" in command.script) and "error: Cannot delete branch '" in command.output and "' checked out at '" in command.output ) @git_support def get_new_command(command): return shell.and_("git checkout master", "{}").format( replace_argument(command.script, "-d", "-D") )
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/grep_arguments_order.py
thefuck/rules/grep_arguments_order.py
import os from thefuck.utils import for_app def _get_actual_file(parts): for part in parts[1:]: if os.path.isfile(part) or os.path.isdir(part): return part @for_app('grep', 'egrep') def match(command): return ': No such file or directory' in command.output \ and _get_actual_file(command.script_parts) def get_new_command(command): actual_file = _get_actual_file(command.script_parts) parts = command.script_parts[::] # Moves file to the end of the script: parts.remove(actual_file) parts.append(actual_file) return ' '.join(parts)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/npm_missing_script.py
thefuck/rules/npm_missing_script.py
import re from thefuck.utils import for_app, replace_command from thefuck.specific.npm import get_scripts, npm_available enabled_by_default = npm_available @for_app('npm') def match(command): return (any(part.startswith('ru') for part in command.script_parts) and 'npm ERR! missing script: ' in command.output) def get_new_command(command): misspelled_script = re.findall( r'.*missing script: (.*)\n', command.output)[0] return replace_command(command, misspelled_script, get_scripts())
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/heroku_not_command.py
thefuck/rules/heroku_not_command.py
import re from thefuck.utils import for_app @for_app('heroku') def match(command): return 'Run heroku _ to run' in command.output def get_new_command(command): return re.findall('Run heroku _ to run ([^.]*)', command.output)[0]
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_remote_delete.py
thefuck/rules/git_remote_delete.py
import re from thefuck.specific.git import git_support @git_support def match(command): return "remote delete" in command.script @git_support def get_new_command(command): return re.sub(r"delete", "remove", command.script, 1)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_branch_delete.py
thefuck/rules/git_branch_delete.py
from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): return ('branch -d' in command.script and 'If you are sure you want to delete it' in command.output) @git_support def get_new_command(command): return replace_argument(command.script, '-d', '-D')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_commit_amend.py
thefuck/rules/git_commit_amend.py
from thefuck.specific.git import git_support @git_support def match(command): return ('commit' in command.script_parts) @git_support def get_new_command(command): return 'git commit --amend'
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/switch_lang.py
thefuck/rules/switch_lang.py
# -*- encoding: utf-8 -*- from thefuck.utils import memoize, get_alias target_layout = '''qwertyuiop[]asdfghjkl;'zxcvbnm,./QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''' # any new keyboard layout must be appended greek = u''';ςερτυθιοπ[]ασδφγηξκλ΄ζχψωβνμ,./:΅ΕΡΤΥΘΙΟΠ{}ΑΣΔΦΓΗΞΚΛ¨"ΖΧΨΩΒΝΜ<>?''' korean = u'''ㅂㅈㄷㄱㅅㅛㅕㅑㅐㅔ[]ㅁㄴㅇㄹㅎㅗㅓㅏㅣ;'ㅋㅌㅊㅍㅠㅜㅡ,./ㅃㅉㄸㄲㅆㅛㅕㅑㅒㅖ{}ㅁㄴㅇㄹㅎㅗㅓㅏㅣ:"ㅋㅌㅊㅍㅠㅜㅡ<>?''' source_layouts = [u'''йцукенгшщзхъфывапролджэячсмитьбю.ЙЦУКЕНГШЩЗХЪФЫВАПРОЛДЖЭЯЧСМИТЬБЮ,''', u'''йцукенгшщзхїфівапролджєячсмитьбю.ЙЦУКЕНГШЩЗХЇФІВАПРОЛДЖЄЯЧСМИТЬБЮ,''', u'''ضصثقفغعهخحجچشسیبلاتنمکگظطزرذدپو./ًٌٍَُِّْ][}{ؤئيإأآة»«:؛كٓژٰ‌ٔء><؟''', u'''/'קראטוןםפ][שדגכעיחלךף,זסבהנמצתץ.QWERTYUIOP{}ASDFGHJKL:"ZXCVBNM<>?''', greek, korean] source_to_target = { greek: {u';': "q", u'ς': "w", u'ε': "e", u'ρ': "r", u'τ': "t", u'υ': "y", u'θ': "u", u'ι': "i", u'ο': "o", u'π': "p", u'[': "[", u']': "]", u'α': "a", u'σ': "s", u'δ': "d", u'φ': "f", u'γ': "g", u'η': "h", u'ξ': "j", u'κ': "k", u'λ': "l", u'΄': "'", u'ζ': "z", u'χ': "x", u'ψ': "c", u'ω': "v", u'β': "b", u'ν': "n", u'μ': "m", u',': ",", u'.': ".", u'/': "/", u':': "Q", u'΅': "W", u'Ε': "E", u'Ρ': "R", u'Τ': "T", u'Υ': "Y", u'Θ': "U", u'Ι': "I", u'Ο': "O", u'Π': "P", u'{': "{", u'}': "}", u'Α': "A", u'Σ': "S", u'Δ': "D", u'Φ': "F", u'Γ': "G", u'Η': "H", u'Ξ': "J", u'Κ': "K", u'Λ': "L", u'¨': ":", u'"': '"', u'Ζ': "Z", u'Χ': "X", u'Ψ': "C", u'Ω': "V", u'Β': "B", u'Ν': "N", u'Μ': "M", u'<': "<", u'>': ">", u'?': "?", u'ά': "a", u'έ': "e", u'ύ': "y", u'ί': "i", u'ό': "o", u'ή': 'h', u'ώ': u"v", u'Ά': "A", u'Έ': "E", u'Ύ': "Y", u'Ί': "I", u'Ό': "O", u'Ή': "H", u'Ώ': "V"}, } '''Lists used for decomposing korean letters.''' HEAD_LIST = [u'ㄱ', u'ㄲ', u'ㄴ', u'ㄷ', u'ㄸ', u'ㄹ', u'ㅁ', u'ㅂ', u'ㅃ', u'ㅅ', u'ㅆ', u'ㅇ', u'ㅈ', u'ㅉ', u'ㅊ', u'ㅋ', u'ㅌ', u'ㅍ', u'ㅎ'] BODY_LIST = [u'ㅏ', u'ㅐ', u'ㅑ', u'ㅒ', u'ㅓ', u'ㅔ', u'ㅕ', u'ㅖ', u'ㅗ', u'ㅘ', u'ㅙ', u'ㅚ', u'ㅛ', u'ㅜ', u'ㅝ', u'ㅞ', u'ㅟ', u'ㅠ', u'ㅡ', u'ㅢ', u'ㅣ'] TAIL_LIST = [u' ', u'ㄱ', u'ㄲ', u'ㄳ', u'ㄴ', u'ㄵ', u'ㄶ', u'ㄷ', u'ㄹ', u'ㄺ', u'ㄻ', u'ㄼ', u'ㄽ', u'ㄾ', u'ㄿ', u'ㅀ', u'ㅁ', u'ㅂ', u'ㅄ', u'ㅅ', u'ㅆ', u'ㅇ', u'ㅈ', u'ㅊ', u'ㅋ', u'ㅌ', u'ㅍ', u'ㅎ'] DOUBLE_LIST = [u'ㅘ', u'ㅙ', u'ㅚ', u'ㅝ', u'ㅞ', u'ㅟ', u'ㅢ', u'ㄳ', u'ㄵ', u'ㄶ', u'ㄺ', u'ㄻ', u'ㄼ', u'ㄽ', u'ㄾ', u'ㅀ', u'ㅄ'] DOUBLE_MOD_LIST = [u'ㅗㅏ', u'ㅗㅐ', u'ㅗㅣ', u'ㅜㅓ', u'ㅜㅔ', u'ㅜㅣ', u'ㅡㅣ', u'ㄱㅅ', u'ㄴㅈ', u'ㄴㅎ', u'ㄹㄱ', u'ㄹㅁ', u'ㄹㅂ', u'ㄹㅅ', u'ㄹㅌ', u'ㄹㅎ', u'ㅂㅅ'] @memoize def _get_matched_layout(command): # don't use command.split_script here because a layout mismatch will likely # result in a non-splitable script as per shlex cmd = command.script.split(' ') for source_layout in source_layouts: is_all_match = True for cmd_part in cmd: if not all([ch in source_layout or ch in '-_' for ch in cmd_part]): is_all_match = False break if is_all_match: return source_layout def _switch(ch, layout): if ch in layout: return target_layout[layout.index(ch)] return ch def _switch_command(command, layout): # Layouts with different amount of characters than English if layout in source_to_target: return ''.join(source_to_target[layout].get(ch, ch) for ch in command.script) return ''.join(_switch(ch, layout) for ch in command.script) def _decompose_korean(command): def _change_double(ch): if ch in DOUBLE_LIST: return DOUBLE_MOD_LIST[DOUBLE_LIST.index(ch)] return ch hg_str = u'' for ch in command.script: if u'가' <= ch <= u'힣': ord_ch = ord(ch) - ord(u'가') hd = ord_ch // 588 bd = (ord_ch - 588 * hd) // 28 tl = ord_ch - 588 * hd - 28 * bd for ch in [HEAD_LIST[hd], BODY_LIST[bd], TAIL_LIST[tl]]: if ch != ' ': hg_str += _change_double(ch) else: hg_str += _change_double(ch) return hg_str def match(command): if 'not found' not in command.output: return False if any(u'ㄱ' <= ch <= u'ㅎ' or u'ㅏ' <= ch <= u'ㅣ' or u'가' <= ch <= u'힣' for ch in command.script): return True matched_layout = _get_matched_layout(command) return (matched_layout and _switch_command(command, matched_layout) != get_alias()) def get_new_command(command): if any(u'ㄱ' <= ch <= u'ㅎ' or u'ㅏ' <= ch <= u'ㅣ' or u'가' <= ch <= u'힣' for ch in command.script): command.script = _decompose_korean(command) matched_layout = _get_matched_layout(command) return _switch_command(command, matched_layout)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/gem_unknown_command.py
thefuck/rules/gem_unknown_command.py
import re import subprocess from thefuck.utils import for_app, eager, replace_command, cache, which @for_app('gem') def match(command): return ('ERROR: While executing gem ... (Gem::CommandLineError)' in command.output and 'Unknown command' in command.output) def _get_unknown_command(command): return re.findall(r'Unknown command (.*)$', command.output)[0] @eager def _get_all_commands(): proc = subprocess.Popen(['gem', 'help', 'commands'], stdout=subprocess.PIPE) for line in proc.stdout.readlines(): line = line.decode() if line.startswith(' '): yield line.strip().split(' ')[0] if which('gem'): _get_all_commands = cache(which('gem'))(_get_all_commands) def get_new_command(command): unknown_command = _get_unknown_command(command) all_commands = _get_all_commands() return replace_command(command, unknown_command, all_commands)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/pip_unknown_command.py
thefuck/rules/pip_unknown_command.py
import re from thefuck.utils import replace_argument, for_app from thefuck.specific.sudo import sudo_support @sudo_support @for_app('pip', 'pip2', 'pip3') def match(command): return ('pip' in command.script and 'unknown command' in command.output and 'maybe you meant' in command.output) def get_new_command(command): broken_cmd = re.findall(r'ERROR: unknown command "([^"]+)"', command.output)[0] new_cmd = re.findall(r'maybe you meant "([^"]+)"', command.output)[0] return replace_argument(command.script, broken_cmd, new_cmd)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/chmod_x.py
thefuck/rules/chmod_x.py
import os from thefuck.shells import shell def match(command): return (command.script.startswith('./') and 'permission denied' in command.output.lower() and os.path.exists(command.script_parts[0]) and not os.access(command.script_parts[0], os.X_OK)) def get_new_command(command): return shell.and_( 'chmod +x {}'.format(command.script_parts[0][2:]), command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/go_unknown_command.py
thefuck/rules/go_unknown_command.py
from itertools import dropwhile, islice, takewhile import subprocess from thefuck.utils import get_closest, replace_argument, for_app, which, cache def get_golang_commands(): proc = subprocess.Popen('go', stderr=subprocess.PIPE) lines = [line.decode('utf-8').strip() for line in proc.stderr.readlines()] lines = dropwhile(lambda line: line != 'The commands are:', lines) lines = islice(lines, 2, None) lines = takewhile(lambda line: line, lines) return [line.split(' ')[0] for line in lines] if which('go'): get_golang_commands = cache(which('go'))(get_golang_commands) @for_app('go') def match(command): return 'unknown command' in command.output def get_new_command(command): closest_subcommand = get_closest(command.script_parts[1], get_golang_commands()) return replace_argument(command.script, command.script_parts[1], closest_subcommand)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/yarn_command_replaced.py
thefuck/rules/yarn_command_replaced.py
import re from thefuck.utils import for_app regex = re.compile(r'Run "(.*)" instead') @for_app('yarn', at_least=1) def match(command): return regex.findall(command.output) def get_new_command(command): return regex.findall(command.output)[0]
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/choco_install.py
thefuck/rules/choco_install.py
from thefuck.utils import for_app, which @for_app("choco", "cinst") def match(command): return ((command.script.startswith('choco install') or 'cinst' in command.script_parts) and 'Installing the following packages' in command.output) def get_new_command(command): # Find the argument that is the package name for script_part in command.script_parts: if ( script_part not in ["choco", "cinst", "install"] # Need exact match (bc chocolatey is a package) and not script_part.startswith('-') # Leading hyphens are parameters; some packages contain them though and '=' not in script_part and '/' not in script_part # These are certainly parameters ): return command.script.replace(script_part, script_part + ".install") return [] enabled_by_default = bool(which("choco")) or bool(which("cinst"))
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_stash.py
thefuck/rules/git_stash.py
from thefuck.shells import shell from thefuck.specific.git import git_support @git_support def match(command): # catches "Please commit or stash them" and "Please, commit your changes or # stash them before you can switch branches." return 'or stash them' in command.output @git_support def get_new_command(command): formatme = shell.and_('git stash', '{}') return formatme.format(command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/path_from_history.py
thefuck/rules/path_from_history.py
from collections import Counter import re from thefuck.system import Path from thefuck.utils import (get_valid_history_without_current, memoize, replace_argument) from thefuck.shells import shell patterns = [r'no such file or directory: (.*)$', r"cannot access '(.*)': No such file or directory", r': (.*): No such file or directory', r"can't cd to (.*)$"] @memoize def _get_destination(command): for pattern in patterns: found = re.findall(pattern, command.output) if found: if found[0] in command.script_parts: return found[0] def match(command): return bool(_get_destination(command)) def _get_all_absolute_paths_from_history(command): counter = Counter() for line in get_valid_history_without_current(command): splitted = shell.split_command(line) for param in splitted[1:]: if param.startswith('/') or param.startswith('~'): if param.endswith('/'): param = param[:-1] counter[param] += 1 return (path for path, _ in counter.most_common(None)) def get_new_command(command): destination = _get_destination(command) paths = _get_all_absolute_paths_from_history(command) return [replace_argument(command.script, destination, path) for path in paths if path.endswith(destination) and Path(path).expanduser().exists()] priority = 800
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_help_aliased.py
thefuck/rules/git_help_aliased.py
from thefuck.specific.git import git_support @git_support def match(command): return 'help' in command.script and ' is aliased to ' in command.output @git_support def get_new_command(command): aliased = command.output.split('`', 2)[2].split("'", 1)[0].split(' ', 1)[0] return 'git help {}'.format(aliased)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/heroku_multiple_apps.py
thefuck/rules/heroku_multiple_apps.py
import re from thefuck.utils import for_app @for_app('heroku') def match(command): return 'https://devcenter.heroku.com/articles/multiple-environments' in command.output def get_new_command(command): apps = re.findall('([^ ]*) \\([^)]*\\)', command.output) return [command.script + ' --app ' + app for app in apps]
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/cd_correction.py
thefuck/rules/cd_correction.py
"""Attempts to spellcheck and correct failed cd commands""" import os import six from thefuck.specific.sudo import sudo_support from thefuck.rules import cd_mkdir from thefuck.utils import for_app, get_close_matches __author__ = "mmussomele" MAX_ALLOWED_DIFF = 0.6 def _get_sub_dirs(parent): """Returns a list of the child directories of the given parent directory""" return [child for child in os.listdir(parent) if os.path.isdir(os.path.join(parent, child))] @sudo_support @for_app('cd') def match(command): """Match function copied from cd_mkdir.py""" return ( command.script.startswith('cd ') and any(( 'no such file or directory' in command.output.lower(), 'cd: can\'t cd to' in command.output.lower(), 'does not exist' in command.output.lower() ))) @sudo_support def get_new_command(command): """ Attempt to rebuild the path string by spellchecking the directories. If it fails (i.e. no directories are a close enough match), then it defaults to the rules of cd_mkdir. Change sensitivity by changing MAX_ALLOWED_DIFF. Default value is 0.6 """ dest = command.script_parts[1].split(os.sep) if dest[-1] == '': dest = dest[:-1] if dest[0] == '': cwd = os.sep dest = dest[1:] elif six.PY2: cwd = os.getcwdu() else: cwd = os.getcwd() for directory in dest: if directory == ".": continue elif directory == "..": cwd = os.path.split(cwd)[0] continue best_matches = get_close_matches(directory, _get_sub_dirs(cwd), cutoff=MAX_ALLOWED_DIFF) if best_matches: cwd = os.path.join(cwd, best_matches[0]) else: return cd_mkdir.get_new_command(command) return u'cd "{0}"'.format(cwd)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_not_command.py
thefuck/rules/git_not_command.py
import re from thefuck.utils import get_all_matched_commands, replace_command from thefuck.specific.git import git_support @git_support def match(command): return (" is not a git command. See 'git --help'." in command.output and ('The most similar command' in command.output or 'Did you mean' in command.output)) @git_support def get_new_command(command): broken_cmd = re.findall(r"git: '([^']*)' is not a git command", command.output)[0] matched = get_all_matched_commands(command.output, ['The most similar command', 'Did you mean']) return replace_command(command, broken_cmd, matched)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/django_south_ghost.py
thefuck/rules/django_south_ghost.py
def match(command): return 'manage.py' in command.script and \ 'migrate' in command.script \ and 'or pass --delete-ghost-migrations' in command.output def get_new_command(command): return u'{} --delete-ghost-migrations'.format(command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/touch.py
thefuck/rules/touch.py
import re from thefuck.shells import shell from thefuck.utils import for_app @for_app('touch') def match(command): return 'No such file or directory' in command.output def get_new_command(command): path = re.findall( r"touch: (?:cannot touch ')?(.+)/.+'?:", command.output)[0] return shell.and_(u'mkdir -p {}'.format(path), command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_rebase_no_changes.py
thefuck/rules/git_rebase_no_changes.py
from thefuck.specific.git import git_support @git_support def match(command): return ( {'rebase', '--continue'}.issubset(command.script_parts) and 'No changes - did you forget to use \'git add\'?' in command.output ) def get_new_command(command): return 'git rebase --skip'
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/unknown_command.py
thefuck/rules/unknown_command.py
import re from thefuck.utils import replace_command def match(command): return (re.search(r"([^:]*): Unknown command.*", command.output) is not None and re.search(r"Did you mean ([^?]*)?", command.output) is not None) def get_new_command(command): broken_cmd = re.findall(r"([^:]*): Unknown command.*", command.output)[0] matched = re.findall(r"Did you mean ([^?]*)?", command.output) return replace_command(command, broken_cmd, matched)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/missing_space_before_subcommand.py
thefuck/rules/missing_space_before_subcommand.py
from thefuck.utils import get_all_executables, memoize @memoize def _get_executable(script_part): for executable in get_all_executables(): if len(executable) > 1 and script_part.startswith(executable): return executable def match(command): return (not command.script_parts[0] in get_all_executables() and _get_executable(command.script_parts[0])) def get_new_command(command): executable = _get_executable(command.script_parts[0]) return command.script.replace(executable, u'{} '.format(executable), 1) priority = 4000
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_add_force.py
thefuck/rules/git_add_force.py
from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): return ('add' in command.script_parts and 'Use -f if you really want to add them.' in command.output) @git_support def get_new_command(command): return replace_argument(command.script, 'add', 'add --force')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/dry.py
thefuck/rules/dry.py
def match(command): split_command = command.script_parts return (split_command and len(split_command) >= 2 and split_command[0] == split_command[1]) def get_new_command(command): return ' '.join(command.script_parts[1:]) # it should be rare enough to actually have to type twice the same word, so # this rule can have a higher priority to come before things like "cd cd foo" priority = 900
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_rm_local_modifications.py
thefuck/rules/git_rm_local_modifications.py
from thefuck.specific.git import git_support @git_support def match(command): return (' rm ' in command.script and 'error: the following file has local modifications' in command.output and 'use --cached to keep the file, or -f to force removal' in command.output) @git_support def get_new_command(command): command_parts = command.script_parts[:] index = command_parts.index('rm') + 1 command_parts.insert(index, '--cached') command_list = [u' '.join(command_parts)] command_parts[index] = '-f' command_list.append(u' '.join(command_parts)) return command_list
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/fix_file.py
thefuck/rules/fix_file.py
import re import os from thefuck.utils import memoize, default_settings from thefuck.conf import settings from thefuck.shells import shell # order is important: only the first match is considered patterns = ( # js, node: '^ at {file}:{line}:{col}', # cargo: '^ {file}:{line}:{col}', # python, thefuck: '^ File "{file}", line {line}', # awk: '^awk: {file}:{line}:', # git '^fatal: bad config file line {line} in {file}', # llc: '^llc: {file}:{line}:{col}:', # lua: '^lua: {file}:{line}:', # fish: '^{file} \\(line {line}\\):', # bash, sh, ssh: '^{file}: line {line}: ', # cargo, clang, gcc, go, pep8, rustc: '^{file}:{line}:{col}', # ghc, make, ruby, zsh: '^{file}:{line}:', # perl: 'at {file} line {line}', ) # for the sake of readability do not use named groups above def _make_pattern(pattern): pattern = pattern.replace('{file}', '(?P<file>[^:\n]+)') \ .replace('{line}', '(?P<line>[0-9]+)') \ .replace('{col}', '(?P<col>[0-9]+)') return re.compile(pattern, re.MULTILINE) patterns = [_make_pattern(p).search for p in patterns] @memoize def _search(output): for pattern in patterns: m = pattern(output) if m and os.path.isfile(m.group('file')): return m def match(command): if 'EDITOR' not in os.environ: return False return _search(command.output) @default_settings({'fixlinecmd': u'{editor} {file} +{line}', 'fixcolcmd': None}) def get_new_command(command): m = _search(command.output) # Note: there does not seem to be a standard for columns, so they are just # ignored by default if settings.fixcolcmd and 'col' in m.groupdict(): editor_call = settings.fixcolcmd.format(editor=os.environ['EDITOR'], file=m.group('file'), line=m.group('line'), col=m.group('col')) else: editor_call = settings.fixlinecmd.format(editor=os.environ['EDITOR'], file=m.group('file'), line=m.group('line')) return shell.and_(editor_call, command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/terraform_init.py
thefuck/rules/terraform_init.py
from thefuck.shells import shell from thefuck.utils import for_app @for_app('terraform') def match(command): return ('this module is not yet installed' in command.output.lower() or 'initialization required' in command.output.lower() ) def get_new_command(command): return shell.and_('terraform init', command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_pull_clone.py
thefuck/rules/git_pull_clone.py
from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): return ('fatal: Not a git repository' in command.output and "Stopping at filesystem boundary (GIT_DISCOVERY_ACROSS_FILESYSTEM not set)." in command.output) @git_support def get_new_command(command): return replace_argument(command.script, 'pull', 'clone')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_fix_stash.py
thefuck/rules/git_fix_stash.py
from thefuck import utils from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): if command.script_parts and len(command.script_parts) > 1: return (command.script_parts[1] == 'stash' and 'usage:' in command.output) else: return False # git's output here is too complicated to be parsed (see the test file) stash_commands = ( 'apply', 'branch', 'clear', 'drop', 'list', 'pop', 'save', 'show') @git_support def get_new_command(command): stash_cmd = command.script_parts[2] fixed = utils.get_closest(stash_cmd, stash_commands, fallback_to_first=False) if fixed is not None: return replace_argument(command.script, stash_cmd, fixed) else: cmd = command.script_parts[:] cmd.insert(2, 'save') return ' '.join(cmd)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/grep_recursive.py
thefuck/rules/grep_recursive.py
from thefuck.utils import for_app @for_app('grep') def match(command): return 'is a directory' in command.output.lower() def get_new_command(command): return u'grep -r {}'.format(command.script[5:])
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/dirty_unzip.py
thefuck/rules/dirty_unzip.py
import os import zipfile from thefuck.utils import for_app from thefuck.shells import shell def _is_bad_zip(file): try: with zipfile.ZipFile(file, 'r') as archive: return len(archive.namelist()) > 1 except Exception: return False def _zip_file(command): # unzip works that way: # unzip [-flags] file[.zip] [file(s) ...] [-x file(s) ...] # ^ ^ files to unzip from the archive # archive to unzip for c in command.script_parts[1:]: if not c.startswith('-'): if c.endswith('.zip'): return c else: return u'{}.zip'.format(c) @for_app('unzip') def match(command): if '-d' in command.script: return False zip_file = _zip_file(command) if zip_file: return _is_bad_zip(zip_file) else: return False def get_new_command(command): return u'{} -d {}'.format( command.script, shell.quote(_zip_file(command)[:-4])) def side_effect(old_cmd, command): with zipfile.ZipFile(_zip_file(old_cmd), 'r') as archive: for file in archive.namelist(): if not os.path.abspath(file).startswith(os.getcwd()): # it's unsafe to overwrite files outside of the current directory continue try: os.remove(file) except OSError: # does not try to remove directories as we cannot know if they # already existed before pass requires_output = False
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_checkout.py
thefuck/rules/git_checkout.py
import re import subprocess from thefuck import utils from thefuck.utils import replace_argument from thefuck.specific.git import git_support from thefuck.shells import shell @git_support def match(command): return ('did not match any file(s) known to git' in command.output and "Did you forget to 'git add'?" not in command.output) def get_branches(): proc = subprocess.Popen( ['git', 'branch', '-a', '--no-color', '--no-column'], stdout=subprocess.PIPE) for line in proc.stdout.readlines(): line = line.decode('utf-8') if '->' in line: # Remote HEAD like b' remotes/origin/HEAD -> origin/master' continue if line.startswith('*'): line = line.split(' ')[1] if line.strip().startswith('remotes/'): line = '/'.join(line.split('/')[2:]) yield line.strip() @git_support def get_new_command(command): missing_file = re.findall( r"error: pathspec '([^']*)' " r"did not match any file\(s\) known to git", command.output)[0] closest_branch = utils.get_closest(missing_file, get_branches(), fallback_to_first=False) new_commands = [] if closest_branch: new_commands.append(replace_argument(command.script, missing_file, closest_branch)) if command.script_parts[1] == 'checkout': new_commands.append(replace_argument(command.script, 'checkout', 'checkout -b')) if not new_commands: new_commands.append(shell.and_('git branch {}', '{}').format( missing_file, command.script)) return new_commands
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_clone_missing.py
thefuck/rules/git_clone_missing.py
''' Rule: git_clone_missing Correct missing `git clone` command when pasting a git URL ```sh >>> https://github.com/nvbn/thefuck.git git clone https://github.com/nvbn/thefuck.git ``` Author: Miguel Guthridge ''' from six.moves.urllib import parse from thefuck.utils import which def match(command): # We want it to be a URL by itself if len(command.script_parts) != 1: return False # Ensure we got the error we expected if which(command.script_parts[0]) or not ( 'No such file or directory' in command.output or 'not found' in command.output or 'is not recognised as' in command.output ): return False url = parse.urlparse(command.script, scheme='ssh') # HTTP URLs need a network address if not url.netloc and url.scheme != 'ssh': return False # SSH needs a username and a splitter between the path if url.scheme == 'ssh' and not ( '@' in command.script and ':' in command.script ): return False return url.scheme in ['http', 'https', 'ssh'] def get_new_command(command): return 'git clone ' + command.script
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/nixos_cmd_not_found.py
thefuck/rules/nixos_cmd_not_found.py
import re from thefuck.specific.nix import nix_available from thefuck.shells import shell regex = re.compile(r'nix-env -iA ([^\s]*)') enabled_by_default = nix_available def match(command): return regex.findall(command.output) def get_new_command(command): name = regex.findall(command.output)[0] return shell.and_('nix-env -iA {}'.format(name), command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/yarn_help.py
thefuck/rules/yarn_help.py
import re from thefuck.utils import for_app from thefuck.system import open_command @for_app('yarn', at_least=2) def match(command): return (command.script_parts[1] == 'help' and 'for documentation about this command.' in command.output) def get_new_command(command): url = re.findall( r'Visit ([^ ]*) for documentation about this command.', command.output)[0] return open_command(url)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/cp_create_destination.py
thefuck/rules/cp_create_destination.py
from thefuck.shells import shell from thefuck.utils import for_app @for_app("cp", "mv") def match(command): return ( "No such file or directory" in command.output or command.output.startswith("cp: directory") and command.output.rstrip().endswith("does not exist") ) def get_new_command(command): return shell.and_(u"mkdir -p {}".format(command.script_parts[-1]), command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_commit_add.py
thefuck/rules/git_commit_add.py
from thefuck.utils import eager, replace_argument from thefuck.specific.git import git_support @git_support def match(command): return ( "commit" in command.script_parts and "no changes added to commit" in command.output ) @eager @git_support def get_new_command(command): for opt in ("-a", "-p"): yield replace_argument(command.script, "commit", "commit {}".format(opt))
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/yum_invalid_operation.py
thefuck/rules/yum_invalid_operation.py
import subprocess from itertools import dropwhile, islice, takewhile from thefuck.specific.sudo import sudo_support from thefuck.specific.yum import yum_available from thefuck.utils import for_app, replace_command, which, cache enabled_by_default = yum_available @sudo_support @for_app('yum') def match(command): return 'No such command: ' in command.output def _get_operations(): proc = subprocess.Popen('yum', stdout=subprocess.PIPE) lines = proc.stdout.readlines() lines = [line.decode('utf-8') for line in lines] lines = dropwhile(lambda line: not line.startswith("List of Commands:"), lines) lines = islice(lines, 2, None) lines = list(takewhile(lambda line: line.strip(), lines)) return [line.strip().split(' ')[0] for line in lines] if which('yum'): _get_operations = cache(which('yum'))(_get_operations) @sudo_support def get_new_command(command): invalid_operation = command.script_parts[1] if invalid_operation == 'uninstall': return [command.script.replace('uninstall', 'remove')] return replace_command(command, invalid_operation, _get_operations())
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_push_without_commits.py
thefuck/rules/git_push_without_commits.py
import re from thefuck.shells import shell from thefuck.specific.git import git_support @git_support def match(command): return bool(re.search(r"src refspec \w+ does not match any", command.output)) def get_new_command(command): return shell.and_('git commit -m "Initial commit"', command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/has_exists_script.py
thefuck/rules/has_exists_script.py
import os from thefuck.specific.sudo import sudo_support @sudo_support def match(command): return command.script_parts and os.path.exists(command.script_parts[0]) \ and 'command not found' in command.output @sudo_support def get_new_command(command): return u'./{}'.format(command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_rm_recursive.py
thefuck/rules/git_rm_recursive.py
from thefuck.specific.git import git_support @git_support def match(command): return (' rm ' in command.script and "fatal: not removing '" in command.output and "' recursively without -r" in command.output) @git_support def get_new_command(command): command_parts = command.script_parts[:] index = command_parts.index('rm') + 1 command_parts.insert(index, '-r') return u' '.join(command_parts)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/brew_install.py
thefuck/rules/brew_install.py
import re from thefuck.utils import for_app from thefuck.specific.brew import brew_available enabled_by_default = brew_available def _get_suggestions(str): suggestions = str.replace(" or ", ", ").split(", ") return suggestions @for_app('brew', at_least=2) def match(command): is_proper_command = ('install' in command.script and 'No available formula' in command.output and 'Did you mean' in command.output) return is_proper_command def get_new_command(command): matcher = re.search('Warning: No available formula with the name "(?:[^"]+)". Did you mean (.+)\\?', command.output) suggestions = _get_suggestions(matcher.group(1)) return ["brew install " + formula for formula in suggestions]
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/lein_not_task.py
thefuck/rules/lein_not_task.py
import re from thefuck.utils import replace_command, get_all_matched_commands, for_app from thefuck.specific.sudo import sudo_support @sudo_support @for_app('lein') def match(command): return (command.script.startswith('lein') and "is not a task. See 'lein help'" in command.output and 'Did you mean this?' in command.output) @sudo_support def get_new_command(command): broken_cmd = re.findall(r"'([^']*)' is not a task", command.output)[0] new_cmds = get_all_matched_commands(command.output, 'Did you mean this?') return replace_command(command, broken_cmd, new_cmds)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/apt_get.py
thefuck/rules/apt_get.py
from types import ModuleType from thefuck.specific.apt import apt_available from thefuck.utils import memoize, which from thefuck.shells import shell try: from CommandNotFound import CommandNotFound enabled_by_default = apt_available if isinstance(CommandNotFound, ModuleType): # For ubuntu 18.04+ _get_packages = CommandNotFound.CommandNotFound().get_packages else: # For older versions _get_packages = CommandNotFound().getPackages except ImportError: enabled_by_default = False def _get_executable(command): if command.script_parts[0] == 'sudo': return command.script_parts[1] else: return command.script_parts[0] @memoize def get_package(executable): try: packages = _get_packages(executable) return packages[0][0] except IndexError: # IndexError is thrown when no matching package is found return None def match(command): if 'not found' in command.output or 'not installed' in command.output: executable = _get_executable(command) return not which(executable) and get_package(executable) else: return False def get_new_command(command): executable = _get_executable(command) name = get_package(executable) formatme = shell.and_('sudo apt-get install {}', '{}') return formatme.format(name, command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/java.py
thefuck/rules/java.py
"""Fixes common java command mistake Example: > java foo.java Error: Could not find or load main class foo.java """ from thefuck.utils import for_app @for_app('java') def match(command): return command.script.endswith('.java') def get_new_command(command): return command.script[:-5]
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/cp_omitting_directory.py
thefuck/rules/cp_omitting_directory.py
import re from thefuck.specific.sudo import sudo_support from thefuck.utils import for_app @sudo_support @for_app('cp') def match(command): output = command.output.lower() return 'omitting directory' in output or 'is a directory' in output @sudo_support def get_new_command(command): return re.sub(r'^cp', 'cp -a', command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/mvn_no_command.py
thefuck/rules/mvn_no_command.py
from thefuck.utils import for_app @for_app('mvn') def match(command): return 'No goals have been specified for this build' in command.output def get_new_command(command): return [command.script + ' clean package', command.script + ' clean install']
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/scm_correction.py
thefuck/rules/scm_correction.py
from thefuck.utils import for_app, memoize from thefuck.system import Path path_to_scm = { '.git': 'git', '.hg': 'hg', } wrong_scm_patterns = { 'git': 'fatal: Not a git repository', 'hg': 'abort: no repository found', } @memoize def _get_actual_scm(): for path, scm in path_to_scm.items(): if Path(path).is_dir(): return scm @for_app(*wrong_scm_patterns.keys()) def match(command): scm = command.script_parts[0] pattern = wrong_scm_patterns[scm] return pattern in command.output and _get_actual_scm() def get_new_command(command): scm = _get_actual_scm() return u' '.join([scm] + command.script_parts[1:])
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/ln_no_hard_link.py
thefuck/rules/ln_no_hard_link.py
# -*- coding: utf-8 -*- """Suggest creating symbolic link if hard link is not allowed. Example: > ln barDir barLink ln: ‘barDir’: hard link not allowed for directory --> ln -s barDir barLink """ import re from thefuck.specific.sudo import sudo_support @sudo_support def match(command): return (command.output.endswith("hard link not allowed for directory") and command.script_parts[0] == 'ln') @sudo_support def get_new_command(command): return re.sub(r'^ln ', 'ln -s ', command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/apt_invalid_operation.py
thefuck/rules/apt_invalid_operation.py
import subprocess from thefuck.specific.apt import apt_available from thefuck.specific.sudo import sudo_support from thefuck.utils import for_app, eager, replace_command enabled_by_default = apt_available @sudo_support @for_app('apt', 'apt-get', 'apt-cache') def match(command): return 'E: Invalid operation' in command.output @eager def _parse_apt_operations(help_text_lines): is_commands_list = False for line in help_text_lines: line = line.decode().strip() if is_commands_list and line: yield line.split()[0] elif line.startswith('Basic commands:') \ or line.startswith('Most used commands:'): is_commands_list = True @eager def _parse_apt_get_and_cache_operations(help_text_lines): is_commands_list = False for line in help_text_lines: line = line.decode().strip() if is_commands_list: if not line: return yield line.split()[0] elif line.startswith('Commands:') \ or line.startswith('Most used commands:'): is_commands_list = True def _get_operations(app): proc = subprocess.Popen([app, '--help'], stdout=subprocess.PIPE, stderr=subprocess.PIPE) lines = proc.stdout.readlines() if app == 'apt': return _parse_apt_operations(lines) else: return _parse_apt_get_and_cache_operations(lines) @sudo_support def get_new_command(command): invalid_operation = command.output.split()[-1] if invalid_operation == 'uninstall': return [command.script.replace('uninstall', 'remove')] else: operations = _get_operations(command.script_parts[0]) return replace_command(command, invalid_operation, operations)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/remove_shell_prompt_literal.py
thefuck/rules/remove_shell_prompt_literal.py
"""Fixes error for commands containing one or more occurrences of the shell prompt symbol '$'. This usually happens when commands are copied from documentations including them in their code blocks. Example: > $ git clone https://github.com/nvbn/thefuck.git bash: $: command not found... """ import re def match(command): return ( "$: command not found" in command.output and re.search(r"^[\s]*\$ [\S]+", command.script) is not None ) def get_new_command(command): return command.script.lstrip("$ ")
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/rm_root.py
thefuck/rules/rm_root.py
from thefuck.specific.sudo import sudo_support enabled_by_default = False @sudo_support def match(command): return (command.script_parts and {'rm', '/'}.issubset(command.script_parts) and '--no-preserve-root' not in command.script and '--no-preserve-root' in command.output) @sudo_support def get_new_command(command): return u'{} --no-preserve-root'.format(command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/php_s.py
thefuck/rules/php_s.py
from thefuck.utils import replace_argument, for_app @for_app('php', at_least=2) def match(command): return ('-s' in command.script_parts and command.script_parts[-1] != '-s') def get_new_command(command): return replace_argument(command.script, "-s", "-S")
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_branch_list.py
thefuck/rules/git_branch_list.py
from thefuck.shells import shell from thefuck.specific.git import git_support @git_support def match(command): # catches "git branch list" in place of "git branch" return (command.script_parts and command.script_parts[1:] == 'branch list'.split()) @git_support def get_new_command(command): return shell.and_('git branch --delete list', 'git branch')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_push_force.py
thefuck/rules/git_push_force.py
from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): return ('push' in command.script and '! [rejected]' in command.output and 'failed to push some refs to' in command.output and 'Updates were rejected because the tip of your current branch is behind' in command.output) @git_support def get_new_command(command): return replace_argument(command.script, 'push', 'push --force-with-lease') enabled_by_default = False
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/aws_cli.py
thefuck/rules/aws_cli.py
import re from thefuck.utils import for_app, replace_argument INVALID_CHOICE = "(?<=Invalid choice: ')(.*)(?=', maybe you meant:)" OPTIONS = "^\\s*\\*\\s(.*)" @for_app('aws') def match(command): return "usage:" in command.output and "maybe you meant:" in command.output def get_new_command(command): mistake = re.search(INVALID_CHOICE, command.output).group(0) options = re.findall(OPTIONS, command.output, flags=re.MULTILINE) return [replace_argument(command.script, mistake, o) for o in options]
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/workon_doesnt_exists.py
thefuck/rules/workon_doesnt_exists.py
from thefuck.utils import for_app, replace_command, eager, memoize from thefuck.system import Path @memoize @eager def _get_all_environments(): root = Path('~/.virtualenvs').expanduser() if not root.is_dir(): return for child in root.iterdir(): if child.is_dir(): yield child.name @for_app('workon') def match(command): return (len(command.script_parts) >= 2 and command.script_parts[1] not in _get_all_environments()) def get_new_command(command): misspelled_env = command.script_parts[1] create_new = u'mkvirtualenv {}'.format(misspelled_env) available = _get_all_environments() if available: return (replace_command(command, misspelled_env, available) + [create_new]) else: return create_new
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/ssh_known_hosts.py
thefuck/rules/ssh_known_hosts.py
import re from thefuck.utils import for_app commands = ('ssh', 'scp') @for_app(*commands) def match(command): if not command.script: return False if not command.script.startswith(commands): return False patterns = ( r'WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!', r'WARNING: POSSIBLE DNS SPOOFING DETECTED!', r"Warning: the \S+ host key for '([^']+)' differs from the key for the IP address '([^']+)'", ) return any(re.findall(pattern, command.output) for pattern in patterns) def get_new_command(command): return command.script def side_effect(old_cmd, command): offending_pattern = re.compile( r'(?:Offending (?:key for IP|\S+ key)|Matching host key) in ([^:]+):(\d+)', re.MULTILINE) offending = offending_pattern.findall(old_cmd.output) for filepath, lineno in offending: with open(filepath, 'r') as fh: lines = fh.readlines() del lines[int(lineno) - 1] with open(filepath, 'w') as fh: fh.writelines(lines)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/mercurial.py
thefuck/rules/mercurial.py
import re from thefuck.utils import get_closest, for_app def extract_possibilities(command): possib = re.findall(r'\n\(did you mean one of ([^\?]+)\?\)', command.output) if possib: return possib[0].split(', ') possib = re.findall(r'\n ([^$]+)$', command.output) if possib: return possib[0].split(' ') return possib @for_app('hg') def match(command): return ('hg: unknown command' in command.output and '(did you mean one of ' in command.output or "hg: command '" in command.output and "' is ambiguous:" in command.output) def get_new_command(command): script = command.script_parts[:] possibilities = extract_possibilities(command) script[1] = get_closest(script[1], possibilities) return ' '.join(script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/conda_mistype.py
thefuck/rules/conda_mistype.py
import re from thefuck.utils import replace_command, for_app @for_app("conda") def match(command): """ Match a mistyped command """ return "Did you mean 'conda" in command.output def get_new_command(command): match = re.findall(r"'conda ([^']*)'", command.output) broken_cmd = match[0] correct_cmd = match[1] return replace_command(command, broken_cmd, [correct_cmd])
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/port_already_in_use.py
thefuck/rules/port_already_in_use.py
import re from subprocess import Popen, PIPE from thefuck.utils import memoize, which from thefuck.shells import shell enabled_by_default = bool(which('lsof')) patterns = [r"bind on address \('.*', (?P<port>\d+)\)", r'Unable to bind [^ ]*:(?P<port>\d+)', r"can't listen on port (?P<port>\d+)", r'listen EADDRINUSE [^ ]*:(?P<port>\d+)'] @memoize def _get_pid_by_port(port): proc = Popen(['lsof', '-i', ':{}'.format(port)], stdout=PIPE) lines = proc.stdout.read().decode().split('\n') if len(lines) > 1: return lines[1].split()[1] else: return None @memoize def _get_used_port(command): for pattern in patterns: matched = re.search(pattern, command.output) if matched: return matched.group('port') def match(command): port = _get_used_port(command) return port and _get_pid_by_port(port) def get_new_command(command): port = _get_used_port(command) pid = _get_pid_by_port(port) return shell.and_(u'kill {}'.format(pid), command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/yarn_alias.py
thefuck/rules/yarn_alias.py
import re from thefuck.utils import replace_argument, for_app @for_app('yarn', at_least=1) def match(command): return 'Did you mean' in command.output def get_new_command(command): broken = command.script_parts[1] fix = re.findall(r'Did you mean [`"](?:yarn )?([^`"]*)[`"]', command.output)[0] return replace_argument(command.script, broken, fix)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_merge_unrelated.py
thefuck/rules/git_merge_unrelated.py
from thefuck.specific.git import git_support @git_support def match(command): return ('merge' in command.script and 'fatal: refusing to merge unrelated histories' in command.output) @git_support def get_new_command(command): return command.script + ' --allow-unrelated-histories'
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/ls_all.py
thefuck/rules/ls_all.py
from thefuck.utils import for_app @for_app('ls') def match(command): return command.output.strip() == '' def get_new_command(command): return ' '.join(['ls', '-A'] + command.script_parts[1:])
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/prove_recursively.py
thefuck/rules/prove_recursively.py
import os from thefuck.utils import for_app def _is_recursive(part): if part == '--recurse': return True elif not part.startswith('--') and part.startswith('-') and 'r' in part: return True def _isdir(part): return not part.startswith('-') and os.path.isdir(part) @for_app('prove') def match(command): return ( 'NOTESTS' in command.output and not any(_is_recursive(part) for part in command.script_parts[1:]) and any(_isdir(part) for part in command.script_parts[1:])) def get_new_command(command): parts = command.script_parts[:] parts.insert(1, '-r') return u' '.join(parts)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/ifconfig_device_not_found.py
thefuck/rules/ifconfig_device_not_found.py
import subprocess from thefuck.utils import for_app, replace_command, eager @for_app('ifconfig') def match(command): return 'error fetching interface information: Device not found' \ in command.output @eager def _get_possible_interfaces(): proc = subprocess.Popen(['ifconfig', '-a'], stdout=subprocess.PIPE) for line in proc.stdout.readlines(): line = line.decode() if line and line != '\n' and not line.startswith(' '): yield line.split(' ')[0] def get_new_command(command): interface = command.output.split(' ')[0][:-1] possible_interfaces = _get_possible_interfaces() return replace_command(command, interface, possible_interfaces)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/brew_update_formula.py
thefuck/rules/brew_update_formula.py
from thefuck.utils import for_app @for_app('brew', at_least=2) def match(command): return ('update' in command.script and "Error: This command updates brew itself" in command.output and "Use `brew upgrade" in command.output) def get_new_command(command): return command.script.replace('update', 'upgrade')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/npm_wrong_command.py
thefuck/rules/npm_wrong_command.py
from thefuck.specific.npm import npm_available from thefuck.utils import replace_argument, for_app, eager, get_closest from thefuck.specific.sudo import sudo_support enabled_by_default = npm_available def _get_wrong_command(script_parts): commands = [part for part in script_parts[1:] if not part.startswith('-')] if commands: return commands[0] @sudo_support @for_app('npm') def match(command): return (command.script_parts[0] == 'npm' and 'where <command> is one of:' in command.output and _get_wrong_command(command.script_parts)) @eager def _get_available_commands(stdout): commands_listing = False for line in stdout.split('\n'): if line.startswith('where <command> is one of:'): commands_listing = True elif commands_listing: if not line: break for command in line.split(', '): stripped = command.strip() if stripped: yield stripped def get_new_command(command): npm_commands = _get_available_commands(command.output) wrong_command = _get_wrong_command(command.script_parts) fixed = get_closest(wrong_command, npm_commands) return replace_argument(command.script, wrong_command, fixed)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_tag_force.py
thefuck/rules/git_tag_force.py
from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): return ('tag' in command.script_parts and 'already exists' in command.output) @git_support def get_new_command(command): return replace_argument(command.script, 'tag', 'tag --force')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/open.py
thefuck/rules/open.py
# Opens URL's in the default web browser # # Example: # > open github.com # The file ~/github.com does not exist. # Perhaps you meant 'http://github.com'? # from thefuck.shells import shell from thefuck.utils import eager, for_app def is_arg_url(command): return ('.com' in command.script or '.edu' in command.script or '.info' in command.script or '.io' in command.script or '.ly' in command.script or '.me' in command.script or '.net' in command.script or '.org' in command.script or '.se' in command.script or 'www.' in command.script) @for_app('open', 'xdg-open', 'gnome-open', 'kde-open') def match(command): return (is_arg_url(command) or command.output.strip().startswith('The file ') and command.output.strip().endswith(' does not exist.')) @eager def get_new_command(command): output = command.output.strip() if is_arg_url(command): yield command.script.replace('open ', 'open http://') elif output.startswith('The file ') and output.endswith(' does not exist.'): arg = command.script.split(' ', 1)[1] for option in ['touch', 'mkdir']: yield shell.and_(u'{} {}'.format(option, arg), command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/javac.py
thefuck/rules/javac.py
"""Appends .java when compiling java files Example: > javac foo error: Class names, 'foo', are only accepted if annotation processing is explicitly requested """ from thefuck.utils import for_app @for_app('javac') def match(command): return not command.script.endswith('.java') def get_new_command(command): return command.script + '.java'
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/brew_unknown_command.py
thefuck/rules/brew_unknown_command.py
import os import re from thefuck.utils import get_closest, replace_command from thefuck.specific.brew import get_brew_path_prefix, brew_available BREW_CMD_PATH = '/Homebrew/Library/Homebrew/cmd' TAP_PATH = '/Homebrew/Library/Taps' TAP_CMD_PATH = '/%s/%s/cmd' enabled_by_default = brew_available def _get_brew_commands(brew_path_prefix): """To get brew default commands on local environment""" brew_cmd_path = brew_path_prefix + BREW_CMD_PATH return [name[:-3] for name in os.listdir(brew_cmd_path) if name.endswith(('.rb', '.sh'))] def _get_brew_tap_specific_commands(brew_path_prefix): """To get tap's specific commands https://github.com/Homebrew/homebrew/blob/master/Library/brew.rb#L115""" commands = [] brew_taps_path = brew_path_prefix + TAP_PATH for user in _get_directory_names_only(brew_taps_path): taps = _get_directory_names_only(brew_taps_path + '/%s' % user) # Brew Taps's naming rule # https://github.com/Homebrew/homebrew/blob/master/share/doc/homebrew/brew-tap.md#naming-conventions-and-limitations taps = (tap for tap in taps if tap.startswith('homebrew-')) for tap in taps: tap_cmd_path = brew_taps_path + TAP_CMD_PATH % (user, tap) if os.path.isdir(tap_cmd_path): commands += (name.replace('brew-', '').replace('.rb', '') for name in os.listdir(tap_cmd_path) if _is_brew_tap_cmd_naming(name)) return commands def _is_brew_tap_cmd_naming(name): return name.startswith('brew-') and name.endswith('.rb') def _get_directory_names_only(path): return [d for d in os.listdir(path) if os.path.isdir(os.path.join(path, d))] def _brew_commands(): brew_path_prefix = get_brew_path_prefix() if brew_path_prefix: try: return (_get_brew_commands(brew_path_prefix) + _get_brew_tap_specific_commands(brew_path_prefix)) except OSError: pass # Failback commands for testing (Based on Homebrew 0.9.5) return ['info', 'home', 'options', 'install', 'uninstall', 'search', 'list', 'update', 'upgrade', 'pin', 'unpin', 'doctor', 'create', 'edit', 'cask'] def match(command): is_proper_command = ('brew' in command.script and 'Unknown command' in command.output) if is_proper_command: broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)', command.output)[0] return bool(get_closest(broken_cmd, _brew_commands())) return False def get_new_command(command): broken_cmd = re.findall(r'Error: Unknown command: ([a-z]+)', command.output)[0] return replace_command(command, broken_cmd, _brew_commands())
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/mvn_unknown_lifecycle_phase.py
thefuck/rules/mvn_unknown_lifecycle_phase.py
from thefuck.utils import for_app, get_close_matches, replace_command import re def _get_failed_lifecycle(command): return re.search(r'\[ERROR\] Unknown lifecycle phase "(.+)"', command.output) def _getavailable_lifecycles(command): return re.search( r'Available lifecycle phases are: (.+) -> \[Help 1\]', command.output) @for_app('mvn') def match(command): failed_lifecycle = _get_failed_lifecycle(command) available_lifecycles = _getavailable_lifecycles(command) return available_lifecycles and failed_lifecycle def get_new_command(command): failed_lifecycle = _get_failed_lifecycle(command) available_lifecycles = _getavailable_lifecycles(command) if available_lifecycles and failed_lifecycle: selected_lifecycle = get_close_matches( failed_lifecycle.group(1), available_lifecycles.group(1).split(", ")) return replace_command(command, failed_lifecycle.group(1), selected_lifecycle) else: return []
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/test.py.py
thefuck/rules/test.py.py
def match(command): return command.script == 'test.py' and 'not found' in command.output def get_new_command(command): return 'pytest' # make it come before the python_command rule priority = 900
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/quotation_marks.py
thefuck/rules/quotation_marks.py
# Fixes careless " and ' usage # # Example: # > git commit -m 'My Message" def match(command): return '\'' in command.script and '\"' in command.script def get_new_command(command): return command.script.replace('\'', '\"')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/fab_command_not_found.py
thefuck/rules/fab_command_not_found.py
from thefuck.utils import eager, get_closest, for_app @for_app('fab') def match(command): return 'Warning: Command(s) not found:' in command.output # We need different behavior then in get_all_matched_commands. @eager def _get_between(content, start, end=None): should_yield = False for line in content.split('\n'): if start in line: should_yield = True continue if end and end in line: return if should_yield and line: yield line.strip().split(' ')[0] def get_new_command(command): not_found_commands = _get_between( command.output, 'Warning: Command(s) not found:', 'Available commands:') possible_commands = _get_between( command.output, 'Available commands:') script = command.script for not_found in not_found_commands: fix = get_closest(not_found, possible_commands) script = script.replace(' {}'.format(not_found), ' {}'.format(fix)) return script
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/omnienv_no_such_command.py
thefuck/rules/omnienv_no_such_command.py
import re from thefuck.utils import (cache, for_app, replace_argument, replace_command, which) from subprocess import PIPE, Popen supported_apps = 'goenv', 'nodenv', 'pyenv', 'rbenv' enabled_by_default = any(which(a) for a in supported_apps) COMMON_TYPOS = { 'list': ['versions', 'install --list'], 'remove': ['uninstall'], } @for_app(*supported_apps, at_least=1) def match(command): return 'env: no such command ' in command.output def get_app_commands(app): proc = Popen([app, 'commands'], stdout=PIPE) return [line.decode('utf-8').strip() for line in proc.stdout.readlines()] def get_new_command(command): broken = re.findall(r"env: no such command ['`]([^']*)'", command.output)[0] matched = [replace_argument(command.script, broken, common_typo) for common_typo in COMMON_TYPOS.get(broken, [])] app = command.script_parts[0] app_commands = cache(which(app))(get_app_commands)(app) matched.extend(replace_command(command, broken, app_commands)) return matched
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_bisect_usage.py
thefuck/rules/git_bisect_usage.py
import re from thefuck.utils import replace_command from thefuck.specific.git import git_support @git_support def match(command): return ('bisect' in command.script_parts and 'usage: git bisect' in command.output) @git_support def get_new_command(command): broken = re.findall(r'git bisect ([^ $]*).*', command.script)[0] usage = re.findall(r'usage: git bisect \[([^\]]+)\]', command.output)[0] return replace_command(command, broken, usage.split('|'))
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/django_south_merge.py
thefuck/rules/django_south_merge.py
def match(command): return 'manage.py' in command.script and \ 'migrate' in command.script \ and '--merge: will just attempt the migration' in command.output def get_new_command(command): return u'{} --merge'.format(command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_push.py
thefuck/rules/git_push.py
import re from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): return ('push' in command.script_parts and 'git push --set-upstream' in command.output) def _get_upstream_option_index(command_parts): if '--set-upstream' in command_parts: return command_parts.index('--set-upstream') elif '-u' in command_parts: return command_parts.index('-u') else: return None @git_support def get_new_command(command): # If --set-upstream or -u are passed, remove it and its argument. This is # because the remaining arguments are concatenated onto the command suggested # by git, which includes --set-upstream and its argument command_parts = command.script_parts[:] upstream_option_index = _get_upstream_option_index(command_parts) if upstream_option_index is not None: command_parts.pop(upstream_option_index) # In case of `git push -u` we don't have next argument: if len(command_parts) > upstream_option_index: command_parts.pop(upstream_option_index) else: # the only non-qualified permitted options are the repository and refspec; git's # suggestion include them, so they won't be lost, but would be duplicated otherwise. push_idx = command_parts.index('push') + 1 while len(command_parts) > push_idx and command_parts[len(command_parts) - 1][0] != '-': command_parts.pop(len(command_parts) - 1) arguments = re.findall(r'git push (.*)', command.output)[-1].replace("'", r"\'").strip() return replace_argument(" ".join(command_parts), 'push', 'push {}'.format(arguments))
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/composer_not_command.py
thefuck/rules/composer_not_command.py
import re from thefuck.utils import replace_argument, for_app @for_app('composer') def match(command): return (('did you mean this?' in command.output.lower() or 'did you mean one of these?' in command.output.lower())) or ( "install" in command.script_parts and "composer require" in command.output.lower() ) def get_new_command(command): if "install" in command.script_parts and "composer require" in command.output.lower(): broken_cmd, new_cmd = "install", "require" else: broken_cmd = re.findall(r"Command \"([^']*)\" is not defined", command.output)[0] new_cmd = re.findall(r'Did you mean this\?[^\n]*\n\s*([^\n]*)', command.output) if not new_cmd: new_cmd = re.findall(r'Did you mean one of these\?[^\n]*\n\s*([^\n]*)', command.output) new_cmd = new_cmd[0].strip() return replace_argument(command.script, broken_cmd, new_cmd)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/python_execute.py
thefuck/rules/python_execute.py
# Appends .py when executing python files # # Example: # > python foo # error: python: can't open file 'foo': [Errno 2] No such file or directory from thefuck.utils import for_app @for_app('python') def match(command): return not command.script.endswith('.py') def get_new_command(command): return command.script + '.py'
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/sudo.py
thefuck/rules/sudo.py
patterns = ['permission denied', 'eacces', 'pkg: insufficient privileges', 'you cannot perform this operation unless you are root', 'non-root users cannot', 'operation not permitted', 'not super-user', 'superuser privilege', 'root privilege', 'this command has to be run under the root user.', 'this operation requires root.', 'requested operation requires superuser privilege', 'must be run as root', 'must run as root', 'must be superuser', 'must be root', 'need to be root', 'need root', 'needs to be run as root', 'only root can ', 'you don\'t have access to the history db.', 'authentication is required', 'edspermissionerror', 'you don\'t have write permissions', 'use `sudo`', 'sudorequirederror', 'error: insufficient privileges', 'updatedb: can not open a temporary file'] def match(command): if command.script_parts and '&&' not in command.script_parts and command.script_parts[0] == 'sudo': return False for pattern in patterns: if pattern in command.output.lower(): return True return False def get_new_command(command): if '&&' in command.script: return u'sudo sh -c "{}"'.format(" ".join([part for part in command.script_parts if part != "sudo"])) elif '>' in command.script: return u'sudo sh -c "{}"'.format(command.script.replace('"', '\\"')) else: return u'sudo {}'.format(command.script)
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/apt_upgrade.py
thefuck/rules/apt_upgrade.py
from thefuck.specific.apt import apt_available from thefuck.specific.sudo import sudo_support from thefuck.utils import for_app enabled_by_default = apt_available @sudo_support @for_app('apt') def match(command): return command.script == "apt list --upgradable" and len(command.output.strip().split('\n')) > 1 @sudo_support def get_new_command(command): return 'apt upgrade'
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/dirty_untar.py
thefuck/rules/dirty_untar.py
import tarfile import os from thefuck.utils import for_app from thefuck.shells import shell tar_extensions = ('.tar', '.tar.Z', '.tar.bz2', '.tar.gz', '.tar.lz', '.tar.lzma', '.tar.xz', '.taz', '.tb2', '.tbz', '.tbz2', '.tgz', '.tlz', '.txz', '.tz') def _is_tar_extract(cmd): if '--extract' in cmd: return True cmd = cmd.split() return len(cmd) > 1 and 'x' in cmd[1] def _tar_file(cmd): for c in cmd: for ext in tar_extensions: if c.endswith(ext): return (c, c[0:len(c) - len(ext)]) @for_app('tar') def match(command): return ('-C' not in command.script and _is_tar_extract(command.script) and _tar_file(command.script_parts) is not None) def get_new_command(command): dir = shell.quote(_tar_file(command.script_parts)[1]) return shell.and_('mkdir -p {dir}', '{cmd} -C {dir}') \ .format(dir=dir, cmd=command.script) def side_effect(old_cmd, command): with tarfile.TarFile(_tar_file(old_cmd.script_parts)[0]) as archive: for file in archive.getnames(): if not os.path.abspath(file).startswith(os.getcwd()): # it's unsafe to overwrite files outside of the current directory continue try: os.remove(file) except OSError: # does not try to remove directories as we cannot know if they # already existed before pass
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false
nvbn/thefuck
https://github.com/nvbn/thefuck/blob/c7e7e1d884d3bb241ea6448f72a989434c2a35ec/thefuck/rules/git_diff_staged.py
thefuck/rules/git_diff_staged.py
from thefuck.utils import replace_argument from thefuck.specific.git import git_support @git_support def match(command): return ('diff' in command.script and '--staged' not in command.script) @git_support def get_new_command(command): return replace_argument(command.script, 'diff', 'diff --staged')
python
MIT
c7e7e1d884d3bb241ea6448f72a989434c2a35ec
2026-01-04T14:38:15.457096Z
false