Fka*_*Fka 10 command-line cd-command
我有许多文件夹的工作区,所有文件夹都由长路径组成。例如:
|- workspace
|-- this.is.very.long.name.context
|-- this.is.another.long.path.authors
|-- // 20 more folders
|-- this.is.folder.with.too.many.characters.folder
Run Code Online (Sandbox Code Playgroud)
它们都以相同的阶段 ( this.is) 开始,在我的实际情况下,该阶段是 20 个字符长,并且它们在最后一个序列中大多不同。有什么方法可以使用cd命令快速浏览它们吗?任何野生字符像??
Ste*_*art 27
我不能代表其他人(例如zsh),但如果您使用的是bash,通配符在一定程度上确实有效。例子:
~ $ ls
Documents
Desktop
Downloads
Run Code Online (Sandbox Code Playgroud)
如果使用星号 ( *),则会得到:
~ $ cd *ments
~/Documents $
Run Code Online (Sandbox Code Playgroud)
那是因为bash可以在命令到达cd.
在 的情况下cd,如果多个匹配项起作用,您会期望行为未定义:
~ $ cd *s
bash: cd: too many arguments
Run Code Online (Sandbox Code Playgroud)
bash将其扩展为cd Documents Downloads,这对 没有意义cd。
您还可以依赖bash的自动完成功能。在您的示例中,您只需键入cd t; 然后点击Tab将自动完成为:cd this.is.或下一个不明确的字符是什么。Tab再次点击以查看此过滤集中的所有选项。
您可以重复输入另一个字符以缩小范围, Tab自动完成下一个不明确的字符,然后Tab查看所有选项。
更进一步,bash可以在自动完成中处理通配符。在上面的第一种情况下,您可以输入cd D*s然后点击Tab以获取与模式匹配的建议:
~ $ cd D*s
Documents/ Downloads/
~ $ cd D*s
Run Code Online (Sandbox Code Playgroud)
如果只存在一场比赛,它将为您完成。
~ $ cd *loads
~ $ cd Downloads/
Run Code Online (Sandbox Code Playgroud)
ls如果您不介意在有问题的目录中,您也可以使用。该-d通知ls以列出目录本身,而不是它们的内容。
$ ls -d *long*
this.is.very.long.name.context
this.is.another.long.path.authors
Run Code Online (Sandbox Code Playgroud)
或者,find如果您想递归查看,可以使用:
$ find workspace -type d -name '*long*'
workspace/this.is.very.long.name.context
workspace/this.is.another.long.path.authors
Run Code Online (Sandbox Code Playgroud)
使用zsh,您可以使用zstyles配置完成系统,使其在中间完成单词。
该compinstall功能可以帮助您做到这一点。autoload compinstall; compinstall例如运行它。它也可以通过zsh-newuser-install菜单获得,通常在第一次使用zsh时调用(当您.zshrc还没有时)。
*** compinstall: main menu ***
2. Matching control: set behaviour for case-insensitive matching,
extended (partial-word) matching and substring matching.
Run Code Online (Sandbox Code Playgroud)
*** compinstall: matcher menu ***
`Matchers' compare the completion code with the possible matches in some
special way. Numbers in parentheses show matchers to be tried and the order.
The same number can be assigned to different matchers, meaning apply at the
same time. Omit a sequence number to try normal matching at that point.
A `+' in the first line indicates the element is added to preceding matchers
instead of replacing them; toggle this with `t'. You don't need to set
all four, or indeed any matchers --- then the style will not be set.
( ) `+' indicates add to previous matchers, else replace
n. ( ) No matchers; you may want to try this as the first choice.
c. ( ) Case-insensitive completion (lowercase matches uppercase)
C. ( ) Case-insensitive completion (lower/uppercase match each other)
p. ( ) Partial-word completion: expand 'f.b' to 'foo.bar', etc., in one go.
You can choose the separators (here `.') used each time.
s. ( ) Substring completion: complete on substrings, not just initial
strings. Warning: it is recommended this not be used for element 1.
Run Code Online (Sandbox Code Playgroud)
如果你只是:
( ) `+' indicates add to previous matchers, else replace
n. (1 ) No matchers; you may want to try this as the first choice.
c. ( ) Case-insensitive completion (lowercase matches uppercase)
C. ( ) Case-insensitive completion (lower/uppercase match each other)
p. ( ) Partial-word completion: expand 'f.b' to 'foo.bar', etc., in one go.
You can choose the separators (here `.') used each time.
s. ( 2 ) Substring completion: complete on substrings, not just initial
strings. Warning: it is recommended this not be used for element 1.
Run Code Online (Sandbox Code Playgroud)
并保存并退出,您会看到compinstall将此行添加到您的~/.zshrc:
zstyle ':completion:*' matcher-list '' '' '' 'l:|=* r:|=*'
Run Code Online (Sandbox Code Playgroud)
info zsh matcher-list(注意:您可能需要安装一个zsh-doc软件包)会告诉您它是如何工作的。
然后,如果您键入cd anoTab,您将看到它已完成,this.is.another.long.path.authors假设没有名称以ano.
我邀请您浏览所有compinstall菜单,因为您可以启用更多令人惊叹的功能。(同样适用于zsh-newuser-install)。