ohmyzsh: No, I dont want share history.


SOLUTION

The solution to this is appending the command unsetopt share_history to your zshrc file (make sure to put it at the bottom of the file; that is, after OMZ has been loaded).

2376022 removed share_history from OMZ. Just omz update. I reverted the change. You can still fix this by putting unsetopt share_history in your zshrc file, after OMZ is loaded.

@mcornella


you have

setopt share_history

on libs/history.szh.

The thing is that once enable there no seems to be a way to disable it. On my .zshrc I tried appending at the end of file:

setopt share_history Off setopt share_history 0

It doesnt work, the only way is disabling it on the history.zsh file but… that means i wont get updates for it =)

So what is the correct way? are you sure users expect this to be enabled by default?? It’s very anoying for me

About this issue

  • Original URL
  • State: closed
  • Created 10 years ago
  • Reactions: 225
  • Comments: 48 (12 by maintainers)

Commits related to this issue

Most upvoted comments

Well, you could check the zsh documentation for a start… http://zsh.sourceforge.net/Doc/Release/Options.html

setopt no_share_history or unsetopt share_history

this solved the issue for me:

$ cat ~/.zsh_profile
unsetopt share_history

Agreed. This is driving me nuts. I have many terminals into many servers and the commands from each (usually ssh commands) are all getting mushed together. I now regularly go back to bash because this irritates me so. Please make the default match other shells!

Rant: Can we warn people before doing breaking changes like this one? I have used the zsh shared history feature for years (it’s one of the things I like most about zsh) and to have it turn off suddenly and without any warning is quite disruptive.

Why is this a default? Nothing else does this and there’s not even a use-case for this…

Agreed with others that this option should default to false. It is not consistent with the convention of other shells.

Perhaps it should be disabled by default (it’s not the default for bash on MacOS).

No luck, tried both at the very end of my ~/zshrc:

unsetopt share_history
setopt no_share_history

Hello everybody! Is it possible to leave this option commented? I mean, if somebody (like me) wants to disable the history sharing, it’s only a matter of uncomment the lines.

It’s the third time this hits me, and the third time I have to search internet because I forgot the option 😛

I can do a PR if you agree.

It should be .zshrc where you put this. Then restart all open shell sessions.

Exactly: Oh My Zsh sets the share_history option, so you have to unset that after OMZ has been loaded. I’ve updated the original post to contain the clear solution.

This did not work for me. I have tried both of these in my .zshrc: unsetopt share_history setopt no_share_history I also created a .zsh_profile with the same lines above which still had no affect.

I had to do as OP suggested and delete the line in .oh-my-zsh/lib/history.zsh (which I guess will be undone in the next update)

Could this be an environmental difference? I’m running iTerm2 on OSX 10.10.5

Was surprised to see shared history after changing from zsh to ohmyzsh. Since I tend to have multiple open terminals, each running a different process, sharing history doesn’t fit too well with my workflow.

confirmed,zsh 5.7.1 version,share history command removed

## History wrapper
function omz_history {
  local clear list
  zparseopts -E c=clear l=list

  if [[ -n "$clear" ]]; then
    # if -c provided, clobber the history file
    echo -n >| "$HISTFILE"
    echo >&2 History file deleted. Reload the session to see its effects.
  elif [[ -n "$list" ]]; then
    # if -l provided, run as if calling `fc' directly
    builtin fc "$@"
  else
    # unless a number is provided, show all history events (starting from 1)
    [[ ${@[-1]-} = *[0-9]* ]] && builtin fc -l "$@" || builtin fc -l "$@" 1
  fi
}

# Timestamp format
case ${HIST_STAMPS-} in
  "mm/dd/yyyy") alias history='omz_history -f' ;;
  "dd.mm.yyyy") alias history='omz_history -E' ;;
  "yyyy-mm-dd") alias history='omz_history -i' ;;
  "") alias history='omz_history' ;;
  *) alias history="omz_history -t '$HIST_STAMPS'" ;;
esac

## History file configuration
[ -z "$HISTFILE" ] && HISTFILE="$HOME/.zsh_history"
[ "$HISTSIZE" -lt 50000 ] && HISTSIZE=50000
[ "$SAVEHIST" -lt 10000 ] && SAVEHIST=10000

## History command configuration
setopt extended_history       # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups       # ignore duplicated commands history list
setopt hist_ignore_space      # ignore commands that start with space
setopt hist_verify            # show command with history expansion to user before running it

if you need shared history command,you can add command to .zshrc file or add command to ~/.oh-my-zsh/lib/history.zsh file

setopt inc_append_history     # add commands to HISTFILE in order of execution
setopt share_history          # share command history data

execute command

source ~/.zshrc

use unsetopt SHARE_HISTORY

in your .zshrc file

Sorry, I misread your comment. Did you append that at the end of the file?

share_history has not been removed, macOS still have the setop flag, 😦

