如何使ZSH自动完成删除后斜线返回?

发布于 2025-02-13 19:30:38 字数 357 浏览 0 评论 0原文

我有一个自定义脚本,该脚本将一个参数传递到该参数中,该参数将在特定文件夹中创建一个目录,然后将其CD在其中创建,除非它已经存在,否则它只是CD。

如果我想使用命令将命令跳到该文件夹​​中的目录,我可以自动完成目标文件夹并以更少的键击(键)来完成,我会以这种方式添加ZSH自动完成。我的ZSH自动完成的唯一问题是,它在自动完成后留下了尾部目录斜线。有什么办法告诉ZSH只返回目录的名称并离开 /关闭?文档长期存在,我的搜索并没有发现任何有用的东西。

这是我的ZSH自动完成

compdef'_path_files -w/home/me/dir1/dir2/folder-/&&返回0 ||返回1'mycommand

I have a custom script that I pass an argument into that will create a directory in a specific folder and then cd to it, unless it already exists, then it just cd to it.

I added a zsh autocompletion that way if I want to use the command to just jump to a directory in that folder I can autocomplete the target folder and get there in less keystrokes. The only issue with my zsh autocomplete is that it leaves the tailing directory slash after the autocomplete. Is there any way to tell zsh to only return the name of the directory and leave the / off? The docs are long winded and my searching has not turned up anything useful.

Here is my zsh autocomplete

compdef '_path_files -W /home/me/dir1/dir2/folder -/ && return 0 || return 1' mycommand

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文