Zsh: consistent history between machines

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
0
down vote

favorite












Use case: distribute zsh's history between machines in source control.



Is that something that I can achieve with zsh's history -- put history in version control the sync between mahcines? This is to avoid re-typing commands and quick trace.










share|improve this question























  • Zsh saves history in ~/.zsh_history.
    – Henrik
    2 hours ago














up vote
0
down vote

favorite












Use case: distribute zsh's history between machines in source control.



Is that something that I can achieve with zsh's history -- put history in version control the sync between mahcines? This is to avoid re-typing commands and quick trace.










share|improve this question























  • Zsh saves history in ~/.zsh_history.
    – Henrik
    2 hours ago












up vote
0
down vote

favorite









up vote
0
down vote

favorite











Use case: distribute zsh's history between machines in source control.



Is that something that I can achieve with zsh's history -- put history in version control the sync between mahcines? This is to avoid re-typing commands and quick trace.










share|improve this question















Use case: distribute zsh's history between machines in source control.



Is that something that I can achieve with zsh's history -- put history in version control the sync between mahcines? This is to avoid re-typing commands and quick trace.







zsh command-history version-control






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited 2 mins ago









Jeff Schaller

35.2k952115




35.2k952115










asked 3 hours ago









Tuyen Pham

375111




375111











  • Zsh saves history in ~/.zsh_history.
    – Henrik
    2 hours ago
















  • Zsh saves history in ~/.zsh_history.
    – Henrik
    2 hours ago















Zsh saves history in ~/.zsh_history.
– Henrik
2 hours ago




Zsh saves history in ~/.zsh_history.
– Henrik
2 hours ago










1 Answer
1






active

oldest

votes

















up vote
1
down vote













Modify PROMPT_COMMAND since it executes before each new prompt line.



11:40:22 jmunsch@pop-os network → export OLD_PROMPT=$PROMPT_COMMAND
11:52:38 jmunsch@pop-os network → unset PROMPT_COMMAND && export PROMPT_COMMAND="echo ssh copy the files to another machine; $PROMPT_COMMAND"
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → pwd
/etc/systemd/network
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → export PROMPT_COMMAND=$OLD_PROMPT
11:53:09 jmunsch@pop-os network →


One possible way to do this, you can update the .zshrc on each machine, this would also work for a .bashrc, i'm not sure how reliable, or consistent it will be if a bunch of commands are running across multiple machines at the same time:



# across terminals, sessions, and machines
export machine1=192.168.43.70
export OLD_PROMPT=$PROMPT_COMMAND
unset PROMPT_COMMAND
export PROMPT_COMMAND="history -a; history -c; history -r; scp ~/.zsh_history $machine1:~/.zsh_history; $PROMPT_COMMAND"


history flags explained:




  • -a append the current session history to the history file


  • -c clear the sessions history


  • -r read the history file into the session history

scp explained:



  • ssh copy your current ~/.zsh_history

  • to a remote location on machine1 `$machine1:/home/someuser/remote/location

  • you can do this for multiple machines by repeating the ssh copy for each address

To make it easier to do this



  • Setup key based ssh login.

  • Add hostnames/usernames to the .ssh/ssh_config.





share|improve this answer






















  • Can you give an explanation on export PROMPT_COMMAND="history -a; history -c; <...>, still look ambiguous to me. Even though I don't work at both machines at the same time, your setup look interesting for another use-case that I would cross in the future.
    – Tuyen Pham
    1 hour ago










  • @TuyenPham updated
    – jmunsch
    51 mins ago










Your Answer








StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "106"
;
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',
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
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%2funix.stackexchange.com%2fquestions%2f479592%2fzsh-consistent-history-between-machines%23new-answer', 'question_page');

);

Post as a guest






























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes








up vote
1
down vote













Modify PROMPT_COMMAND since it executes before each new prompt line.



11:40:22 jmunsch@pop-os network → export OLD_PROMPT=$PROMPT_COMMAND
11:52:38 jmunsch@pop-os network → unset PROMPT_COMMAND && export PROMPT_COMMAND="echo ssh copy the files to another machine; $PROMPT_COMMAND"
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → pwd
/etc/systemd/network
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → export PROMPT_COMMAND=$OLD_PROMPT
11:53:09 jmunsch@pop-os network →


One possible way to do this, you can update the .zshrc on each machine, this would also work for a .bashrc, i'm not sure how reliable, or consistent it will be if a bunch of commands are running across multiple machines at the same time:



# across terminals, sessions, and machines
export machine1=192.168.43.70
export OLD_PROMPT=$PROMPT_COMMAND
unset PROMPT_COMMAND
export PROMPT_COMMAND="history -a; history -c; history -r; scp ~/.zsh_history $machine1:~/.zsh_history; $PROMPT_COMMAND"


history flags explained:




  • -a append the current session history to the history file


  • -c clear the sessions history


  • -r read the history file into the session history

scp explained:



  • ssh copy your current ~/.zsh_history

  • to a remote location on machine1 `$machine1:/home/someuser/remote/location

  • you can do this for multiple machines by repeating the ssh copy for each address

