我正在从 ZSH 迁移到 Fish,我唯一还没弄清楚的是我的c功能:
函数/c:
#!/bin/sh
cd "$PROJECTS/$1"
Run Code Online (Sandbox Code Playgroud)
函数/_c:
#compdef c
_files -W $PROJECTS -/
Run Code Online (Sandbox Code Playgroud)
这在 ZSH 上运行得很好,我可以输入c <tab>并且完成它,就像我cd $PROJECTS直接做一样。
在鱼上,我创建了c.fish这样的:
function c
cd $PROJECTS/$argv
end
complete --command c --no-files --arguments='(find $PROJECTS -mindepth 1 -maxdepth 2)'
Run Code Online (Sandbox Code Playgroud)
但正如您可以想象的那样,它不能像 ZSH 版本一样工作,因为完成操作不知道$argv,并且不会完成第一个文件夹之后的操作。
有没有办法在 Fish 中做同样的事情?
我考虑过创建一个abbr,但我真的很喜欢今天在 ZSH 上的方式。
如果c应该像set tocd一样,这是一种方法:$PWD$PROJECTS
function c_complete
# get the argument to 'c'
set arg (commandline -ct)
# save our PWD
set saved_pwd $PWD
# cd to $PROJECTS (and then back after)
# while in $PROJECTS, complete as if we are 'cd'
builtin cd $PROJECTS
and complete -C"cd $arg"
builtin cd $saved_pwd
end
complete --command c --arguments '(c_complete)'
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
635 次 |
| 最近记录: |