gpt4 book ai didi

zsh - 在 zsh 中确认 rm

转载 作者:行者123 更新时间:2023-12-02 13:23:07 25 4
gpt4 key购买 nike

在发现“trash-put”之后,我想训练自己在大多数情况下使用它而不是“rm”。如果我只是给它起别名,可能会让我在没有配置文件的机器上感到太安全,所以我想出了以下内容(在我的 .zshrc 中):

function rm() {
local go_ahead
read -q "go_ahead?Are you sure you don't want to use rms? (y/n)"
echo ""
if [[ "$go_ahead" == "y" ]]; then
/bin/rm $*
fi
}
alias rms='trash-put'

它似乎有效,但我对 zsh 脚本编写没有太多经验...这是实现我想要的功能的好方法吗?

谢谢彼得

最佳答案

那么,为什么要创建一个函数和别名而不是简单地:

alias rm="rm -i"

或者以其他方式改造您的 rm,使其成为:

function rm() {
local go_ahead
read -q "Are you sure you don't want to use trash-put? [y/N]"
echo ""
if [[ "$go_ahead" = "y" ]]; then
/bin/rm $*
else
/usr/bin/env trash-put $*
fi
}

如果您不说y,它就会运行trash-put

关于zsh - 在 zsh 中确认 rm,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21453185/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com