nvbn / thefuck

Magnificent app which corrects your previous console command.
MIT License
83.59k stars 3.41k forks source link

[fish] Some command output is missing #1346

Open asportnoy opened 1 year ago

asportnoy commented 1 year ago

The Fuck 3.32 Python 3.10.8 Fish Shell 3.5.1 macOS Ventura

I'm trying to create a rule to catch suggestions from fish for a command to try. An example:

> set -x name=value
set: name=value: invalid variable name. See `help identifiers`
set: Did you mean `set name value`?
(Type 'help set' for related documentation)

# desired response from thefuck, does not currently work
> fuck
set name value

However, after some debugging, I found that command.output is empty for some reason. This isn't the only anomaly like that; I also found that command.output for fish's command not found message is /bin/sh: x: command not found instead of fish: Unknown command: x (what shows in terminal). This leads me to believe that thefuck is trying to read some internal output instead of what Fish is actually outputting to the user.

For reference, here's my WIP rule:

import re;

regex = r'Did you mean `(.*)`'

def match(command):
    return re.match(regex, command.output)

def get_new_command(command):
    return re.match(regex, command.output).group(1)

And to debug the output, I used

def match(command):
    return True

def get_new_command(command):
    return command.output
asportnoy commented 1 year ago

I should mention that I was able to make that rule by matching the script instead of the output, but I'd prefer to be able to do it with the output since that should work with more commands than just this one.

flowchartsman commented 1 year ago

I am having a similar issue. I am unable to create any rules which match the output of the previous command, which makes some rules impossible.