I'm trying to gather user input in a fish shellscript, particularly of the following oft-seen form:
This command will delete some files. Proceed (y/N)?
After some searching around, I am still not sure how to do this cleanly.
Is these a special way of doing this in fish?
This does the same as the chosen answer but with only one function, seems cleaner to me:
The prompt function can be inlined as such.
The best way I know of is to use the builtin
read
. If you are using this in multiple places you could create this helper function:and use it like this in your scripts/functions:
See documentation for more options: https://fishshell.com/docs/current/commands.html#read
Here's a version with optional, defaulted prompt:
With the help of some fish plugins fisherman and get
To install both, simply in your fish shell
then you can write something like this in your fish function/script