From c100ef9436a3a87f4573cc3fafd9d65d9b76c61b Mon Sep 17 00:00:00 2001 From: Andrew Phillips Date: Mon, 18 Sep 2023 14:29:38 +0000 Subject: [PATCH] Add bash profile --- profile.bash | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100755 profile.bash 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