Search code examples
fish

Fish shell git_prompt inside TIDE


Is it possible to force Fish shell extention TIDE to use fish_git_prompt instead of its own _tide_item_git.fish?

My goal is to make TIDE git prompt identical to this tutorial.

Right now with default TIDE setting I have this git prompt:

enter image description here

However, I want to make it look like this, but still use TIDE:

enter image description here Source image


fish, version 3.2.1

Fedora 33


Solution

  • So what that tide function does is simply collect the git info and print it. Tide calls it, takes what it prints, and puts it in the correct place. This is also how the fish_git_prompt works - it prints the git stuff, your prompt is responsible for putting that in the correct place.

    Simplified:

    function fish_prompt
        set gitstuff (_tide_item_git)
        # do other tide stuff
        printf '%s' $gitstuff $otherstuff
    end
    

    When fish calls a function, it goes through $fish_function_path for a file with the name of the function (plus a ".fish" suffix).

    So what you would simply do is make your own function _tide_item_git, and put it first in $fish_function_path.

    I'm not sure how you've installed tide, I'm assuming it's not directly in ~/.config/fish/functions - the normal directory for your functions. That's the simple case, so you can just call funced _tide_item_git, which will open it in your editor, and replace it with

    function _tide_item_git
        fish_git_prompt
    end
    

    then run funcsave _tide_item_git once you're happy.

    In the more complicated case, make another directory for your functions - ~/.config/fish/myfunctions maybe - add it to $fish_function_path:

    set -g fish_function_path ~/.config/fish/myfunctions $fish_function_path
    

    (put that in config.fish)

    make a file called _tide_item_git.fish there and put the above function in.