modify promptcommand, use direnv to set umask

This commit is contained in:
Jakobus Schürz 2020-11-28 17:42:42 +01:00
parent 98ffb534d4
commit 420cb4663c
2 changed files with 36 additions and 2 deletions

View file

@ -170,6 +170,9 @@ EOF
# source loading workaround for x2go to forward local etoken to remote machine with forwardagent
. "${MYSHELLCONFIG_BASE}/myshell_load_x2go_tokenforward"
promptcommandmunge "_prompt_command"
promptcommandmunge "_umask_hook"
which direnv >/dev/null && eval "$(direnv hook bash)"
cat << EOF >> "${MYSHELLCONFIG_LOGFILE}"
==8<=== finished configure new shell ================ $(date) ===============8<==

View file

@ -6,9 +6,23 @@
export TMUX_SESSION_DIRS SETPROXY_CREDS_DIRS KERBEROS_CONFIG_DIRS
promptcommandmunge () {
ENTRY
case ":${PROMPT_COMMAND}:" in
*:"$1":*)
;;
*)
if [ "$2" = "after" ] ; then
PROMPT_COMMAND=$PROMPT_COMMAND:$1
else
PROMPT_COMMAND=$1:$PROMPT_COMMAND
fi
esac
EXIT
}
## this function updates in combination with PROMPT_COMMAND the shell-environment-variables in tmus-sessions,
# every time prompt is called. It does it only, when called from tmux (Environment TMUX is set)
function prompt_command() {
function _prompt_command() {
# [ -z "${TMUX+x}" ] || eval "$(tmux show-environment -s)"
if [ -n "${TMUX}" ]; then
@ -16,8 +30,25 @@ function prompt_command() {
fi
}
PROMPT_COMMAND=prompt_command
# Append `;` if PROMPT_COMMAND is not empty
#PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND;}_prompt_command"
# To make the code more reliable on detecting the default umask
function _umask_hook {
# Record the default umask value on the 1st run
[[ -z $DEFAULT_UMASK ]] && export DEFAULT_UMASK="$(builtin umask)"
if [[ -n $UMASK ]]; then
umask "$UMASK"
else
umask "$DEFAULT_UMASK"
fi
}
# Append `;` if PROMPT_COMMAND is not empty
#PROMPT_COMMAND="${PROMPT_COMMAND:+$PROMPT_COMMAND;}_umask_hook"
cpb() {
scp "$1" ${SSH_CLIENT%% *}:~/Work