zsh中的多点路径,如cd .... [英] Multi-dot paths in zsh, like `cd ....`

查看:130
本文介绍了zsh中的多点路径,如cd ....的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所有shell都可以理解以下命令:

All shells understand these commands:

$ cd .
$ cd ..

zsh也可以理解:

$ cd ...
$ cd ....

假设您说:

$ alias -g ...='../..'
$ alias -g ....='../../..'

现在,当我开始键入cd ..../<TAB>时,如何使它完成正确的制表符填充?我记得它是在oh-my-zsh中实现的,但是我现在已经停止使用它.

Now, how can I make it do proper tab-completion when I've started typing cd ..../<TAB>? I recall it was implemented in oh-my-zsh but I've stopped using it now.

如果它不仅适用于cd,例如我想执行cat ..../a/b/..../c/d | less,也将不胜感激.

It would also be appreciated if it would work not only for cd, say I want to execute cat ..../a/b/..../c/d | less.

推荐答案

我要处理相同问题的方法是,当我键入...时让zsh填写../..并将其扩展是有意义的以这种方式.它可能适合您(或不适合:-P):

What I did to to deal with the same problem is to just let zsh fill in ../.. when I type ... and it makes sense to expand it in that way. It may suit you (or not :-P):

if is-at-least 5.0.0 && [[ ! $UID -eq 0 ]]; then                                                                                                                             
  ## http://www.zsh.org/mla/users/2010/msg00769.html                                                                                                                       
  function rationalise-dot() {                                                                                                                                             
    local MATCH # keep the regex match from leaking to the environment                                                                                                   
    if [[ $LBUFFER =~ '(^|/| |      |'$'\n''|\||;|&)\.\.$' && ! $LBUFFER = p4* ]]; then                                                                                  
        #if [[ ! $LBUFFER = p4* && $LBUFFER = *.. ]]; then                                                                                                               
        LBUFFER+=/..                                                                                                                                                     
    else                                                                                                                                                                 
        zle self-insert                                                                                                                                                  
    fi                                                                                                                                                                   
}                                                                                                                                                                        
zle -N rationalise-dot                                                                                                                                                   
bindkey . rationalise-dot                                                                                                                                                
bindkey -M isearch . self-insert                                                                                                                                         
fi

我也有...的别名,但它不是全局的.

I also have an alias for ..., but it is not global.

注意,我检查命令行是否以p4(Perforce命令行工具)开头,并且在这种情况下不要搞乱,因为Perforce参数通常涉及文字....如果您不使用p4,则显然可以删除该支票.

Notice I check if the command line starts with p4 (the Perforce command line tool) and do not mess with it in that case, as Perforce arguments often involve literal .... If you do not use p4 you can obviously remove that check.

这篇关于zsh中的多点路径,如cd ....的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