AskOverflow.Dev

AskOverflow.Dev Logo AskOverflow.Dev Logo

AskOverflow.Dev Navigation

  • 主页
  • 系统&网络
  • Ubuntu
  • Unix
  • DBA
  • Computer
  • Coding
  • LangChain

Mobile menu

Close
  • 主页
  • 系统&网络
    • 最新
    • 热门
    • 标签
  • Ubuntu
    • 最新
    • 热门
    • 标签
  • Unix
    • 最新
    • 标签
  • DBA
    • 最新
    • 标签
  • Computer
    • 最新
    • 标签
  • Coding
    • 最新
    • 标签
主页 / computer / 问题 / 1615268
Accepted
snapshoe
snapshoe
Asked: 2021-01-06 10:36:43 +0800 CST2021-01-06 10:36:43 +0800 CST 2021-01-06 10:36:43 +0800 CST

有没有一种鱼的方式来做 zsh 的 noglob 内置?

  • 772

来自https://linux.die.net/man/1/zshmisc:

noglob
Filename generation (globbing) is not performed on any of the words.

zsh 示例:

$ ls /*
  <lots of output>
$ noglob ls /*
ls: cannot access '/*': No such file or directory
$ ls "/*"
ls: cannot access '/*': No such file or directory

在鱼中,这适用于引号:

$ ls "/*"
ls: cannot access '/*': No such file or directory

鱼是否可以在不需要引号的情况下做同样的事情?

fish
  • 1 1 个回答
  • 214 Views

1 个回答

  • Voted
  1. Best Answer
    NotTheDr01ds
    2021-01-06T11:33:03+08:002021-01-06T11:33:03+08:00

    原始答案:关于noglob行为本身,我相当肯定答案是“否”,根据这个 Github 问题。

    编辑/更新: 但是考虑到您在评论中描述的用例,可能有另一种方法可以避免输入引号,尽管远不如noglob.

    为了使这尽可能简单,我在评论中与您的示例略有不同。根据该示例,您使用noglobin zsh 创建别名,以便:

    findf /path/*.ext映射到find /path -name "*.ext"

    我使用空格将路径和名称分隔为两个不同的参数:

    findf /path *.ext映射到find /path -name "*.ext"

    好吧,有点-至少那是您要键入的内容。在这种情况下,解决方法是让 fish 在您findf使用*通配符键入参数时自动为您添加周围的引号。

    为此,设置三个函数(其中两个只是单行),全部在~/.config/fish/functions:

    findf.鱼:

    function findf --description 'alias findf=find {path} -name {name}'
        find $argv[1..-2] -name $argv[-1]
    end
    

    非常简单 - 只需将最后一个参数findf作为-name参数传递给find.

    然后才是真正的主力。 findf_binding.fish:

    function findf_binding 
        commandline -i '*'
        set -l tokens (commandline -bo)
        if test (count $tokens) -gt 0
        and [ $tokens[1] = "findf" ]
            set -l currentToken (commandline -t)
            if not contains "\"" (string split "" $currentToken)
                set -l replaceToken "\""$currentToken"\""
                set -l cursorPos (commandline --cursor)
                commandline -t $replaceToken
                commandline --cursor (math $cursorPos+1)
            end
        end
    end
    

    这基本上归结为“如果*被按下,并且该行以 开头,并且 尚未引用findf带有 的参数,然后引用它并将光标移动到 之后。”**

    最后,将 绑定*到fish_user_key_bindings.fishfindf_binding中:

    function fish_user_key_bindings
        bind '*' findf_binding
    end
    

    完全披露 - 这是我在 fish 中的第一个键绑定脚本。这是我一直想学习/尝试一段时间的鱼功能,我认为这是一个很好的机会。结果,尽管如此,毫无疑问,我错过了一些极端情况,并且可以进行样式或语法改进。

    例如,作为一个已知限制,如果您想使用通配符来匹配多个路径(例如findf path* *.yaml),此绑定也会错误地将引号添加到路径组件。

    但希望这能让你接近你正在寻找的东西,或者至少让你走上正确的轨道来调整它或编写你自己的东西。

    • 4

相关问题

  • 将启动目录更改为 HOME 以外的其他目录

  • 是否有与“bash --rcfile ~/.bashrc”等效的 Fish

  • 重定向流

  • 鱼壳 - 找不到“la”定义为“ls -la”的位置

  • weechat, tig, htop, ranger等没有颜色

Sidebar

Stats

  • 问题 205573
  • 回答 270741
  • 最佳答案 135370
  • 用户 68524
  • 热门
  • 回答
  • Marko Smith

    如何减少“vmmem”进程的消耗?

    • 11 个回答
  • Marko Smith

    从 Microsoft Stream 下载视频

    • 4 个回答
  • Marko Smith

    Google Chrome DevTools 无法解析 SourceMap:chrome-extension

    • 6 个回答
  • Marko Smith

    Windows 照片查看器因为内存不足而无法运行?

    • 5 个回答
  • Marko Smith

    支持结束后如何激活 WindowsXP?

    • 6 个回答
  • Marko Smith

    远程桌面间歇性冻结

    • 7 个回答
  • Marko Smith

    子网掩码 /32 是什么意思?

    • 6 个回答
  • Marko Smith

    鼠标指针在 Windows 中按下的箭头键上移动?

    • 1 个回答
  • Marko Smith

    VirtualBox 无法以 VERR_NEM_VM_CREATE_FAILED 启动

    • 8 个回答
  • Marko Smith

    应用程序不会出现在 MacBook 的摄像头和麦克风隐私设置中

    • 5 个回答
  • Martin Hope
    Saaru Lindestøkke 为什么使用 Python 的 tar 库时 tar.xz 文件比 macOS tar 小 15 倍? 2021-03-14 09:37:48 +0800 CST
  • Martin Hope
    CiaranWelsh 如何减少“vmmem”进程的消耗? 2020-06-10 02:06:58 +0800 CST
  • Martin Hope
    Jim Windows 10 搜索未加载,显示空白窗口 2020-02-06 03:28:26 +0800 CST
  • Martin Hope
    v15 为什么通过电缆(同轴电缆)的千兆位/秒 Internet 连接不能像光纤一样提供对称速度? 2020-01-25 08:53:31 +0800 CST
  • Martin Hope
    andre_ss6 远程桌面间歇性冻结 2019-09-11 12:56:40 +0800 CST
  • Martin Hope
    Riley Carney 为什么在 URL 后面加一个点会删除登录信息? 2019-08-06 10:59:24 +0800 CST
  • Martin Hope
    zdimension 鼠标指针在 Windows 中按下的箭头键上移动? 2019-08-04 06:39:57 +0800 CST
  • Martin Hope
    jonsca 我所有的 Firefox 附加组件突然被禁用了,我该如何重新启用它们? 2019-05-04 17:58:52 +0800 CST
  • Martin Hope
    MCK 是否可以使用文本创建二维码? 2019-04-02 06:32:14 +0800 CST
  • Martin Hope
    SoniEx2 更改 git init 默认分支名称 2019-04-01 06:16:56 +0800 CST

热门标签

windows-10 linux windows microsoft-excel networking ubuntu worksheet-function bash command-line hard-drive

Explore

  • 主页
  • 问题
    • 最新
    • 热门
  • 标签
  • 帮助

Footer

AskOverflow.Dev

关于我们

  • 关于我们
  • 联系我们

Legal Stuff

  • Privacy Policy

Language

  • Pt
  • Server
  • Unix

© 2023 AskOverflow.DEV All Rights Reserve