diff --git a/profile.bash b/profile.bash new file mode 100755 index 0000000..a60dce0 --- /dev/null +++ b/profile.bash @@ -0,0 +1,51 @@ +#!/bin/bash + +function __keep_preexec { + KEEP_META_command="$1" + KEEP_META_directory=${KEEP_META_directory:-${PWD}} + KEEP_META_hostname=${KEEP_META_hostname:-${HOSTNAME:-$(hostname -f)}} + KEEP_META_tty=${KEEP_META_tty:-$(tty)} +} + +function __keep_preexec_init { + local found=false + local f + for f in "${preexec_functions[@]}"; do + if [[ $f = __keep_preexec ]]; then + found=true + break + fi + done + + if [[ $found = false ]]; then + preexec_functions+=(__keep_preexec) + fi + + if [[ -z $KEEP_LIST_META ]]; then + export KEEP_LIST_META="hostname,command" + fi +} + +function keep { + ( + if [[ $BASH_SUBSHELL -eq 2 ]]; then + export KEEP_META_command + fi + + export KEEP_META_directory + export KEEP_META_hostname + export KEEP_META_tty + + exec keep "$@" + ) +} + +function @ { + keep --save "$@" +} + +function @@ { + keep --get "$@" +} + +__keep_preexec_init