gpt4 book ai didi

zsh - 填写当前目录下最近使用的文件

转载 作者:行者123 更新时间:2023-12-03 21:20:53 26 4
gpt4 key购买 nike

我正在寻找一种在命令行上快速访问最新文件/目录的方法,最好是在 ZSH 中。

ls -d *(om[1])

给我这个,如果我想用一个命令,例如少 *(om[1])

这也有效。

但是,输入所有括号很乏味,我使用这个 很多 - 因此我正在寻找一种为该字符串创建快捷方式的方法。

我在 .zshrc 文件中创建了一个函数
lf(){ 
ls -d *(om[1])
}

,我可以这样使用:
less <$(lf)
less <`lf`

,但我发现这仍然不太理想。
less |lf

不起作用。

有没有办法在不使用“难以输入的字符”的情况下快速访问最新文件?理想情况下,它只是类似于
less LATEST

有任何想法吗?

最佳答案

您可以使用 _most_recent_file (^Xm) .

_most_recent_file (^Xm)

Complete the name of the most recently modified file matching the pattern on the command line (which may be blank). If given a numeric argument N, complete the Nth most recently modified file. Note the completion, if any, is always unique.

-- zshcompsys(1) BINDABLE COMMANDS



因此,我们可以通过键入 CTRL-x-m 来获取最新的文件。例如:
% less ;# typing `CTRL-X m` here, we could get:
% less newest-file-or-directory

我们可以在这里指定一些模式,例如:
% less *.log ;# when I want the newest *.log:
% less newest.log

有必要有一些 autoload -Uz compinit; compinit~/.zshrc尽管。

关于zsh - 填写当前目录下最近使用的文件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28369062/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com