设置并从功能执行命令

发布于 2025-01-21 22:38:59 字数 417 浏览 2 评论 0原文

如何编写在字符串中执行命令并在历史记录中显示命令的鱼功能?

function qh --description 'Use peco to query command history'
    if test (count $argv) = 0
        set peco_flags --layout=bottom-up
    else
        set peco_flags --layout=bottom-up --query "$argv"
    end

    history | peco $peco_flags | read cmd

    if test $cmd
        commandline $cmd
    else
        commandline ''
    end
end

这不起作用...

How can I write a fish function that executes a command in a string and make it appear in the history?

function qh --description 'Use peco to query command history'
    if test (count $argv) = 0
        set peco_flags --layout=bottom-up
    else
        set peco_flags --layout=bottom-up --query "$argv"
    end

    history | peco $peco_flags | read cmd

    if test $cmd
        commandline $cmd
    else
        commandline ''
    end
end

This does not work...

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

旧伤慢歌 2025-01-28 22:38:59

可以创建一个键绑定,以设置命令行,然后执行它。然后,该命令将出现在历史中。示例:

function whatday
    commandline "echo Today is $(date +%A)"
    commandline -f execute
end
bind \eq whatday

现在ALT-Q将将命令行设置为今天的Echo是星期日并执行它。它出现在历史上。

除此之外,还有 abbreviations 可以用文本代替代币;但是文本只是静态的(例如gco-> git Checkout)。

尚无任意鱼类功能(例如作为壳脚本的一部分运行)附加到历史记录,只有从中删除并读取它。

It is possible to create a key binding which sets the command line and then executes it; that command will then appear in history. Example:

function whatday
    commandline "echo Today is $(date +%A)"
    commandline -f execute
end
bind \eq whatday

now alt-q will set the commandline to echo Today is Sunday and execute it; it appears in history.

Beyond that there are also abbreviations which allow replacing tokens with text; but the text is just static (e.g. gco -> git checkout).

There is as yet no way for an arbitrary fish function (e.g. run as part of a shell script) to append to history, only delete and read from it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文