Skip to content

Let read builtin take a custom prompt string #802

Description

@terlar

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:

function dangerous_function
  function continue_prompt
    echo 'Do you want to continue? [Y/n]'
  end

  echo 'I will do dangerous stuff'
  read -l -p continue_prompt continue

  if test $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).

function dangerous_function
  echo 'I will do dangerous stuff'
  read -l -p 'Do you want to continue? [Y/n]' continue

  if test $continue = 'Y' -o $continue = 'y'
    echo 'Do dangerous stuff'
  end
end

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions