Skip to content

fish_config doesn't seem to install vars in prompts #1141

Closed

Description

@nafg

e.g. I run fish_config, under Informative Git Prompt I see:

set -g __fish_git_prompt_show_informative_status 1
set -g __fish_git_prompt_hide_untrackedfiles 1

set -g __fish_git_prompt_color_branch magenta bold
set -g __fish_git_prompt_showupstream "informative"
set -g __fish_git_prompt_char_upstream_ahead "↑"
set -g __fish_git_prompt_char_upstream_behind "↓"
set -g __fish_git_prompt_char_upstream_prefix ""

set -g __fish_git_prompt_char_stagedstate "●"
set -g __fish_git_prompt_char_dirtystate "✚"
set -g __fish_git_prompt_char_untrackedfiles "…"
set -g __fish_git_prompt_char_conflictedstate "✖"
set -g __fish_git_prompt_char_cleanstate "✔"

set -g __fish_git_prompt_color_dirtystate blue
set -g __fish_git_prompt_color_stagedstate yellow
set -g __fish_git_prompt_color_invalidstate red
set -g __fish_git_prompt_color_untrackedfiles $fish_color_normal
set -g __fish_git_prompt_color_cleanstate green bold


function fish_prompt --description 'Write out the prompt'

  set -l last_status $status

  if not set -q __fish_prompt_normal
    set -g __fish_prompt_normal (set_color normal)
  end

  # PWD
  set_color $fish_color_cwd
  echo -n (prompt_pwd)
  set_color normal

  printf '%s ' (__fish_git_prompt)

  if not test $last_status -eq 0
  set_color $fish_color_error
  end

  echo -n '$ '

end

After clicking Use Prompt, the prompt is somewhat changed but the colors and symbols seem to be missing. The function has been added to ~/.config/fish/functions/fish_prompt.fish but not the set lines. Adding them to that file fixes the prompt.
Restarting fish did not seem to help.

Activity

  1. added this to the next-major milestone on Nov 4, 2014
  2. snnw commented on Mar 23, 2015

    @snnw
    Contributor

    I'll take a look sometime this week.

  3. snnw commented on Mar 23, 2015

    @snnw
    Contributor

    Works just fine for me with latest fish (version 2.1.2-1225-g733108e). Global variables are set (and show up in the output of set -g), but are not in ~/.config/fish/functions/fish_prompt.fish. This is how it should be, since that file only stores the function, while the global vars go in ~/.config/fish/fishd.*

  4. walles commented on Aug 28, 2015

    @walles
    Contributor

    I have the same issue with fish 2.2.0 on Mac OS X and "Informative Git Prompt".

    The global vars aren't written to neither ~/.config/fish/functions/fish_prompt.fish nor ~/.config/fish/fishd.*.

    It did work with the "Debian chroot" prompt, which makes me think it's the definition of Informative Git Prompt that is wrong in some way.

    Those set commands for example, should they be "-g" or "-U"?

  5. walles commented on Aug 28, 2015

    @walles
    Contributor

    @mariuszs, do you know what's wrong here?

  6. faho commented on Aug 28, 2015

    @faho
    Member

    Yeah, this way to do it just isn't compatible with what webconfig.py currently does - it funcsaves the "fish_prompt" function after sourcing the file, so it won't save anything outside of it.

    So we have two ways to solve it:

    • Audit all sample prompts and move everything into that function
    • Change webconfig to e.g. cp the file instead

    Neither of those solutions will work with fish_right_prompt, though, but the former is more easily extended to also do that, and requires zero semantics changes.

  7. faho commented on Aug 28, 2015

    @faho
    Member

    So, I just completed the "audit", and only three prompts actually do something outside of fish_prompt (other than fish_right_prompt):

    • Informative Git - it sets a bunch of chars and colors for __fish_git_prompt, though I think they aren't different from the defaults anyway
    • Pythonista - it binds colors to variables and sets $VIRTUAL_ENV_DISABLE_PROMPT to "true", without using either of those - maybe they are used outside?
    • Terlar - it sets colors which I'm not sure we want the prompt to do

    Others however also have comments outside of it, so those won't carry over to the user's copy of the prompt, so it's a bit hard to find out which prompt you're using by looking at the file.

    I could now just push a simple move-into-function solution, but I'd rather look at it a bit deeper.

    So, anyone know what $VIRTUAL_ENV_DISABLE_PROMPT is for?

  8. ridiculousfish commented on Aug 31, 2015

    @ridiculousfish
    Member

    Thanks for doing that @faho! From what I can tell, VIRTUAL_ENV_DISABLE_PROMPT is a virtualenv thing, used in Python development. It disables virtualenv replacing the prompt; that's justified since this prompt outputs data related to $VIRTUAL_ENV itself. I think we ought to keep that variable, though it can probably go inside the prompt if that's more convenient.

  9. faho commented on Aug 31, 2015

    @faho
    Member

    I've now pushed all necessary setup into the prompt functions, so no sample prompt should be doing anything outside of the fish_prompt or fish_right_prompt functions anymore.

    In doing this, I've also removed what I deemed to be unnecessary (the pythonista prompt setting variables to colors and then not using them - I kept the virtualenv thing though) or wrong (the terlar prompt setting colors). If anyone takes issue with that, please open a dedicated issue.

  10. modified the milestones: , next-major on Aug 31, 2015
  11. added a commit that references this issue on Sep 8, 2015
    e8ba655
  12. locked as resolved and limited conversation to collaborators on Apr 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions