[Pkg-zsh-devel] Bug#969305: Bug#969305: zsh: safe-rm needs to be added to the default path of interactive shells to work

Daniel Shahaf d.s at daniel.shahaf.name
Mon Aug 31 05:41:56 BST 2020


Control: affects -1 safe-rm

Francois Marier wrote on Sun, Aug 30, 2020 at 19:50:10 -0700:
> This isn't really a bug in zsh, but rather I'd like to figure out how to
> best enable the safe-rm package for zsh users.

Thanks!

> As far as I can tell, the equivalent to protect zsh users who choose to
> install safe-rm would be to add the following to /etc/zhs/zshrc:
> 
>   if [[ -d "/usr/share/safe-rm/bin" ]]
>   then
>     PATH="/usr/share/safe-rm/bin:$PATH"
>     export PATH
>   fi

I guess it should be in the zprofile file, guarded by a [[ -o interactive ]] check.

> However, I don't see a way for packages to do this. So I guess there would
> be two ways to make this possible:
> 
> 1. The main /etc/zsh/zshrc script could source all .sh files in a new
>    /etc/zsh/zshrc.d/ directory.
> 2. The /etc/zsh/zshrc that ships in Debian could include the above.
> 
> Are either of these something you'd be willing to consider?

I don't have an opinion one way or the other.

I do note that optionĀ #2 would cause a stat(2) call during shell startup
for everyone who _doesn't_ use safe-rm.  Would that be a problem?
(E.g., slower shell startup)

> Or is there another way to do this that I haven't seen?

Probably not what you had in mind, but my first instinct here is to look
for a shell-independent solution.  For example:

3. Get the OS to add /usr/share/safe-rm/bin to $PATH before the user's
shell is executed in the first place.  (On FreeBSD that'd be
login.conf(5), but I don't know what the Linux equivalent is.)

4. Use dpkg-divert(8) to replace /bin/rm with a wrapper that calls
either safe-rm or the diverted rm binary, depending on whether it's
interactive or not.

> I would really like to make it easy for zsh users to be as protected as
> bash/dash users (i.e. "apt install safe-rm" and you're done).

Thanks!

If you don't already know them, see RM_STAR_SILENT and RM_STAR_WAIT in
zshoptions(1).

Cheers,

Daniel

P.S.  Compare #489646, about providing a directory for packages to drop
completion files into.  (That didn't involve reimplementing
run-parts(1), though; it was just a matter of adding a directory to
a list of directories.)



More information about the Pkg-zsh-devel mailing list