make_bash_history_safe() {
  # save current history in memory to ~/.bash_history
  history -a
  # clear current history list in memory
  history -c
  # comment all uncommented commands in ~/.bash_history with sed
  sed -i -e 's/^\([^#]\)/# \1/g' ~/.bash_history
  # reload history in memory from ~/.bash_history file
  history -r
}
# execute make_bash_history_safe after each command execution
PROMPT_COMMAND="make_bash_history_safe; "

_remove_comment() {
  READLINE_LINE=$(echo "${READLINE_LINE}" | sed -E -e "s/^[# ]+//g")
}
bind -x '"\C-x\C-x": _remove_comment'