d646884 (HEAD -> master, origin/master, origin/HEAD) feat(git): add aliases `gcas` and `gcasm` for commit with sign-off (#8881)
4e8ffe8 fix(cargo): complete flags for default cargo aliases (#9692)
f4de8c5 fix(command-not-found): remove invalid argument for PackageKit (#9876)
70ab292 feat(plugins): add `gh` plugin for GitHub CLI (#9557)
63a7422 fix(deno): actually load deno completion (#9863)
0655241 fix(kubectl): use `--current` flag in `kcn` alias (#7605)
6a7285b chore: fix "Facebook" typo in README.md (#9378)
6cc12e0 feat(plugins): add plugin for `deno` (#9847)
7ed8888 feat(npm): add aliases for `npm search` and `npm info` (#9365)
32532c1 feat(npm): add alias for `npm update` (#9442)
1cc15ca feat(npm): add alias for `npm i -f` (#8454)
48a3c2f feat(fzf): look in XDG compliant location (#9858)
1916a31 feat(systemadmin): add IPv6 info to `geteip` command (#9856)
0e5fed1 feat(ys): add virtualenv prompt info (#8453)
b3d1826 feat(ys): add setting to hide dirty info in hg repositories (#8415)
12669f2 fix(gentoo): fix tab color completion (#9810)
e9f805a docs(rails): reflect changes to aliases (#9809)
6ae7869 feat(command-not-found): add support for Termux (#9666)
b54a6da refactor(command-not-found): clean up and reorganize logic
8b55fb3 feat(command-not-found): add support for Homebrew on Apple M1 (#9797)
9f8801b feat(archlinux)!: remove deprecated commands `aur` and `abs` (#9803)
3f50482 feat(react-native): add aliases for iPhone 12 (#9792)
615f9dd chore: direct support queries to Discussions
74db9ac chore: I'm dumb
7da330f chore: fix CONTRIBUTING.md TOC
d5e9e8d docs: document commit convention in CONTRIBUTING.md
1670f1c chore: add maintainer for archlinux plugin
b94bdf8 feat(archlinux): add support for aura AUR helper (#9467)
2e487b1 feat(shell-proxy): enable unexported `DEFAULT_PROXY` setting (#9774)
790f185 refactor(archlinux): fix name & scripts; reorder aliases (#9546)
279212f feat(theme_chooser): display non-zero exit code (#8428)
2d40b56 fix(dirhistory): make sure to call built-in zle widgets (#9771)
2b1d412 fix(git): add `push` or `save` to `gstu` alias (#9766)
69507c9 refactor(adben): refactor theme and degrade gracefully on missing dependencies (#9734)
6e56784 fix(virtualenv): allow empty prefix/suffix in prompt function (#9763)
d8b3e11 feat(plugins): add hitchhiker plugin (#5117)
~/.oh-my-zsh   master  tail -10 lib/history.zsh
[ "$HISTSIZE" -lt 50000 ] && HISTSIZE=50000
[ "$SAVEHIST" -lt 10000 ] && SAVEHIST=10000

## History command configuration
setopt extended_history       # record timestamp of command in HISTFILE
setopt hist_expire_dups_first # delete duplicates first when HISTFILE size exceeds HISTSIZE
setopt hist_ignore_dups       # ignore duplicated commands history list
setopt hist_ignore_space      # ignore commands that start with space
setopt hist_verify            # show command with history expansion to user before running it
setopt share_history          # share command history data

@mcornella @robbyrussell, I see this issue as well. I tried appending the unsetopt share_history at the bottom of .zshrc and still same issue

It might in the future, why not just add it to the .zshrc file (after OMZ is sourced)? It’s much more portable and cleaner.

vim ~/.oh-my-zsh/lib/history.zsh

remove command

setopt inc_append_history setopt share_history

or in .zshrc file add command

unsetopt inc_append_history
unsetopt share_history

I notice from the docs that it says:

INC_APPEND_HISTORY_TIME

This option is a variant of INC_APPEND_HISTORY in which, where possible, the history entry is written out to the file after the command is finished, so that the time taken by the command is recorded correctly in the history file in EXTENDED_HISTORY format. This means that the history entry will not be available immediately from other instances of the shell that are using the same history file.

This option is only useful if INC_APPEND_HISTORY and SHARE_HISTORY are turned off. The three options should be considered mutually exclusive.

SHARE_HISTORY <K>

This option both imports new commands from the history file, and also causes your typed commands to be appended to the history file (the latter is like specifying INC_APPEND_HISTORY, which should be turned off if this option is in effect). The history lines are also output with timestamps ala EXTENDED_HISTORY (which makes it easier to find the spot where we left off reading the file after it gets re-written).

Is it intentional that INC_APPEND_HISTORY and SHARE_HISTORY are both set in oh-my-zsh?

@JohnnyWalkerDesign, I’ve a created an issue on StackOverflow which better illustrates, what i’n truing to achieve: https://stackoverflow.com/questions/48873643/how-to-stop-zsh-from-merging-history-for-all-closing-tabs

@mcornella Oh thank you for the tip. It was the ordering. This was driving me nuts. 🌻