Zsh Mailing List Archive
Messages sorted by: Reverse Date, Date, Thread, Author

Re: zsh detects rm * but not rm ** (multiple stars)



On Mar 13,  5:26pm, Amm wrote:
} Subject: zsh detects rm * but not rm ** (multiple stars)
}
} But I suppose match should not just be on single *
} but on *+ (1 or more *)

Thanks for the suggestion.  The "rm *" behavior is very old (was in
the shell even before the special meaning of "**", something over 20
years ago now) and hasn't changed in all that time, so I can't say
with any confidence it'll change now.  It probably wouldn't have been
included in the first place if the shell then had some of the other
features that have been added since.
 
} Also is there a way to make zsh warn when there is * in
} argument list, regardless of command?

I think most people would just find this annoying :-) and it's hard
to emit a sensible prompt when you don't know what's going to be done
with the result.  However:

zle-line-finish() {
  emulate -R zsh -o extendedglob -o localoptions
  local words stars ask yes
  words=( ${(Z{c})BUFFER} )
  [[ -o interactivecomments ]] && words=( ${words%(#s)\#*} )
  stars=( ${(M)words#((#s)[*]|*/[*]##)(#e)} )
  for ask in $stars
  do
    read -q yes$'?\n'"zsh: sure you want to pass $ask [n/y]?"
    if [[ $yes != y ]]
    then
      zle -I
      zle push-input
      zle send-break
    fi
  done
  (( $#stars )) && zle -I
}
zle -N zle-line-finish

This behaves the way you wanted, aborting the entire command on any
"no" answer (but leaving it in the editor for you to fix, which you
didn't ask for but seemed reasonable).

The placement of "zle -I" here is critical for reasons that are most
likely a bug.

-- 
Barton E. Schaefer



Messages sorted by: Reverse Date, Date, Thread, Author