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

Config for fish history length #2674

Closed
dvcrn opened this Issue Jan 13, 2016 · 14 comments

Comments

Projects
None yet
7 participants
@dvcrn

dvcrn commented Jan 13, 2016

Hi, new fish user here!

I couldn't find how to set the maximum length for the fish history file. Is that even possible?

On my mac for example, I prefer a very very long history to probably date back weeks. On my servers however, if I were to use fish, I want something small and light weld.

@zanchey

This comment has been minimized.

Show comment
Hide comment
@zanchey

zanchey Jan 13, 2016

Member

I wrote some notes on this in #940 (comment) (and there are several related issues containing insightful comments), but the short answer is that fish uses a LRU list to manage history, that it's limited to 256k unique items, and that there's no configuration knob to control this. There's not been a compelling case made for changing this so far, so I'm going to close the issue for now although if you can think of something then definitely speak up.

Member

zanchey commented Jan 13, 2016

I wrote some notes on this in #940 (comment) (and there are several related issues containing insightful comments), but the short answer is that fish uses a LRU list to manage history, that it's limited to 256k unique items, and that there's no configuration knob to control this. There's not been a compelling case made for changing this so far, so I'm going to close the issue for now although if you can think of something then definitely speak up.

@zanchey zanchey closed this Jan 13, 2016

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Jan 13, 2016

Member

To build on what zanchey said, fish de-duplicates history so history files are generally smaller than in other shells. In practice you can easily have years of history in a few 100 KB. Or if you only run a few commands on the server, the files will be very small. If the history files are larger than you expect or want, please report that. Thanks for filing this.

Member

ridiculousfish commented Jan 13, 2016

To build on what zanchey said, fish de-duplicates history so history files are generally smaller than in other shells. In practice you can easily have years of history in a few 100 KB. Or if you only run a few commands on the server, the files will be very small. If the history files are larger than you expect or want, please report that. Thanks for filing this.

@dvcrn

This comment has been minimized.

Show comment
Hide comment
@dvcrn

dvcrn Jan 13, 2016

Thanks for clearing that up! I just found it odd that fish didn't have that option and thought I must have missed it.

dvcrn commented Jan 13, 2016

Thanks for clearing that up! I just found it odd that fish didn't have that option and thought I must have missed it.

@faho faho added the will-not-fix label Mar 6, 2016

@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Apr 14, 2016

@ridiculousfish I was also curious about this. I'm happy with the way it currently seems to work, but I would like to know, how much history does Fish keep? Is it unlimited?

alphapapa commented Apr 14, 2016

@ridiculousfish I was also curious about this. I'm happy with the way it currently seems to work, but I would like to know, how much history does Fish keep? Is it unlimited?

@krader1961

This comment has been minimized.

Show comment
Hide comment
@krader1961

krader1961 Apr 14, 2016

Contributor

@alphapapa: It is not unlimited. From src/history.h

#define HISTORY_SAVE_MAX (1024 * 256)

That limit is a trifle vague but it means that the most recently executed 256K (262,144) entries are saved. Why that limit? It's arbitrary and reflects the propensity of programmers to use power of two (2^n) values.

Contributor

krader1961 commented Apr 14, 2016

@alphapapa: It is not unlimited. From src/history.h

#define HISTORY_SAVE_MAX (1024 * 256)

That limit is a trifle vague but it means that the most recently executed 256K (262,144) entries are saved. Why that limit? It's arbitrary and reflects the propensity of programmers to use power of two (2^n) values.

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Apr 14, 2016

Member

That's right! To be clear, those are 256K unique commands. Running the same command multiple times only requires one history "slot".

Member

ridiculousfish commented Apr 14, 2016

That's right! To be clear, those are 256K unique commands. Running the same command multiple times only requires one history "slot".

@alphapapa

This comment has been minimized.

Show comment
Hide comment
@alphapapa

alphapapa Apr 14, 2016

@krader1961 Thanks, I was going to look into that but you saved me the trouble.

@ridiculousfish Thanks. I think that is probably enough. :) I'm currently at 12,400 unique commands since about this time last year (I must have wiped out the history around that time...oops).

alphapapa commented Apr 14, 2016

@krader1961 Thanks, I was going to look into that but you saved me the trouble.

@ridiculousfish Thanks. I think that is probably enough. :) I'm currently at 12,400 unique commands since about this time last year (I must have wiped out the history around that time...oops).

@rsalmei

This comment has been minimized.

Show comment
Hide comment
@rsalmei

rsalmei Apr 2, 2018

Hey, I'm sorry to revive an old thread, but I'd like to ask a related question...

Please @ridiculousfish, you said that fish de-duplicates history, and I'm writing a small tool to import my zsh history, and change to fish for good.
So, in my tests, I do not see this behavior, does fish only de-duplicates if it needs more space?

Let's see, in one session:

- cmd: docker ps
  when: 1522644420
- cmd: docker ps -a
  when: 1522644435
- cmd: docker ps
  when: 1522644442
- cmd: docker ps -a
  when: 1522644451

Between sessions:

- cmd: pyenv shell 3.5.4
  when: 1522642627
