From a4da2efa2eea2be9ae3e5b46ad1d7c4617e646f0 Mon Sep 17 00:00:00 2001 From: mrjk Date: Tue, 12 Jan 2021 18:19:44 -0500 Subject: [PATCH] Add: Reenable last ID when shell opens --- lib/idmgr_mod_id.sh | 44 +++++++++++++++++++++++++++----------------- shell/bash.sh | 17 ++++++++++++++++- 2 files changed, 43 insertions(+), 18 deletions(-) diff --git a/lib/idmgr_mod_id.sh b/lib/idmgr_mod_id.sh index bad5b85..0522efb 100644 --- a/lib/idmgr_mod_id.sh +++ b/lib/idmgr_mod_id.sh @@ -28,6 +28,7 @@ idm_id__disable() { # Disable internal variables echo "unset SHELL_ID GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL" | lib_log CODE - + idm_id_save_last_id _ } idm_id__kill () { idm_id__disable ${@-}; } @@ -43,6 +44,8 @@ idm_id__enable () echo "export GIT_AUTHOR_NAME='${common_name:-$id}'" echo "export GIT_AUTHOR_EMAIL='${email}'" + idm_id_save_last_id $id + # echo "export PATH=${XDG_OPT_HOME}/bin:$PATH" # echo "export SSH_CONFIG=${id}" # echo "export SSH_AUTH_SOCK=/tmp/ssh-S88jysAIp3qs/${id}-agent.1767" @@ -180,23 +183,6 @@ idm_id__dump () done } -idm_id_template () -{ - local cn=${1-} - local hostname=${2-} - local tz lang - - # Auto guess - tz=$( timedatectl | grep "Time zone" | awk '{print $3}' || true ) - - echo "common_name=${cn}" - echo "login=${cn}" - echo "email=" - echo "tz=$tz" - echo "public=false" - echo "hostname=${hostname:-$(hostname -f)}" - -} idm_id__rm () { local id=${1} @@ -214,3 +200,27 @@ idm_id__rm () lib_log WARN "File '$IDM_DIR_ID/$id.env' was already deleted" fi } + +idm_id_save_last_id () +{ + local id=${1} + echo "$id" > "$IDM_DIR_CACHE/last_id" +} + +idm_id_template () +{ + local cn=${1-} + local hostname=${2-} + local tz lang + + # Auto guess + tz=$( timedatectl | grep "Time zone" | awk '{print $3}' || true ) + + echo "common_name=${cn}" + echo "login=${cn}" + echo "email=" + echo "tz=$tz" + echo "public=false" + echo "hostname=${hostname:-$(hostname -f)}" + +} diff --git a/shell/bash.sh b/shell/bash.sh index 2e1b9c8..b493b5d 100644 --- a/shell/bash.sh +++ b/shell/bash.sh @@ -33,9 +33,24 @@ i () } +i_restore_last_id () +{ + local IDM_DIR_CACHE=${IDM_DIR_CACHE:-${XDG_CACHE_HOME:-~/.cache}/idmgr} + local state_file=$IDM_DIR_CACHE/last_id + if [ -f "$state_file" ]; then + local id=$(cat "$state_file") + if ! [ -z "${id//_/}" ]; then + >&2 echo "INFO: Auto enabling last id: $id" + i enable $id + fi + fi + +} + + # Disable when pressing C-b in shell :) bind -x '"\C-b": i disable' - +i_restore_last_id