has icon indicating copy to clipboard operation
has copied to clipboard

HAS_ALLOW_UNSAFE only checks lowercase

Open virgilwashere opened this issue 6 years ago • 2 comments

Needs to be case insenstive ([Yy]) or just an existence check [[ -v HAS_ALLOW_UNSAFE ]]

virgilwashere avatar May 22 '19 13:05 virgilwashere

+1 for case insensitivity Just existence check might break for someone trying HAS_ALLOW_UNSAFE=N, if we really need to go that route, I would choose a different evn variable name then

kdabir avatar May 26 '19 16:05 kdabir

Will make it a command line option too.

  • [X] has -u sets HAS_ALLOW_UNSAFE=yes to reuse code below

..when I get to #36 😀

How's this?

  • [X] keep HAS_ALLOW_UNSAFE so no Breaking Change

  • [x] not Bash 4.x dependent (where extglob is default on)

  • [x] save and restore existing shopt

  • [x] case insensitive "y"

    • [x] optional "es"
  ## probably cannot use ${var,,} for lowercase because: darwin
  ## save extglob nocasematch current
  p_shopt=$( shopt -p extglob nocasematch ) && shopt -s extglob nocasematch 
  if [[ "${HAS_ALLOW_UNSAFE}" = "y?(es)" ]]; then
    ...
  fi
  eval "${p_shopt[@]}"

Or, to support HAS_ALLOW_UNSAFE=true

if [[ "${HAS_ALLOW_UNSAFE}" =~ ^(true|y?(es)|only_thursday)$ ]]; then
  printf '%s in list.\n' "${HAS_ALLOW_UNSAFE}"
  # true
fi

virgilwashere avatar Jun 05 '19 05:06 virgilwashere