How do you share history between terminals in zsh?












28















How can it be achieved so that every command that is entered, is visible in every open terminal's history?



When having multiple terminals open, the history isn't shared, i.e. what you entered in one terminals history, doesn't show up in another one. Think of an alternative to Bash's PROMPT_COMMAND="history -a" (which saves the history before the prompt is beeing displayed).










share|improve this question

























  • See also related and advanced Q&A: superuser.com/questions/446594/…

    – lumbric
    Dec 22 '13 at 18:27
















28















How can it be achieved so that every command that is entered, is visible in every open terminal's history?



When having multiple terminals open, the history isn't shared, i.e. what you entered in one terminals history, doesn't show up in another one. Think of an alternative to Bash's PROMPT_COMMAND="history -a" (which saves the history before the prompt is beeing displayed).










share|improve this question

























  • See also related and advanced Q&A: superuser.com/questions/446594/…

    – lumbric
    Dec 22 '13 at 18:27














28












28








28


11






How can it be achieved so that every command that is entered, is visible in every open terminal's history?



When having multiple terminals open, the history isn't shared, i.e. what you entered in one terminals history, doesn't show up in another one. Think of an alternative to Bash's PROMPT_COMMAND="history -a" (which saves the history before the prompt is beeing displayed).










share|improve this question
















How can it be achieved so that every command that is entered, is visible in every open terminal's history?



When having multiple terminals open, the history isn't shared, i.e. what you entered in one terminals history, doesn't show up in another one. Think of an alternative to Bash's PROMPT_COMMAND="history -a" (which saves the history before the prompt is beeing displayed).







command-line history zsh






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jul 12 '12 at 2:47







MJB

















asked Jan 28 '11 at 2:04









MJBMJB

1,03411021




1,03411021













  • See also related and advanced Q&A: superuser.com/questions/446594/…

    – lumbric
    Dec 22 '13 at 18:27



















  • See also related and advanced Q&A: superuser.com/questions/446594/…

    – lumbric
    Dec 22 '13 at 18:27

















See also related and advanced Q&A: superuser.com/questions/446594/…

– lumbric
Dec 22 '13 at 18:27





See also related and advanced Q&A: superuser.com/questions/446594/…

– lumbric
Dec 22 '13 at 18:27










2 Answers
2






active

oldest

votes


















34