- cmd: pyenv shell 3.5.4
  when: 1522642801
- cmd: pyenv shell 3.5.4
  when: 1522642808

Both are contiguous sections of the history file. In neither case it was de-duped... When this is actually applied? Thank you!!

rsalmei commented Apr 2, 2018

Hey, I'm sorry to revive an old thread, but I'd like to ask a related question...

Please @ridiculousfish, you said that fish de-duplicates history, and I'm writing a small tool to import my zsh history, and change to fish for good.
So, in my tests, I do not see this behavior, does fish only de-duplicates if it needs more space?

Let's see, in one session:

- cmd: docker ps
  when: 1522644420
- cmd: docker ps -a
  when: 1522644435
- cmd: docker ps
  when: 1522644442
- cmd: docker ps -a
  when: 1522644451

Between sessions:

- cmd: pyenv shell 3.5.4
  when: 1522642627
- cmd: pyenv shell 3.5.4
  when: 1522642801
- cmd: pyenv shell 3.5.4
  when: 1522642808

Both are contiguous sections of the history file. In neither case it was de-duped... When this is actually applied? Thank you!!

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Apr 2, 2018

Member

fish deduplicates the whole file every 25 commands, starting at a random number (so the first dedup is probably fewer than 25 commands). See the logic around countdown_to_vacuum in history.cpp.

Member

ridiculousfish commented Apr 2, 2018

fish deduplicates the whole file every 25 commands, starting at a random number (so the first dedup is probably fewer than 25 commands). See the logic around countdown_to_vacuum in history.cpp.

@rsalmei

This comment has been minimized.

Show comment
Hide comment
@rsalmei

rsalmei Apr 6, 2018

Nice @ridiculousfish, thanks!

Just one more question, please.
Why do some entries are written with a "paths" component and some don't?
Example:

- cmd: echo (which fish) | sudo tee -a /etc/shells
  when: 1522978375
  paths:
    - /etc/shells
- cmd: mv /usr/local/Cellar/pyenv/1.0.3/versions/ /usr/local/Cellar/pyenv/1.2.2/
  when: 1521681288
  paths:
    - /usr/local/Cellar/pyenv/1.0.3/versions/
    - /usr/local/Cellar/pyenv/1.2.2/

but

- cmd: cat ~/.config/fish/functions/pyenv.fish 
  when: 1521684129
- cmd: time /usr/local/bin/zsh -i -c exit
  when: 1521000722

rsalmei commented Apr 6, 2018

Nice @ridiculousfish, thanks!

Just one more question, please.
Why do some entries are written with a "paths" component and some don't?
Example:

- cmd: echo (which fish) | sudo tee -a /etc/shells
  when: 1522978375
  paths:
    - /etc/shells
- cmd: mv /usr/local/Cellar/pyenv/1.0.3/versions/ /usr/local/Cellar/pyenv/1.2.2/
  when: 1521681288
  paths:
    - /usr/local/Cellar/pyenv/1.0.3/versions/
    - /usr/local/Cellar/pyenv/1.2.2/

but

- cmd: cat ~/.config/fish/functions/pyenv.fish 
  when: 1521684129
- cmd: time /usr/local/bin/zsh -i -c exit
  when: 1521000722
@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Apr 6, 2018

Member

The paths indicate which arguments were file paths, as a hint to the autosuggestion machinery. For example, if I run cat ../file.txt, and there's a file at ../file.txt, fish will only suggest that command when ../file.txt is again a file. This helps avoid suggesting certain commands that would otherwise be invalid.

Member

ridiculousfish commented Apr 6, 2018

The paths indicate which arguments were file paths, as a hint to the autosuggestion machinery. For example, if I run cat ../file.txt, and there's a file at ../file.txt, fish will only suggest that command when ../file.txt is again a file. This helps avoid suggesting certain commands that would otherwise be invalid.

@rsalmei

This comment has been minimized.

Show comment
Hide comment
@rsalmei

rsalmei Apr 7, 2018

Ok, that's very nice.
But why aren't all paths extracted, like I've shown? cd for instance seems to never extract any paths.

rsalmei commented Apr 7, 2018

Ok, that's very nice.
But why aren't all paths extracted, like I've shown? cd for instance seems to never extract any paths.

@ridiculousfish

This comment has been minimized.

Show comment
Hide comment
@ridiculousfish

ridiculousfish Apr 7, 2018

Member

The path detection is pretty naive and doesn't do any expansions, even tilde expansion. This is something that ought to be fixed some day. But it doesn't matter for cd since that has custom autocompletion logic.

Member

ridiculousfish commented Apr 7, 2018

The path detection is pretty naive and doesn't do any expansions, even tilde expansion. This is something that ought to be fixed some day. But it doesn't matter for cd since that has custom autocompletion logic.

@rsalmei

This comment has been minimized.

Show comment
Hide comment
@rsalmei

rsalmei Apr 17, 2018

Cool! Thank you @ridiculousfish!
I've successfully migrated to fish, and brought along all my zsh history!

rsalmei commented Apr 17, 2018

Cool! Thank you @ridiculousfish!
I've successfully migrated to fish, and brought along all my zsh history!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment