Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make fish_history have a single default value #7650

Closed
etcusrvar opened this issue Jan 23, 2021 · 5 comments
Closed

Make fish_history have a single default value #7650

etcusrvar opened this issue Jan 23, 2021 · 5 comments

Comments

@etcusrvar
Copy link

fish 3.1.2
enhancement, change request

There are 3 different settings that the variable fish_history can have that all essentially mean the same thing (docs)--

  • fish_history is unset
  • $fish_history = default
  • $fish_history = fish

It would be nice if this was a single value.

Motivation: I've been writing snippets of code frequently such as

if set -q fish_history
    switch $fish_history
        case default fish
            set foo fish
        case \*
            set foo $fish_history
    end
else
    set foo fish
end
do-something-with $foo

This can be worked around easily enough with an --on-variable function, such as

> function _fish_history_value --on-variable fish_history
    test "$fish_history" = default && set -g fish_history fish
    not set -q fish_history && set -g fish_history fish
end
> _fish_history_value
> echo $fish_history 
fish
> set fish_history default; echo $fish_history
fish
> set -e fish_history; echo $fish_history
fish
> set fish_history foo; echo $fish_history
foo

I call a function like this at the top of my config.fish. And all is fine. But others I share functions or plugins or the like with may not have this workaround, or even want it.

This seems like it should be something that is handled in the fish_history variable itself.

@faho
Copy link
Member

faho commented Jan 23, 2021

Yeah, we should probably ditch the "default" value.

However, what I'd like to know is what you're doing with the value? I'd expect most people and programs to not care at all about $fish_history, and those that do I'd expect to just set it and be done, so if you're doing anything else that's interesting.

@faho faho added this to the fish-future milestone Jan 23, 2021
@etcusrvar
Copy link
Author

I essentially do exactly what you said-- just set it and be done.

Here's a function I use all the time to start a new fish "profile" subshell:

function fishp
    fish_history=$argv[1] $__fish_bin_dir/fish $argv[2..-1]
end

I freqently do

  • fishp sudo -P # just sudo/system stuff
  • fishp chezmoi|docker|project1|project2|...

So, I don't set fish_history interactively (yet).

But I use the value in a lot of places-- config.fish, fish_prompt, fish_title, ...

I turned some of my homegrown functions into a plugin that's essentially a workaround until #7589 is merged to a fish release. Here's one snippet that prompted me to open this issue.

I also have lines in my config.fish that do extra configuration based on the profile I started fish with. Essentially,

set -l p $__fish_config_dir/profiles/$fish_history
set -p fish_complete_path $p/completions
set -p fish_function_path $p/functions
for f in $p/conf.d/*.fish
    source $f
end
source $p/config.fish

(But a tad more elaborate.)

In these files I have other functions, aliases, completions, etc.

I also use direnv heavily, and have lines like export fish_history=$(basename $PWD) in some directories' .envrc files.

I use fish_history as a session profile mechanism beyond simply the history file itself. I did the same kind of thing in zsh with ZDOTDIR, but fish is so much easier to use and more configurable :).

@faho
Copy link
Member

faho commented Jan 23, 2021

I use fish_history as a session profile mechanism beyond simply the history file itself.

That's.. simply not what it's meant for.

If you want to add a session mechanism, add it and then set $fish_history depending on that, instead of going via $fish_history.

set -q fish_profile
or set -g fish_profile fish

set -g fish_history $fish_profile

@etcusrvar
Copy link
Author

etcusrvar commented Jan 23, 2021

I think that's what I've done in the links in the previous comment. Maybe I should have phrased that last sentence differently. You may be right though, and my thinking has been backwards. Point taken. Either way, the original issue is a separate thing.

@faho faho closed this as completed in e7abb52 Mar 28, 2021
@faho
Copy link
Member

faho commented Mar 28, 2021

Alright, I've just removed the special handling of "default". Now you either set $fish_history to the actual string (with "fish" being the default one), or you leave it unset (and it's still "fish").

I don't think we need to add anything more for backwards compatibility here - just use "fish", always, if you must set it. I don't expect many people to have ever used "default".

@zanchey zanchey modified the milestones: fish-future, fish 3.3.0 Apr 1, 2021
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Sep 28, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants