在鱼 shell 中丰富的 `ls [G-S]*`?

Rich globbing `ls [G-S]*` in fish shell?

在Bash中可以

ls [G-S]*

它会列出来自 g-sG-S 的所有文件。

在 Fish shell 中是如何完成的?

您可以使用 find -iregex "./[G-S].*"。 Fish在这方面相当有限。

Fish 当前不支持丰富的 glob 语法。目前的想法是,应该添加一个 glob 命令,以符合通过命令而不是魔法语法来做事的目标。例如,参见 https://github.com/fish-shell/fish-shell/issues/3681。解决方案是创建一个过滤结果的函数。例如,** glob 匹配 CWD 中及以下的所有文件和目录。我经常只想要普通文件并想忽略 .git 子目录。所以我写了这个函数:

function ff --description 'Like ** but only returns plain files.'
    # This also ignores .git directories.
    find . \( -name .git -type d -prune \) -o -type f | sed -n -e '/\/\.git$/n' -e 's/^\.\///p'
end

我可以这样使用:grep something (ff)。您可以创建一个使用 find -name 模式匹配功能的类似函数,或者使用 string match --regex.

过滤结果