The following options would be applicable:





  • To save every command before it is executed (this is different from bash's history -a solution):



    setopt inc_append_history



  • To read the history file everytime history is called upon as well as the functionality from inc_append_history:



    setopt share_history



These can be set in your .zshrc file.



Related for bash:




  • Is it possible to make writing to .bash_history immediate?






share|improve this answer





















  • 4





    "SHARE_HISTORY: 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)." (From manual emphasis added) i.e. just the INC_APPEND_HISTORY option will do what you want.

    – artfulrobot
    Oct 20 '14 at 10:30








  • 3





    Actually, just the SHARE_HISTORY option alone will do what you want. The phrase "which should be turned off if this option is in effect" translates to "[INC_APPEND_HISTORY] should be turned off if [SHARE_HISTORY] option is in effect". I've tested this on zsh 5.1.1 on Ubuntu Xenial.

    – Linus Arver
    Feb 2 '17 at 0:33






  • 1





    @opert is correct: setopt share_history is what will accomplish the desired result. @MJB would you be willing to edit your answer to remove the mention of setopt inc_append_history? It obscures the actual answer.

    – bonh
    Feb 22 '17 at 16:40











  • Names are case insensitive and underscores are ignored so if you setopt | grep hist will get incappendhistory and sharehistory.

    – Pablo Bianchi
    Oct 5 '17 at 21:16





















4














If you use Robby Russell’s awesome OhMyZSH, it will take care of this and more.



See https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/history.zsh



That includes setopt inc_append_history.






share|improve this answer


























  • It's his/hers/its. Important for shell work.

    – Cees Timmerman
    Oct 13 '16 at 12:36











  • @CeesTimmerman fixed, thank you. It's important for communication in general I believe. What did you mean by "Important for shell work"?

    – james_womack
    Oct 13 '16 at 19:01






  • 1





    A typo in the shell can corrupt your entire system.

    – Cees Timmerman
    Oct 13 '16 at 21:52











Your Answer








StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "89"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f23630%2fhow-do-you-share-history-between-terminals-in-zsh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























2 Answers
2






active

oldest

votes








2 Answers
2






active

oldest

votes









active

oldest

votes






active

oldest

votes









34














The following options would be applicable:





  • To save every command before it is executed (this is different from bash's history -a solution):



    setopt inc_append_history



  • To read the history file everytime history is called upon as well as the functionality from inc_append_history:



    setopt share_history



These can be set in your .zshrc file.



Related for bash:




  • Is it possible to make writing to .bash_history immediate?






share|improve this answer





















  • 4





    "SHARE_HISTORY: 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)." (From manual emphasis added) i.e. just the INC_APPEND_HISTORY option will do what you want.

    – artfulrobot
    Oct 20 '14 at 10:30








  • 3





    Actually, just the SHARE_HISTORY option alone will do what you want. The phrase "which should be turned off if this option is in effect" translates to "[INC_APPEND_HISTORY] should be turned off if [SHARE_HISTORY] option is in effect". I've tested this on zsh 5.1.1 on Ubuntu Xenial.

    – Linus Arver
    Feb 2 '17 at 0:33






  • 1





    @opert is correct: setopt share_history is what will accomplish the desired result. @MJB would you be willing to edit your answer to remove the mention of setopt inc_append_history? It obscures the actual answer.

    – bonh
    Feb 22 '17 at 16:40











  • Names are case insensitive and underscores are ignored so if you setopt | grep hist will get incappendhistory and sharehistory.

    – Pablo Bianchi
    Oct 5 '17 at 21:16


















34














The following options would be applicable:





  • To save every command before it is executed (this is different from bash's history -a solution):



    setopt inc_append_history



  • To read the history file everytime history is called upon as well as the functionality from inc_append_history:



    setopt share_history



These can be set in your .zshrc file.



Related for bash:




  • Is it possible to make writing to .bash_history immediate?






share|improve this answer





















  • 4





    "SHARE_HISTORY: 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)." (From manual emphasis added) i.e. just the INC_APPEND_HISTORY option will do what you want.

    – artfulrobot
    Oct 20 '14 at 10:30








  • 3





    Actually, just the SHARE_HISTORY option alone will do what you want. The phrase "which should be turned off if this option is in effect" translates to "[INC_APPEND_HISTORY] should be turned off if [SHARE_HISTORY] option is in effect". I've tested this on zsh 5.1.1 on Ubuntu Xenial.

    – Linus Arver
    Feb 2 '17 at 0:33






  • 1





    @opert is correct: setopt share_history is what will accomplish the desired result. @MJB would you be willing to edit your answer to remove the mention of setopt inc_append_history? It obscures the actual answer.

    – bonh
    Feb 22 '17 at 16:40











  • Names are case insensitive and underscores are ignored so if you setopt | grep hist will get incappendhistory and sharehistory.

    – Pablo Bianchi
    Oct 5 '17 at 21:16
















34












34








34







The following options would be applicable:





  • To save every command before it is executed (this is different from bash's history -a solution):



    setopt inc_append_history



  • To read the history file everytime history is called upon as well as the functionality from inc_append_history:



    setopt share_history



These can be set in your .zshrc file.



Related for bash:




  • Is it possible to make writing to .bash_history immediate?






share|improve this answer















The following options would be applicable:





  • To save every command before it is executed (this is different from bash's history -a solution):



    setopt inc_append_history



  • To read the history file everytime history is called upon as well as the functionality from inc_append_history:



    setopt share_history



These can be set in your .zshrc file.



Related for bash:




  • Is it possible to make writing to .bash_history immediate?







share|improve this answer














share|improve this answer



share|improve this answer








edited 2 days ago









Chris Stryczynski

2721212




2721212










answered Jan 28 '11 at 2:18









MJBMJB

1,03411021




1,03411021








  • 4





    "SHARE_HISTORY: 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)." (From manual emphasis added) i.e. just the INC_APPEND_HISTORY option will do what you want.

    – artfulrobot
    Oct 20 '14 at 10:30








  • 3





    Actually, just the SHARE_HISTORY option alone will do what you want. The phrase "which should be turned off if this option is in effect" translates to "[INC_APPEND_HISTORY] should be turned off if [SHARE_HISTORY] option is in effect". I've tested this on zsh 5.1.1 on Ubuntu Xenial.

    – Linus Arver
    Feb 2 '17 at 0:33






  • 1





    @opert is correct: setopt share_history is what will accomplish the desired result. @MJB would you be willing to edit your answer to remove the mention of setopt inc_append_history? It obscures the actual answer.

    – bonh
    Feb 22 '17 at 16:40











  • Names are case insensitive and underscores are ignored so if you setopt | grep hist will get incappendhistory and sharehistory.

    – Pablo Bianchi
    Oct 5 '17 at 21:16
















  • 4





    "SHARE_HISTORY: 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)." (From manual emphasis added) i.e. just the INC_APPEND_HISTORY option will do what you want.

    – artfulrobot
    Oct 20 '14 at 10:30








  • 3





    Actually, just the SHARE_HISTORY option alone will do what you want. The phrase "which should be turned off if this option is in effect" translates to "[INC_APPEND_HISTORY] should be turned off if [SHARE_HISTORY] option is in effect". I've tested this on zsh 5.1.1 on Ubuntu Xenial.

    – Linus Arver
    Feb 2 '17 at 0:33






  • 1





    @opert is correct: setopt share_history is what will accomplish the desired result. @MJB would you be willing to edit your answer to remove the mention of setopt inc_append_history? It obscures the actual answer.

    – bonh
    Feb 22 '17 at 16:40











  • Names are case insensitive and underscores are ignored so if you setopt | grep hist will get incappendhistory and sharehistory.

    – Pablo Bianchi
    Oct 5 '17 at 21:16










4




4





"SHARE_HISTORY: 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)." (From manual emphasis added) i.e. just the INC_APPEND_HISTORY option will do what you want.

– artfulrobot
Oct 20 '14 at 10:30







"SHARE_HISTORY: 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)." (From manual emphasis added) i.e. just the INC_APPEND_HISTORY option will do what you want.

– artfulrobot
Oct 20 '14 at 10:30






3




3





Actually, just the SHARE_HISTORY option alone will do what you want. The phrase "which should be turned off if this option is in effect" translates to "[INC_APPEND_HISTORY] should be turned off if [SHARE_HISTORY] option is in effect". I've tested this on zsh 5.1.1 on Ubuntu Xenial.

– Linus Arver
Feb 2 '17 at 0:33





Actually, just the SHARE_HISTORY option alone will do what you want. The phrase "which should be turned off if this option is in effect" translates to "[INC_APPEND_HISTORY] should be turned off if [SHARE_HISTORY] option is in effect". I've tested this on zsh 5.1.1 on Ubuntu Xenial.

– Linus Arver
Feb 2 '17 at 0:33




1




1





@opert is correct: setopt share_history is what will accomplish the desired result. @MJB would you be willing to edit your answer to remove the mention of setopt inc_append_history? It obscures the actual answer.

– bonh
Feb 22 '17 at 16:40





@opert is correct: setopt share_history is what will accomplish the desired result. @MJB would you be willing to edit your answer to remove the mention of setopt inc_append_history? It obscures the actual answer.

– bonh
Feb 22 '17 at 16:40













Names are case insensitive and underscores are ignored so if you setopt | grep hist will get incappendhistory and sharehistory.

– Pablo Bianchi
Oct 5 '17 at 21:16







Names are case insensitive and underscores are ignored so if you setopt | grep hist will get incappendhistory and sharehistory.

– Pablo Bianchi
Oct 5 '17 at 21:16















4














If you use Robby Russell’s awesome OhMyZSH, it will take care of this and more.



See https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/history.zsh



That includes setopt inc_append_history.






share|improve this answer


























  • It's his/hers/its. Important for shell work.

    – Cees Timmerman
    Oct 13 '16 at 12:36











  • @CeesTimmerman fixed, thank you. It's important for communication in general I believe. What did you mean by "Important for shell work"?

    – james_womack
    Oct 13 '16 at 19:01






  • 1





    A typo in the shell can corrupt your entire system.

    – Cees Timmerman
    Oct 13 '16 at 21:52
















4














If you use Robby Russell’s awesome OhMyZSH, it will take care of this and more.



See https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/history.zsh



That includes setopt inc_append_history.






share|improve this answer


























  • It's his/hers/its. Important for shell work.

    – Cees Timmerman
    Oct 13 '16 at 12:36











  • @CeesTimmerman fixed, thank you. It's important for communication in general I believe. What did you mean by "Important for shell work"?

    – james_womack
    Oct 13 '16 at 19:01






  • 1





    A typo in the shell can corrupt your entire system.

    – Cees Timmerman
    Oct 13 '16 at 21:52














4












4








4







If you use Robby Russell’s awesome OhMyZSH, it will take care of this and more.



See https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/history.zsh



That includes setopt inc_append_history.






share|improve this answer















If you use Robby Russell’s awesome OhMyZSH, it will take care of this and more.



See https://github.com/robbyrussell/oh-my-zsh/blob/master/lib/history.zsh



That includes setopt inc_append_history.







share|improve this answer














share|improve this answer



share|improve this answer








edited Sep 12 '18 at 14:46









bfirsh

32




32










answered Apr 13 '15 at 16:57









james_womackjames_womack

1414




1414













  • It's his/hers/its. Important for shell work.

    – Cees Timmerman
    Oct 13 '16 at 12:36











  • @CeesTimmerman fixed, thank you. It's important for communication in general I believe. What did you mean by "Important for shell work"?

    – james_womack
    Oct 13 '16 at 19:01






  • 1





    A typo in the shell can corrupt your entire system.

    – Cees Timmerman
    Oct 13 '16 at 21:52



















  • It's his/hers/its. Important for shell work.

    – Cees Timmerman
    Oct 13 '16 at 12:36











  • @CeesTimmerman fixed, thank you. It's important for communication in general I believe. What did you mean by "Important for shell work"?

    – james_womack
    Oct 13 '16 at 19:01






  • 1





    A typo in the shell can corrupt your entire system.

    – Cees Timmerman
    Oct 13 '16 at 21:52

















It's his/hers/its. Important for shell work.

– Cees Timmerman
Oct 13 '16 at 12:36





It's his/hers/its. Important for shell work.

– Cees Timmerman
Oct 13 '16 at 12:36













@CeesTimmerman fixed, thank you. It's important for communication in general I believe. What did you mean by "Important for shell work"?

– james_womack
Oct 13 '16 at 19:01





@CeesTimmerman fixed, thank you. It's important for communication in general I believe. What did you mean by "Important for shell work"?

– james_womack
Oct 13 '16 at 19:01




1




1





A typo in the shell can corrupt your entire system.

– Cees Timmerman
Oct 13 '16 at 21:52





A typo in the shell can corrupt your entire system.

– Cees Timmerman
Oct 13 '16 at 21:52


















draft saved

draft discarded




















































Thanks for contributing an answer to Ask Ubuntu!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2faskubuntu.com%2fquestions%2f23630%2fhow-do-you-share-history-between-terminals-in-zsh%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

How did Captain America manage to do this?

迪纳利

南乌拉尔铁路局