welp 0.1.0

Fixes the command you just typed wrong. A fast successor to thefuck.
welp-0.1.0 is not a library.
$ gti push
zsh: command not found: gti
$ welp
git push [enter/↑/↓/ctrl+c]
fatal: The current branch feature has no upstream branch.
$ welp
git push --set-upstream origin feature [enter/↑/↓/ctrl+c]

Why welp

thefuck is one of the most-loved command-line tools ever made, but it has had no release since January 2022 and breaks on Python 3.12 and newer (No module named 'imp'). welp keeps what made it great and fixes what didn't:

  • No Python. One small binary that starts instantly, on any Python version or none.
  • Safe. welp never runs destructive or interactive commands (rm, mv, dd, editors, ssh, ...) a second time just to read their output. Rules that need to know more look at your files instead.
  • Moves your setup for you. welp migrate switches your shell config, keeps your alias (yes, fuck still works) and imports your settings.
  • Same rule names. Your thefuck exclude_rules keep working.
  • Workplace-friendly name. Use whatever alias you like.

Install

cargo install welp

Homebrew and prebuilt binaries are coming.

Set up

Add one line to your shell config, then open a new terminal:

Shell Line File
zsh eval "$(welp init zsh)" ~/.zshrc
bash eval "$(welp init bash)" ~/.bashrc
fish welp init fish | source ~/.config/fish/config.fish

Prefer another word? Add --alias, for example eval "$(welp init zsh --alias oops)".

Coming from thefuck

welp migrate --dry-run   # see what would change
welp migrate             # do it

It comments out the thefuck lines in your shell config (with a backup next to each file), adds welp in their place with your alias, and turns ~/.config/thefuck/settings.py into ~/.config/welp/config.toml.

Rules

Rule What it fixes
no_command A mistyped program name: gti → git
git_not_command A mistyped git subcommand: git comit → git commit
git_push Sets the upstream when a new branch has none
git_pull Sets the tracking branch, then pulls
git_checkout Creates the branch when it does not exist yet
git_branch_delete -d → -D for a branch that is not merged
git_commit_add Stages changed files when a commit has nothing staged
did_you_mean Uses the fix a tool suggests: cargo, npm, pip, brew, gh and more
sudo Runs the command again with sudo after "permission denied"
chmod_x Makes a script executable before running it
apt_get Installs a missing program the system names, then runs it
cd_mkdir Creates the folder you tried to cd into
cd_parent cd.. → cd ..
mkdir_p Adds -p when parent folders are missing
cp_omitting_directory Adds -r to copy a folder
rm_dir Adds -r to remove a folder
grep_recursive Adds -r to search a folder
touch Creates missing folders, then the file
sl_ls sl → ls

welp rules lists them. More of thefuck's 170 rules are being ported. Pull requests are welcome.

Settings

~/.config/welp/config.toml (or $XDG_CONFIG_HOME/welp/config.toml):

require_confirmation = true   # false runs the first fix straight away
wait_command = 3              # seconds to wait when reading a command's output
wait_slow_command = 15
slow_commands = ["lein", "react-native", "gradle", "./gradlew", "vagrant"]
no_rerun = ["rm", "mv", "dd", "vim", "ssh"]  # never run these twice (the full default list is longer)
exclude_rules = []

Adding a rule

A rule is a name, a check and a fix, in src/rules/. Each comes with a test that feeds it a command and the output a real tool printed:

Rule {
    name: "mkdir_p",
    description: "Adds -p when parent folders are missing",
    priority: 1000,
    matches: |c| c.is("mkdir") && c.output_lower().contains("no such file or directory"),
    fixes: |c| vec![c.replace_word("mkdir", "mkdir -p")],
},

Run cargo test before opening a pull request.

The demo above is a real session: demo/record.sh sets up a throwaway repo and types the commands into zsh.

Support

If welp saves you some typing, you can buy me a coffee or come hang out on Discord.

Credits

welp's rules are ports of thefuck's, by Vladimir Iakovlev and its contributors (MIT). welp is not affiliated with thefuck.

License

MIT