Inspired by The fuck, a great app for fixing errors in previous console commands, Smartass is an app that uses an LLM rather than a rule base to fix errors in previous console commands.
More examples:
➜ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
➜ damn
sudo apt-get install vim [enter/↑/↓/ctrl+c]
[sudo] password for ubuntu:
Reading package lists... Done
...➜ git push
fatal: The current branch main has no upstream branch.
To push the current branch and set the remote as upstream, use
git push --set-upstream origin main
➜ damn
git push --set-upstream origin main [enter/↑/↓/ctrl+c]
Counting objects: 9, done.
...➜ puthon
No command 'puthon' found, did you mean:
Command 'python' from package 'python-minimal' (main)
Command 'python' from package 'python3' (main)
zsh: command not found: puthon
➜ damn
python [enter/↑/↓/ctrl+c]
Python 3.4.2 (default, Oct 8 2014, 13:08:17)
...➜ git brnch
git: 'brnch' is not a git command. See 'git --help'.
Did you mean this?
branch
➜ damn
git branch [enter/↑/↓/ctrl+c]
* main➜ lein rpl
'rpl' is not a task. See 'lein help'.
Did you mean this?
repl
➜ damn
lein repl [enter/↑/↓/ctrl+c]
nREPL server started on port 54848 on host 127.0.0.1 - nrepl://127.0.0.1:54848
REPL-y 0.3.1
...If you're not afraid of blindly running corrected commands, the
require_confirmation settings option can be disabled:
➜ apt-get install vim
E: Could not open lock file /var/lib/dpkg/lock - open (13: Permission denied)
E: Unable to lock the administration directory (/var/lib/dpkg/), are you root?
➜ damn
sudo apt-get install vim
[sudo] password for ubuntu:
Reading package lists... Done
...- python (3.5+)
- pip
- python-dev
pip install -r requirements.txt
python setup.py installIt is recommended that you place this command in your .bash_profile,
.bashrc, .zshrc or other startup script:
eval $(smartass --alias)Or in your shell config (Bash, Zsh, Fish, Powershell, tcsh).
Changes are only available in a new shell session. To make changes immediately
available, run source ~/.bashrc (or your shell config file like .zshrc).
Smartass generates new commands and executes them via LLM over previous commands. The LLMs we currently support are as follows:
Gemini– Google's LLM, developed by Google Deepmind and served through GCP.
Several Smartass parameters can be changed in the file $XDG_CONFIG_HOME/thefuck/settings.py
($XDG_CONFIG_HOME defaults to ~/.config):
require_confirmation– requires confirmation before running new command, by defaultTrue;wait_command– the max amount of time in seconds for getting previous command output;no_colors– disable colored output;priority– dict with rules priorities, rule with lowerprioritywill be matched first;debug– enables debug output, by defaultFalse;history_limit– the numeric value of how many history commands will be scanned, like2000;alter_history– push fixed command to history, by defaultTrue;wait_slow_command– max amount of time in seconds for getting previous command output if it inslow_commandslist;slow_commands– list of slow commands;excluded_search_path_prefixes– path prefixes to ignore when searching for commands, by default[].provider– LLM model provider.model– The name of LLM model for fix commands.api_key– This is the token or API key that authenticates to use the LLM API.
An example of settings.py:
wait_command = 3
require_confirmation = True
no_colors = False
debug = False
priority = {}
history_limit = None
alter_history = True
wait_slow_command = 15
slow_commands = ['lein', 'react-native', 'gradle', './gradlew', 'vagrant']
repeat = False
instant_mode = False
env = {'LC_ALL': 'C', 'LANG': 'C', 'GIT_TRACE': '1'}
excluded_search_path_prefixes = []
provider = google
model = gemini-1.5-flash
api_key = 'i0GSp7UelXASFAIzaSyCciEmlTdYE_NEFfA'Or via environment variables:
SMARTASS_REQUIRE_CONFIRMATION– require confirmation before running new command,true/false;SMARTASS_WAIT_COMMAND– the max amount of time in seconds for getting previous command output;SMARTASS_NO_COLORS– disable colored output,true/false;SMARTASS_PRIORITY– priority of the rules, likeno_command=9999:apt_get=100, rule with lowerprioritywill be matched first;SMARTASS__DEBUG– enables debug output,true/false;SMARTASS_HISTORY_LIMIT– how many history commands will be scanned, like2000;SMARTASS_ALTER_HISTORY– push fixed command to historytrue/false;SMARTASS_WAIT_SLOW_COMMAND– the max amount of time in seconds for getting previous command output if it inslow_commandslist;SMARTASS_SLOW_COMMANDS– list of slow commands, likelein:gradle;SMARTASS_NUM_CLOSE_MATCHES– the maximum number of close matches to suggest, like5.SMARTASS_EXCLUDED_SEARCH_PATH_PREFIXES– path prefixes to ignore when searching for commands, by default[].
For example:
export SMARTASS_REQUIRE_CONFIRMATION='true'
export SMARTASS_WAIT_COMMAND=10
export SMARTASS_NO_COLORS='false'
export SMARTASS_HISTORY_LIMIT='2000'
export SMARTASS_NUM_CLOSE_MATCHES='5'
export SMARTASS_PROVIDER='google'
export SMARTASS_MODEL='gemini-1.5-flash'
export SMARTASS_API_KEY='i0GSp7UelXASFAIzaSyCciEmlTdYE_NEFfA'Project License can be found here.
