Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Running fuck from command_not_found_handle Not Working Right #875

Open
alexclst opened this issue Jan 13, 2019 · 2 comments
Open

Running fuck from command_not_found_handle Not Working Right #875

alexclst opened this issue Jan 13, 2019 · 2 comments

Comments

@alexclst
Copy link

First of all, fuck is genius. Thanks a lot.

The only thing that’d make it better is to have no need to call it directly. I’m on macOS Mojave, but manually installed and am using the latest bash shell using Homebrew, which allows you to configure your own function to run when commands aren’t found, command_not_found_handle().

My version of this, that I’d like to work is:

command_not_found_handle() {
	/usr/local/bin/fuck
}

Doing this produces the following output, as if fuck isn’t set up:

**Seems like fuck alias isn't configured!
Please put eval $(thefuck --alias) in your ~/.bashrc and apply changes with source ~/.bashrc or restart your shell.
Or run fuck second time for configuring it automatically.
More details - https://github.com/nvbn/thefuck#manual-installation**

I do have the eval $(thefuck --alias) line in my bash profile. It just seems that when run from the command_not_found_handle() bash isn’t using that. fuck does work as expected when run directly.

Is there any way I can get this to work as desired? Or does this need fixing in fuck itself? Not sure if this is a fuck bug, bash bug, or just something that I need help to configure correctly.

The output of fuck -v as it is requested:

The Fuck 3.28 using Python 3.7.2 and Bash 5.0.0(1)-release
@alexclst
Copy link
Author

alexclst commented Jan 13, 2019

Ok, so I’ve done some more digging. If I run /usr/local/bin/thefuck $@ in my handler it will run. However, it in turn will not run the selected command. So, my command_not_found_handle() will produce this output:

d /usr/local/
id /usr/local/ [enter/↑/↓/ctrl+c]           
id /usr/local/

It will run thefuck, but the command I pick there only gets printed out, not run. Whereas, running fuck myself right afterwards I get what is expected:

fuck
id /usr/local/ [enter/↑/↓/ctrl+c]           
id: /usr/local/: no such user

It has run the command selected via fuck. But my handler, for some reason, is not running the command, but rather just printing it.

@stek29
Copy link

stek29 commented May 2, 2020

For bash:

command_not_found_handle () {
    TF_SHELL_ALIASES=$(alias);
    TF_CMD=$(
        export TF_SHELL_ALIASES;
        export TF_SHELL=bash;
        export TF_ALIAS=fuck;
        export TF_HISTORY="$@";
        export PYTHONIOENCODING=utf-8;
        thefuck THEFUCK_ARGUMENT_PLACEHOLDER
    ) && eval $TF_CMD;
    test -n "$TF_CMD" && history -s "$TF_CMD";
}

for zsh:

command_not_found_handler () {
    TF_SHELL_ALIASES=$(alias);
    TF_CMD=$(
        export TF_SHELL_ALIASES;
        export TF_SHELL=zsh;
        export TF_ALIAS=fuck;
        export TF_HISTORY="$@";
        export PYTHONIOENCODING=utf-8;
        thefuck THEFUCK_ARGUMENT_PLACEHOLDER
    ) && eval $TF_CMD;
    test -n "$TF_CMD" && print -s $TF_CMD;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants