1
我想添加到我的.zshrc函数中,该函数将对具有“.c”后缀的文件执行操作。例如,“* .foo”shell函数
*.c() {
gcc $0 -o ${0%.*}
}
必须执行“文件foo.c的gcc -o foo”的,当我进入“foo.c的”
但是,当我添加了这个功能,“.zshrc”,我的壳开始打印“登录时找不到匹配项:* .c”。
我可以用其他方式做这个或者使这个函数“懒”吗?
我想添加到我的.zshrc函数中,该函数将对具有“.c”后缀的文件执行操作。例如,“* .foo”shell函数
*.c() {
gcc $0 -o ${0%.*}
}
必须执行“文件foo.c的gcc -o foo”的,当我进入“foo.c的”
但是,当我添加了这个功能,“.zshrc”,我的壳开始打印“登录时找不到匹配项:* .c”。
我可以用其他方式做这个或者使这个函数“懒”吗?
您需要alias -s
行为。从手册页:
ALIASES
Suffix aliases are supported in zsh since version 4.2.0. Some examples:
alias -s tex=vim
alias -s html=w3m
alias -s org=w3m
Now pressing return-key after entering foobar.tex starts vim with foobar.tex. Calling
a html-file runs browser w3m. www.zsh.org and pressing enter starts w3m with argument
www.zsh.org.
将您的书面功能结合到后缀别名,你应该设置去!
首先,在写这份表单功能:
compile_c() {
gcc $1 -o ${1%.*}
}
然后后缀别名预期
alias -s c='compile_c'
会工作。
它不工作,因为$ 0,$ 1,$ 2变量没有在别名中定义 – user123980801 2011-04-14 17:04:30
@ user123980801我认为这是progo的意思:'__gcc_compile(){gcc $ 1 -o $ {1%。*}};别名-s c = __ gcc_compile' - 这适用于zsh 4.3.11。 – yibe 2011-04-14 17:36:57
是的,它的作品,看我的例子。 – progo 2011-04-14 17:37:43