Created
January 13, 2026 21:27
-
-
Save dbrand666/0b54c5edc659b69bf8dd7134277d9445 to your computer and use it in GitHub Desktop.
Preserve multi-tab history in ptyaxis
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Drop this file into ~/.bashrc.d/ptyxis-history | |
| HISTDIR=~/.history | |
| HISTFILE="$HISTDIR/$$" | |
| mkdir "$HISTDIR" 2>/dev/null | |
| function get_peers() { | |
| ps --no-headers -o pid --ppid $PPID | |
| } | |
| function filter_level0_shells() { | |
| xargs -I'{}' sed -n 's/.*SHLVL=0.*/{}\n/p' /proc/'{}'/environ | |
| } | |
| function get_history_files() { | |
| (cd "$HISTDIR" && ls) | |
| } | |
| function get_orphaned_history_files() { | |
| get_history_files |fgrep -v -f <(get_peers |filter_level0_shells) | |
| } | |
| function adopt_a_history_file() { | |
| for histfile in $(get_orphaned_history_files) ;do | |
| if (cd "$HISTDIR" && flock .LOCKFILE sh -c "[ -f '$histfile' ] && mv '$histfile' '$HISTFILE'") ;then | |
| return 0 | |
| fi | |
| done | |
| return 1 | |
| } | |
| if ! adopt_a_history_file; then | |
| >"$HISTFILE" | |
| fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment