{"action":"closed","issue":{"url":"https://api.github.com/repos/fish-shell/fish-shell/issues/2845","repository_url":"https://api.github.com/repos/fish-shell/fish-shell","labels_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/2845/labels{/name}","comments_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/2845/comments","events_url":"https://api.github.com/repos/fish-shell/fish-shell/issues/2845/events","html_url":"https://github.com/fish-shell/fish-shell/issues/2845","id":142743730,"number":2845,"title":"fish_prompt isn't aware of the variables defined in customized functions","user":{"login":"imcaizheng","id":14214611,"avatar_url":"https://avatars.githubusercontent.com/u/14214611?v=3","gravatar_id":"","url":"https://api.github.com/users/imcaizheng","html_url":"https://github.com/imcaizheng","followers_url":"https://api.github.com/users/imcaizheng/followers","following_url":"https://api.github.com/users/imcaizheng/following{/other_user}","gists_url":"https://api.github.com/users/imcaizheng/gists{/gist_id}","starred_url":"https://api.github.com/users/imcaizheng/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/imcaizheng/subscriptions","organizations_url":"https://api.github.com/users/imcaizheng/orgs","repos_url":"https://api.github.com/users/imcaizheng/repos","events_url":"https://api.github.com/users/imcaizheng/events{/privacy}","received_events_url":"https://api.github.com/users/imcaizheng/received_events","type":"User","site_admin":false},"labels":[{"url":"https://api.github.com/repos/fish-shell/fish-shell/labels/question","name":"question","color":"cc317c"}],"state":"closed","locked":false,"assignee":{"login":"krader1961","id":7545917,"avatar_url":"https://avatars.githubusercontent.com/u/7545917?v=3","gravatar_id":"","url":"https://api.github.com/users/krader1961","html_url":"https://github.com/krader1961","followers_url":"https://api.github.com/users/krader1961/followers","following_url":"https://api.github.com/users/krader1961/following{/other_user}","gists_url":"https://api.github.com/users/krader1961/gists{/gist_id}","starred_url":"https://api.github.com/users/krader1961/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/krader1961/subscriptions","organizations_url":"https://api.github.com/users/krader1961/orgs","repos_url":"https://api.github.com/users/krader1961/repos","events_url":"https://api.github.com/users/krader1961/events{/privacy}","received_events_url":"https://api.github.com/users/krader1961/received_events","type":"User","site_admin":false},"milestone":null,"comments":8,"created_at":"2016-03-22T18:49:40Z","updated_at":"2016-03-28T03:32:02Z","closed_at":"2016-03-28T03:32:02Z","body":"I involve a custom function in the defintion of the fish_prompt function,\r\nbut unexpectly I got a error when starting the terminal.\r\nI think of it as a bug because I have to treat the prompt function\r\nas something special though it's placed in the functions directory\r\nlike any other function.\r\n\r\n### Update\r\n\r\nSorry for the unclarity. I have corrected the title.\r\n\r\nBelow is the customized function:\r\n\r\n    ~➜ cat .config/fish/functions/bat.fish\r\n    set bat0 /sys/class/power_supply/BAT0\r\n\r\n    function bat\r\n        if not count $argv >/dev/null\r\n            bat-all\r\n            return\r\n        end\r\n        switch $argv[1]\r\n            case \"status\"\r\n                bat-status\r\n            case \"capacity\"\r\n                bat-capacity\r\n        end\r\n    end\r\n\r\n    function bat-all\r\n        begin\r\n            bat-status\r\n            bat-capacity\r\n        end | tr '\\n' ' '\r\n    end\r\n\r\n    function bat-status\r\n        cat $bat0/status\r\n    end\r\n\r\n    function bat-capacity\r\n        cat $bat0/capacity\r\n    end\r\n\r\nIt could be executed on the command line sucessfully.\r\n\r\nHere is how I invoke it in my fish_prompt function (simplified):\r\n\r\n    function fish_prompt\r\n        if test (bat capacity) -lt 20\r\n            echo \"Power is critical\"\r\n        end\r\n    end\r\n\r\nfish hangs with no error messages during the initialization.\r\n\r\nfish version: fish, version 2.2.0-486-g1a3bcf6-dirty\r\n\r\n### Additional information:\r\n\r\nAfter some tests, I found that the `$bat0` variable would not be\r\ndefined as expected, which results in `cat $bat0/capacity`\r\nbeing effectively the `cat` command reading from stdin.  That is why fish hangs (as #2848  pointed out).\r\n\r\nIt's wired because before I involved the `bat` command\r\nin the fish_prompt function `$bat0` would be defined properly."}}