To make it easier to do this



  • Setup key based ssh login.

  • Add hostnames/usernames to the .ssh/ssh_config.





share|improve this answer






















  • Can you give an explanation on export PROMPT_COMMAND="history -a; history -c; <...>, still look ambiguous to me. Even though I don't work at both machines at the same time, your setup look interesting for another use-case that I would cross in the future.
    – Tuyen Pham
    1 hour ago










  • @TuyenPham updated
    – jmunsch
    51 mins ago














up vote
1
down vote













Modify PROMPT_COMMAND since it executes before each new prompt line.



11:40:22 jmunsch@pop-os network → export OLD_PROMPT=$PROMPT_COMMAND
11:52:38 jmunsch@pop-os network → unset PROMPT_COMMAND && export PROMPT_COMMAND="echo ssh copy the files to another machine; $PROMPT_COMMAND"
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → pwd
/etc/systemd/network
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → export PROMPT_COMMAND=$OLD_PROMPT
11:53:09 jmunsch@pop-os network →


One possible way to do this, you can update the .zshrc on each machine, this would also work for a .bashrc, i'm not sure how reliable, or consistent it will be if a bunch of commands are running across multiple machines at the same time:



# across terminals, sessions, and machines
export machine1=192.168.43.70
export OLD_PROMPT=$PROMPT_COMMAND
unset PROMPT_COMMAND
export PROMPT_COMMAND="history -a; history -c; history -r; scp ~/.zsh_history $machine1:~/.zsh_history; $PROMPT_COMMAND"


history flags explained:




  • -a append the current session history to the history file


  • -c clear the sessions history


  • -r read the history file into the session history

scp explained:



  • ssh copy your current ~/.zsh_history

  • to a remote location on machine1 `$machine1:/home/someuser/remote/location

  • you can do this for multiple machines by repeating the ssh copy for each address

To make it easier to do this



  • Setup key based ssh login.

  • Add hostnames/usernames to the .ssh/ssh_config.





share|improve this answer






















  • Can you give an explanation on export PROMPT_COMMAND="history -a; history -c; <...>, still look ambiguous to me. Even though I don't work at both machines at the same time, your setup look interesting for another use-case that I would cross in the future.
    – Tuyen Pham
    1 hour ago










  • @TuyenPham updated
    – jmunsch
    51 mins ago












up vote
1
down vote










up vote
1
down vote









Modify PROMPT_COMMAND since it executes before each new prompt line.



11:40:22 jmunsch@pop-os network → export OLD_PROMPT=$PROMPT_COMMAND
11:52:38 jmunsch@pop-os network → unset PROMPT_COMMAND && export PROMPT_COMMAND="echo ssh copy the files to another machine; $PROMPT_COMMAND"
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → pwd
/etc/systemd/network
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → export PROMPT_COMMAND=$OLD_PROMPT
11:53:09 jmunsch@pop-os network →


One possible way to do this, you can update the .zshrc on each machine, this would also work for a .bashrc, i'm not sure how reliable, or consistent it will be if a bunch of commands are running across multiple machines at the same time:



# across terminals, sessions, and machines
export machine1=192.168.43.70
export OLD_PROMPT=$PROMPT_COMMAND
unset PROMPT_COMMAND
export PROMPT_COMMAND="history -a; history -c; history -r; scp ~/.zsh_history $machine1:~/.zsh_history; $PROMPT_COMMAND"


history flags explained:




  • -a append the current session history to the history file


  • -c clear the sessions history


  • -r read the history file into the session history

scp explained:



  • ssh copy your current ~/.zsh_history

  • to a remote location on machine1 `$machine1:/home/someuser/remote/location

  • you can do this for multiple machines by repeating the ssh copy for each address

