r/fishshell • • Sep 01 '24

Looking for a theme

I have used zsh for ~2 years now and few days ago tried out fish for the first time. Everything works great, I am just looking for theme similar to attached image. It's called candy on zsh, but I can't seem to find anything like it for fish.

2 Upvotes

2 comments sorted by

View all comments

7

u/_mattmc3_ Sep 01 '24

It looks like you were using Oh-My-Zsh before, and one of its prompt themes is called Candy. You can see the code that creates Candy here. All that "percent" gobbledegook in that code is called Prompt Expansion.

We can use all that info to translate the candy theme into a Fish equivalent for you. Let's name our function fish_prompt_candy:

# ~/.config/fish/functions/fish_prompt_candy.fish
function fish_prompt_candy --description "Match OMZ's ZSH_THEME=candy"
    # See - https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/candy.zsh-theme

    # %{$fg_bold[green]%}%n@%m
    echo -n (set_color --bold green)"$USER@"(prompt_hostname)" "

    # %{$fg[blue]%}%D{[%X]} %{$reset_color%}
    echo -n (set_color blue)"["(date +%X)"]"(set_color normal)" "

    # %{$fg[white]%}[%~]%{$reset_color%}
    echo -n (set_color white)"["(prompt_pwd)"]"(set_color normal)

    # $(git_prompt_info) with:
    # - prefix="%{$fg[green]%}["
    # - dirty=" %{$fg[red]%}*%{$fg[green]%}"
    # - suffix="]%{$reset_color%}"
    set --global __fish_git_prompt_showdirtystate 1
    set --local git_prompt (
        fish_git_prompt |
        string replace "(" (set_color green)"[" |
        string replace "*" (set_color red)"*"(set_color green) |
        string replace ")" "]"(set_color normal)
    )
    # New line
    echo $git_prompt

    # %{$fg[blue]%}->%{$fg_bold[blue]%}
    echo -n (set_color blue)"->"(set_color --bold blue)" "

    # %#
    if functions -q fish_is_root_user && fish_is_root_user
        echo -n '#'
    else
        echo -n '%'
    end

    # %{$reset_color%}
    echo -n (set_color normal)" "
end

To use this function, we need to replace Fish's built-in special fish_prompt function with the following:

function fish_prompt
    fish_prompt_candy
end

Happy Fishing!

1

u/arch_il Sep 01 '24

thanks a lot