#!/bin/echo "BASH Source Script ONLY" # vim:ft=bash # # history_edit.bash # # Edit the in-memory BASH history. # # This lets me manually look for and remove sensitive information from the # in-memory bash history, that I may had just recently typed in. For example # commands containing passwords, or other cryptographic information, that may # have (just) been typed on the CLI. # # This does NOT write the history file to ".bash_history", only save, edit # and reload the edited history back into memory. # # It would have been better if the information had not been placed into the # history, for example by using the BASH setting "HISTCONTROL=ignorespace", but # I never seem to remember to use it. I could also use "HISTIGNORE=" glob # patterns, but that never covers all situations. # # Also see "history_merge.bash" source script. # # WARNING: Before bash version 5, bash would not read timestamped history # files containing multi-line command correctly. The mutliple lines would # become seperate individual entries. # ### # # he() { source ~/bin/history_edit.bash; } # edit history # ### # # Anthony Thyssen - 3 July 2019 # # temprary file for editing the history histtmp=`mktemp "${TMPDIR:-/tmp}/history_edit.XXXXXXXXXX"` # Write history to s file so we can edit it. #history -w "$histtmp" # # Alt: Write to file for editing, expand timestamps to make it more readable. history -w /dev/stdout | perl -pe '$_ = `date --date=\@$1 +"#\%s - \%F_\%T"` if /^#(\d+)$/;' \ > "$histtmp" vim + "$histtmp" # edit the history, (start on last line) # Remove readable timestamp from edited file # # BASH does not use the extra data in timestamp lines, but also preserves them, # which can cause problems in other programs dealing with history. perl -i -pe 's/^(#\d+).*/$1/' "$histtmp" # replace in-memory history with edited history history -c # clear the current shells history list history -r "$histtmp" # read everything from the history file shred -u "$histtmp" || rm "$histtmp" # clean up unset histtmp