You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Right now it only takes a function name which is a little bit cumbersome if you want to use a custom prompt for a specific use case. The worst part is you have to come up with some name for your prompt and you litter your functions.
Current use case:
functiondangerous_functionfunctioncontinue_promptecho'Do you want to continue? [Y/n]'
end
echo'I will do dangerous stuff'read -l -p continue_prompt continueiftest$continue = 'Y' -o $continue = 'y'echo'Do dangerous stuff'
end
end
If we let -p take a string instead people could use a function if they want by using parenthesis, -p (continue_prompt).
functiondangerous_functionecho'I will do dangerous stuff'read -l -p 'Do you want to continue? [Y/n]'continueiftest$continue = 'Y' -o $continue = 'y'echo'Do dangerous stuff'
end
end
It actually takes arbitrary fishscript, so you can use
functiondangerous_functionecho'I will do dangerous stuff'read -l -p 'echo "Do you want to continue? [Y/n] "'continueiftest$continue = 'Y' -o $continue = 'y'echo'Do dangerous stuff'
end
end
Although I do agree that taking a prompt string is easier and more common.
[crossposting from #2166 where it didn't really belong]
Don't know if a backward-incompatible change can be justified here but:
I wish the current command-to-execute behavior was named something like --prompt-cmd rather than --prompt, -p. Named "prompt" it really sounds like it takes a static string, plus that's exactly what read -p does in bash.
In fact, I don't see any use for the command-to-execute functionality. It's not to be dynamic - I just tested with 'date -Ins' and neither --prompt nor --right-prompt commands are ever re-run during editing.
Actually the standard gradual-deprecation strategy is possible here too:
Add unambiguous --prompt-string and --prompt-command options (plus --right-... variants). -p, --prompt still mean --prompt-command but documentation warns they might change meaning in the future, and recommends the new unambiguous options.
... wait however long we're comfortable with (possible to stop here)...
Make -p, --prompt still mean --prompt-command but also print a warning.
... wait more ...
(In principle, could add here a stage where -p, --prompt are an error, hardly worth it in this case.)
Redefine -p, --prompt to mean --prompt-string.
I'm willing to do the work if you think the gain is worth it.
The current read command API is due to how fish interactive mode works. In other words it is exposing an implementation detail solely because it is used by the read command. Rather than because that implementation detail makes sense in this context.
Outside of the read command the default prompt for reading user input is constructed by calling the fish_prompt function. So the person who implemented read simply required a function name or fish script to be compatible with the implementation for prompting the user for input at the shell's "top level". That is a generalization that is pointless for the read command. Which is to say 99.999% of time anyone invoking read -p does not need the prompt to change based on current conditions. All of the core fish script uses of read -p would work fine if they passed a static string.
We can't break backward compatibility without at least one major release. We can, however, add a saner read flag that accepts a simple string for the left prompt. Such as a -P and --prompt-string flag as proposed by @cben.
Nonetheless, that flexibility is overkill most of the time and simply confuses the script writer trying to prompt someone for input. So it makes sense to provide a simpler UI that satisfies 98% of the read uses.
Activity
rominf commentedon Apr 4, 2014
I think it can be closed as it already implemented.
sugar700 commentedon Apr 4, 2014
@rominf: Huh? Aware of any feature to do so, other than
read -p 'echo "Do you want to continue? [Y/n]"'?rominf commentedon Apr 4, 2014
Sorry, I misread issue. 😞 Yes, you are right. I wish that feature too.
lilyball commentedon Sep 22, 2014
It actually takes arbitrary fishscript, so you can use
Although I do agree that taking a prompt string is easier and more common.
cben commentedon Feb 12, 2016
[crossposting from #2166 where it didn't really belong]
Don't know if a backward-incompatible change can be justified here but:
I wish the current command-to-execute behavior was named something like
--prompt-cmdrather than--prompt,-p. Named "prompt" it really sounds like it takes a static string, plus that's exactly whatread -pdoes in bash.In fact, I don't see any use for the command-to-execute functionality. It's not to be dynamic - I just tested with 'date -Ins' and neither --prompt nor --right-prompt commands are ever re-run during editing.
cben commentedon Feb 12, 2016
Actually the standard gradual-deprecation strategy is possible here too:
--prompt-stringand--prompt-commandoptions (plus--right-...variants).-p,--promptstill mean--prompt-commandbut documentation warns they might change meaning in the future, and recommends the new unambiguous options.-p,--promptstill mean--prompt-commandbut also print a warning.(In principle, could add here a stage where
-p,--promptare an error, hardly worth it in this case.)-p,--promptto mean--prompt-string.I'm willing to do the work if you think the gain is worth it.
krader1961 commentedon Mar 25, 2017
The current
readcommand API is due to how fish interactive mode works. In other words it is exposing an implementation detail solely because it is used by thereadcommand. Rather than because that implementation detail makes sense in this context.Outside of the
readcommand the default prompt for reading user input is constructed by calling thefish_promptfunction. So the person who implementedreadsimply required a function name or fish script to be compatible with the implementation for prompting the user for input at the shell's "top level". That is a generalization that is pointless for thereadcommand. Which is to say 99.999% of time anyone invokingread -pdoes not need the prompt to change based on current conditions. All of the core fish script uses ofread -pwould work fine if they passed a static string.We can't break backward compatibility without at least one major release. We can, however, add a saner
readflag that accepts a simple string for the left prompt. Such as a-Pand--prompt-stringflag as proposed by @cben.krader1961 commentedon Mar 26, 2017
I want to reinforce that the current
-p/--promptflag accepts arbitrary fish script. In fact the default prompt if you don't specify one is this:Nonetheless, that flexibility is overkill most of the time and simply confuses the script writer trying to prompt someone for input. So it makes sense to provide a simpler UI that satisfies 98% of the
readuses.let `read` take a simple string for the prompt
Pysis868 commentedon Jun 16, 2017
woo!!
GitHub - fish-shell/fish-shell - fish 2.6.0 (released June 3, 2017):