shell - 防止fish命令通过fish_preexec执行
问题描述
我想预处理所有发送给鱼的命令。我知道这可以通过 来完成fish_preexec
,因为它将文字命令作为参数传递。但是,我也想防止在某些条件下完全执行命令。我不想退出鱼壳;我想保持当前的 shell 活着,只打印一条"command not executed"
消息。
鱼支持这样的东西吗?
解决方案
这很棘手,但您可以通过将 enter 键重新绑定到自定义函数来做到这一点,如下所示:
function execute_ifnotls
if test (commandline) = 'ls'
echo
echo "No"
commandline ""
commandline -f repaint
else
commandline -f execute
end
end
bind \r execute_ifnotls
bind \n execute_ifnotls
产生:
> ls
No
> whoami
david
推荐阅读
- cryptography - 散列文件期间考虑的参数
- php - MySql 数据库应该有一个表还是多个表?
- mongodb - 按电子邮件地址分组不适用于 php 中的 mongodb
- python - TensorFlow How to Initialize Global Step
- angular - canDeactivate 与 Observable
- c++ - 为什么在 C/C++ 中可以多次包含标头?
- python - 从 VBA 启动时导入 python 模块
- react-native - 手机APP认证匹配手机号有哪些安全隐患?
- mysql - 删除此查询中的联合,仍然得到相同的结果
- azure - PowerShell script for restoring the Azure SQL Database from Azure File share