Skip to content

Instantly share code, notes, and snippets.

@s1037989
Created September 25, 2024 09:52
Show Gist options
  • Save s1037989/5b12870d7ddb68f1b69b62bb0c8ff69f to your computer and use it in GitHub Desktop.
Save s1037989/5b12870d7ddb68f1b69b62bb0c8ff69f to your computer and use it in GitHub Desktop.
function cd {
local _TMUX_PANE=${TMUX_PANE:-%0}
HISTFILE=$HISTFILE_PREFIX-${_TMUX_PANE:1}
export LC_HISTFILE=$HISTFILE
if [ "$1" == -q ]; then shift; test -d "$1" || return; fi; builtin cd "$@"; echo $(pwd) > ${HISTFILE/bash_histories/pwd};
}
function history-file { echo $HISTFILE; }
function reload {
umask 0022
readonly -p | grep -q TMOUT= || unset TMOUT
test -n "$INITPWD" || INITPWD="$PWD"
history-config
return 0
}
function history-config {
test -d ~/.bash_histories || mkdir ~/.bash_histories
test -d ~/.pwd || mkdir ~/.pwd
HISTCONTROL=ignoreboth:erasedups
HISTIGNORE=history:ls:pwd
HISTSIZE=50000
HISTFILESIZE=
HISTTIMEFORMAT="%F %T "
LC_HISTFILE=${LC_HISTFILE/~}
LC_HISTFILE=${LC_HISTFILE:1}
TMUX_SOCKET=${TMUX%%,*}
TMUX_SOCKET=${TMUX_SOCKET##*/}
TMUX_SOCKET=${TMUX_SOCKET:-nosocket}
#HISTFILE=~/$(test -n "$TMUX" && tmux display -p ".bash_histories/#{host}-$TMUX_SOCKET-#{session_name}-#{window_index}-#{pane_index}" 2>/dev/null || echo ${LC_HISTFILE:-.bash_histories/$HOSTNAME-$TMUX_SOCKET})
HISTFILE_PREFIX=~/$(
if test -n "$TMUX"; then
tmux display -p ".bash_histories/#{host}-$TMUX_SOCKET-#{session_name}-#{window_index}" 2>/dev/null
elif test "$TERM_PROGRAM" == vscode; then
echo ${LC_HISTFILE:-.bash_histories/$HOSTNAME-$TMUX_SOCKET-${INITPWD//\//_}}
else
echo ${LC_HISTFILE:-.bash_histories/$HOSTNAME-$TMUX_SOCKET}
fi
)
local _TMUX_PANE=${TMUX_PANE:-%0}
HISTFILE=$HISTFILE_PREFIX-${_TMUX_PANE:1}
export LC_HISTFILE=$HISTFILE
shopt -s histappend
test -f ${HISTFILE/bash_histories/pwd} -a "$TERM_PROGRAM" != vscode && cd -q "$(< ${HISTFILE/bash_histories/pwd})"
return 0
}
reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment