In zsh, you can do the following:
- Run a command in a shell.
- Run
fc -AI in that shell.
- Run
fc -RI in another shell.
- Run
!! or press Up then Enter in the second shell to recall the last command executed in the first shell.
fc -AI writes out the command history of the first shell, and fc -RI reads it back into the second shell. If you turn on the inc_append_history, then the equivalent of fc -AI is performed automatically after each command.
If you turn on the share_history option, then all history lines are automatically shared between all shell instances, so you can go straight from step 1 to step 4. This can feel invasive.
If you used a relative path to change the directory, you'll need to obtain an absolute path first. One way to do that is to type cd $PWD (or just $PWD if you have the auto_cd option turned on) and press Tab (or C-x * with some completion settings) to expand $PWD then press Enter.