To make it easier to do this



  • Setup key based ssh login.

  • Add hostnames/usernames to the .ssh/ssh_config.





share|improve this answer














Modify PROMPT_COMMAND since it executes before each new prompt line.



11:40:22 jmunsch@pop-os network → export OLD_PROMPT=$PROMPT_COMMAND
11:52:38 jmunsch@pop-os network → unset PROMPT_COMMAND && export PROMPT_COMMAND="echo ssh copy the files to another machine; $PROMPT_COMMAND"
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → pwd
/etc/systemd/network
ssh copy the files to another machine
11:52:38 jmunsch@pop-os network → export PROMPT_COMMAND=$OLD_PROMPT
11:53:09 jmunsch@pop-os network →


One possible way to do this, you can update the .zshrc on each machine, this would also work for a .bashrc, i'm not sure how reliable, or consistent it will be if a bunch of commands are running across multiple machines at the same time:



# across terminals, sessions, and machines
export machine1=192.168.43.70
export OLD_PROMPT=$PROMPT_COMMAND
unset PROMPT_COMMAND
export PROMPT_COMMAND="history -a; history -c; history -r; scp ~/.zsh_history $machine1:~/.zsh_history; $PROMPT_COMMAND"


history flags explained:




  • -a append the current session history to the history file


  • -c clear the sessions history


  • -r read the history file into the session history

scp explained:



  • ssh copy your current ~/.zsh_history

  • to a remote location on machine1 `$machine1:/home/someuser/remote/location

  • you can do this for multiple machines by repeating the ssh copy for each address

To make it easier to do this



  • Setup key based ssh login.

  • Add hostnames/usernames to the .ssh/ssh_config.






share|improve this answer














share|improve this answer



share|improve this answer








edited 44 mins ago

























answered 1 hour ago









jmunsch

1,5331920




1,5331920











  • Can you give an explanation on export PROMPT_COMMAND="history -a; history -c; <...>, still look ambiguous to me. Even though I don't work at both machines at the same time, your setup look interesting for another use-case that I would cross in the future.
    – Tuyen Pham
    1 hour ago










  • @TuyenPham updated
    – jmunsch
    51 mins ago
















  • Can you give an explanation on export PROMPT_COMMAND="history -a; history -c; <...>, still look ambiguous to me. Even though I don't work at both machines at the same time, your setup look interesting for another use-case that I would cross in the future.
    – Tuyen Pham
    1 hour ago










  • @TuyenPham updated
    – jmunsch
    51 mins ago















Can you give an explanation on export PROMPT_COMMAND="history -a; history -c; <...>, still look ambiguous to me. Even though I don't work at both machines at the same time, your setup look interesting for another use-case that I would cross in the future.
– Tuyen Pham
1 hour ago




Can you give an explanation on export PROMPT_COMMAND="history -a; history -c; <...>, still look ambiguous to me. Even though I don't work at both machines at the same time, your setup look interesting for another use-case that I would cross in the future.
– Tuyen Pham
1 hour ago












@TuyenPham updated
– jmunsch
51 mins ago




@TuyenPham updated
– jmunsch
51 mins ago

















 

draft saved


draft discarded















































 


draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f479592%2fzsh-consistent-history-between-machines%23new-answer', 'question_page');

);

Post as a guest













































































Popular posts from this blog

Peggy Mitchell

Palaiologos

The Forum (Inglewood, California)