ZSH Shell history not working
Asked Answered
zsh
M

4

53

I recently switched from bash to zshell but my history does not seem to be working. when I press the up arrow I don't get the previous commands. Is the shortcut different? Also how do I enable shared history through tabs and new windows? I am on Lion, and using the standard Terminal

Mythicize answered 5/9, 2012 at 12:50 Comment(1)
See this answer.Claxton
M
97

Add this to your .zshrc:

SAVEHIST=1000  # Save most-recent 1000 lines
HISTFILE=~/.zsh_history
May answered 27/4, 2013 at 17:50 Comment(5)
couldn't figure out why setopt inc_append_history share_history wasn't working. This fixed it.Garnes
Wow, this worked for me as well. Can you put this as an answer?Esplanade
What does SAVEHIST=10 do?Defamation
eivindml, it controls max number of records in history, I believe.May
@DimiDak, sure. Of course, value can be increased. Check zsh.sourceforge.net/Guide/zshguide02.html for more info (particularly 2.5.4).May
A
29

To add to user RoboSloNE, if you've double checked that you have set SAVEHIST and HISTFILE via:

$echo $HISTFILE
 ~/.zsh_history
$echo $SAVEHIST
 100

Then the next step is to check the permissions of the HISTFILE:

$ls -l $HISTFILE
 -rw-------  1 user  staff  3722 Aug  8 11:29 /Users/user/.zsh_history

Your user need to have read/write access on this file to use it as your history file. I've noticed that installing oh-my-zsh as root will set this file permission to root, so you'll need to:

$chown user:group $HISTFILE
Antoniaantonie answered 8/8, 2014 at 15:37 Comment(2)
When I run echo $SAVEHIST, I get zsh: command not found: 10000. Nothing gets written to my $HISTFILE. How can I solve this?Hyatt
What is the group here?Ushijima
P
8

I have resolved zsh history using setup below vim ~/.zshrc

HISTFILE=~/.histfile
HISTSIZE=1000
SAVEHIST=1000

But I have issue with reading from history. I need to cleanup file manually ~/.histfile and then start to work.

Hope this help you a bit.

Pentamerous answered 30/1, 2021 at 16:37 Comment(0)
S
-4

If all of these didn't work, my suggestion is to check the authority of the file ~/.zsh_history.

For example, enter

sudo chmod 777 ~/.zsh_history
Stricklin answered 13/11, 2021 at 2:23 Comment(1)
that's a horrible idea. why would you want the world to be able to read your history, which includes typos and other stuff. Moreover, chmod 777 means it's executable anyone can write to it. That means another user can write to a file in your home directory and you could accidentally run it and it could be destructive.Webbed

© 2022 - 2024 — McMap. All rights reserved.