Skip to content

geoffyoon-dev/smartass-python

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

4 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Smartass-python Version Build Status Coverage MIT License

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.

gif with examples

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
...

Contents

Requirements

  • python (3.5+)
  • pip
  • python-dev

Installation

pip install -r requirements.txt
python setup.py install

It 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).

How it works

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.

Settings

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 default True;
  • 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 lower priority will be matched first;
  • debug – enables debug output, by default False;
  • history_limit – the numeric value of how many history commands will be scanned, like 2000;
  • alter_history – push fixed command to history, by default True;
  • wait_slow_command – max amount of time in seconds for getting previous command output if it in slow_commands list;
  • 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, like no_command=9999:apt_get=100, rule with lower priority will be matched first;
  • SMARTASS__DEBUG – enables debug output, true/false;
  • SMARTASS_HISTORY_LIMIT – how many history commands will be scanned, like 2000;
  • SMARTASS_ALTER_HISTORY – push fixed command to history true/false;
  • SMARTASS_WAIT_SLOW_COMMAND – the max amount of time in seconds for getting previous command output if it in slow_commands list;
  • SMARTASS_SLOW_COMMANDS – list of slow commands, like lein:gradle;
  • SMARTASS_NUM_CLOSE_MATCHES – the maximum number of close matches to suggest, like 5.
  • 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'

License MIT

Project License can be found here.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published