Add: Reenable last ID when shell opens

This commit is contained in:
mrjk 2021-01-12 18:19:44 -05:00
parent c2d840d136
commit a4da2efa2e
2 changed files with 43 additions and 18 deletions

View File

@ -28,6 +28,7 @@ idm_id__disable()
{ {
# Disable internal variables # Disable internal variables
echo "unset SHELL_ID GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL" | lib_log CODE - echo "unset SHELL_ID GIT_AUTHOR_NAME GIT_AUTHOR_EMAIL" | lib_log CODE -
idm_id_save_last_id _
} }
idm_id__kill () { idm_id__disable ${@-}; } 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_NAME='${common_name:-$id}'"
echo "export GIT_AUTHOR_EMAIL='${email}'" echo "export GIT_AUTHOR_EMAIL='${email}'"
idm_id_save_last_id $id
# echo "export PATH=${XDG_OPT_HOME}/bin:$PATH" # echo "export PATH=${XDG_OPT_HOME}/bin:$PATH"
# echo "export SSH_CONFIG=${id}" # echo "export SSH_CONFIG=${id}"
# echo "export SSH_AUTH_SOCK=/tmp/ssh-S88jysAIp3qs/${id}-agent.1767" # echo "export SSH_AUTH_SOCK=/tmp/ssh-S88jysAIp3qs/${id}-agent.1767"
@ -180,23 +183,6 @@ idm_id__dump ()
done 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 () idm_id__rm ()
{ {
local id=${1} local id=${1}
@ -214,3 +200,27 @@ idm_id__rm ()
lib_log WARN "File '$IDM_DIR_ID/$id.env' was already deleted" lib_log WARN "File '$IDM_DIR_ID/$id.env' was already deleted"
fi 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)}"
}

View File

@ -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 :) # Disable when pressing C-b in shell :)
bind -x '"\C-b": i disable' bind -x '"\C-b": i disable'
i_restore_last_id