Skip to content

Commit 8101d98

Browse files
authored
Create restoring_bash_history.md
1 parent ca6468e commit 8101d98

File tree

1 file changed

+39
-0
lines changed

1 file changed

+39
-0
lines changed

docs/restoring_bash_history.md

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
tmux-ressurect no longer restores shell history for each pane, as of [this PR](https://github.com/tmux-plugins/tmux-resurrect/pull/308).
2+
3+
As a workaround, you can use the `HISTFILE` environment variable to preserve history for each pane separately, and modify
4+
`PROMPT_COMMAND` to make sure history gets saved with each new command.
5+
6+
Unfortunately, we haven't found a perfect way of getting a unique identifier for each pane, as the `TMUX_PANE` variable
7+
seems to occasionally change when resurrecting. As a workaround, the example below sets a unique ID in each pane's `title`.
8+
The downside of this implementation is that pane titles must all be unique across sessions/windows, and also must use the `pane_id_prefix`.
9+
10+
Any improvements/suggestions for getting a unique, persistent ID for each pane are welcome!
11+
12+
```bash
13+
pane_id_prefix="resurrect_"
14+
15+
# Create history directory if it doesn't exist
16+
HISTS_DIR=$HOME/.bash_history.d
17+
mkdir -p "${HISTS_DIR}"
18+
19+
if [ -n "${TMUX_PANE}" ]; then
20+
21+
# Check if we've already set this pane title
22+
pane_id=$(tmux display-message -p '#{pane_title}')
23+
if [[ $pane_id != "$pane_id_prefix"* ]]; then
24+
25+
# if not, set it to a random ID
26+
random_id=$(head /dev/urandom | tr -dc A-Za-z0-9 | head -c 16)
27+
printf "\033]2;$pane_id_prefix$random_id\033\\"
28+
pane_id=$(tmux display-message -p '#{pane_title}')
29+
fi
30+
31+
# use the pane's random ID for the HISTFILE
32+
export HISTFILE="${HISTS_DIR}/bash_history_tmux_${pane_id}"
33+
else
34+
export HISTFILE="${HISTS_DIR}/bash_history_no_tmux"
35+
fi
36+
37+
# Stash the new history each time a command runs.
38+
export PROMPT_COMMAND="$PROMPT_COMMAND;history -a"
39+
```

0 commit comments

Comments
 (0)