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

Fix fish shell integration when prompt function doesn't return anything #288

Merged
merged 1 commit into from
Oct 4, 2024

Conversation

dberlin
Copy link
Contributor

@dberlin dberlin commented Sep 21, 2024

The current integration printf's the user's prompt function as if it was a format string.
However, as the documentation for fish's printf builtin says:
" It will also return non-zero if no argument at all was given, in which case it will print nothing"

The result is that there are plenty of cases where the printf function will print nothing at all when the prompt function does not return anything. This is true despite using command substitution to try to get the output as a string.

This is all AFAICT, it's tricky to figure out exactly what happens.

Put another way, this will work fine:

function fish_prompt; printf (__is_prompt_start); printf %s (is_user_prompt); printf (__is_prompt_end); end

This will also work fine:
function fish_prompt; printf (__is_prompt_start); is_user_prompt; printf (__is_prompt_end); end

What exists now:
function fish_prompt; printf (__is_prompt_start); printf (is_user_prompt); printf (__is_prompt_end); end will not always work.

It will result in displaying no user prompt in a large number of cases.

A screenshot is attached where you can see what happens. The printf returns and displays nothing.
both evaluation, and printf with %s + command substitution display the user prompt.

The same is technically true of the other two printfs, but for some reason they always seem to display output.
I wish i could say with certainty why this is. However, one thing i can say with certainty - it will always be correct to simply execute the functions without printfs.
Internally, fish executes the prompt function in a subshell into a buffer and then displays it.

So we do that for the user prompt. I am happy to do it with the other two functions as well.

Screenshot_20240921_140318

@cpendery
Copy link
Member

The same is technically true of the other two printfs, but for some reason they always seem to display output. I wish i could say with certainty why this is. However, one thing i can say with certainty - it will always be correct to simply execute the functions without printfs. Internally, fish executes the prompt function in a subshell into a buffer and then displays it.

I think this is because the __is_prompt functions always have output. Lets remove all the printfs and just using function invocations for all 3, that sounds like a better option. Thanks for the PR and detailed write up!

Instead of assuming printf will print the prompt, just evaluate the prompt functions.
This is what fish itself does.
@dberlin
Copy link
Contributor Author

dberlin commented Sep 26, 2024

The same is technically true of the other two printfs, but for some reason they always seem to display output. I wish i could say with certainty why this is. However, one thing i can say with certainty - it will always be correct to simply execute the functions without printfs. Internally, fish executes the prompt function in a subshell into a buffer and then displays it.

I think this is because the __is_prompt functions always have output. Lets remove all the printfs and just using function invocations for all 3, that sounds like a better option. Thanks for the PR and detailed write up!

done.

@cpendery cpendery merged commit 2012335 into microsoft:main Oct 4, 2024
10 checks passed
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

Successfully merging this pull request may close these issues.

2 participants