Skip to content

Commit

Permalink
Append to Bash history after each command
Browse files Browse the repository at this point in the history
Update `prexec` to have a `precmd` counterpart and properly work with
the `z` util.
  • Loading branch information
Pinjasaur committed Jun 28, 2018
1 parent 8677ed5 commit 77c8f98
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 7 deletions.
32 changes: 28 additions & 4 deletions .bash_profile
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ shopt -s extglob
# Auto-cd to a directory without specifying 'cd' (e.g. foobar)
shopt -s autocd

# Source z (https://github.com/rupa/z)
# Don't have Z clobber the $PROMPT_COMMAND
export _Z_NO_PROMPT_COMMAND='1'

# Source Z (https://github.com/rupa/z)
source ~/.bash/z/z.sh

# Source Git Bash completion
Expand All @@ -28,14 +31,35 @@ for file in ~/.{exports,aliases,functions,bash_prompt,bash.local}; do
done
unset file

# Ran before every command
# The next two functions are helpers that mimic zsh's preexec & precmd:
# 1. preexec runs before every command
# 2. the command runs
# 3. precmd runs before the prompt

# Ran before every command (before `precmd`)
preexec() {
# Don't cause a preexec for PROMPT_COMMAND
# Beware! This fails if PROMPT_COMMAND is a string with more than one command
# Don't cause a preexec if completing
[ -n "$COMP_LINE" ] && return

# Don't cause a preexec for $PROMPT_COMMAND
[ "$BASH_COMMAND" = "$PROMPT_COMMAND" ] && return

# Update $DISPLAY to help avoid stale values within tmux
update-x11-forwarding

# Z
_z --add "$(command pwd '$_Z_RESOLVE_SYMLINKS' 2>/dev/null)" 2>/dev/null

# echo ">>> preexec <<<"
}

# Ran before every prompt (after `preexec`)
precmd() {
# Write current/new lines to histfile
history -a

# echo "<<< precmd >>>"
}

trap 'preexec' DEBUG
export PROMPT_COMMAND=precmd
6 changes: 3 additions & 3 deletions .tmux.conf
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ bind -n M-L swap-window -t +1

# Start window index at 1 (match keyboard order)
set -g base-index 1
setw -g pane-base-index 1
set -g pane-base-index 1

# Re-number windows sequentially after closing them
set -g renumber-windows on
Expand Down Expand Up @@ -93,12 +93,12 @@ set -g status-fg white
set -g window-status-current-bg red
set -g window-status-current-fg white
set -g window-status-current-attr bold
setw -g window-status-current-format '#{?pane_synchronized,>> ,}#I:#W#F#{?pane_synchronized, <<,}'
set -g window-status-current-format '#{?pane_synchronized,>> ,}#I:#W#F#{?pane_synchronized, <<,}'
set -g status-interval 1
set -g status-left-length 20 # default is 10
set -g status-right-length 60 # default is 40
set -g status-left '#[fg=white][#[fg=colour45]#S#[fg=white]] '
set -g status-right '#[fg=white][#[fg=colour196]#{continuum_status}#[fg=white]] %a, %Y-%m-%d at %H:%M:%S (#[fg=colour93]#(whoami)#[fg=white])'
set -g status-right '#[fg=white]%a, %Y-%m-%d at %H:%M:%S (#[fg=colour93]#(whoami)#[fg=white])'

# TPM Plugins
set -g @plugin 'tmux-plugins/tmux-resurrect'
Expand Down

0 comments on commit 77c8f98

Please sign in to comment.