Fix fish shell integration when prompt function doesn't return anything #288
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.