首页 > 解决方案 > 对发出的事件做出反应时,Unix Dialog 实用程序在 fish shell 中失败

问题描述

我有这个功能(已知工作正常)

function problem_open -e on_problem_open -d "select from existing problems"
    set matches (find $FD_PROB_HOME/ -maxdepth 1 -mindepth 1 -type d ! -name ".git")

    if test 1 -eq (count $matches)
        if test -d $matches
            set -U FD_PROB_CURRENT $matches[1]
            echo "chose option 1"
            return
        end
    end
    set -g dcmd "dialog --stdout --no-tags --menu 'select the file to edit' 20 60 20 "
    set c 1
    for option in $matches
        set l (basename "$option")
        set -g dcmd "$dcmd $c '$l'"
        set c (math $c + 1)
    end
    set choice (eval "$dcmd") 
    #clear
    if test $status -eq 0
        echo "edit option $choice"
        set -U FD_PROB_CURRENT $matches[$choice]
    end
end

当我直接调用时problem_open,对话框显示正常。当我间接调用该函数时,emit on_problem_open不会显示通过对话框。

任何想法为什么会发生这种情况?它是事件的预期行为吗?

我可以解决这个问题,但这将是一个棘手的问题。

标签: eventsdialogfish

解决方案


您的示例在这里可以,但一个提示是确保该函数是手动定义的或在您的 中定义的config.fish,而不是依赖它来自动加载。存储在自动加载文件中的函数在第一次运行之前不会监听事件处理程序


推荐阅读