diff --git a/PS1 b/PS1 index b6457d5..1a6fd95 100644 --- a/PS1 +++ b/PS1 @@ -9,6 +9,7 @@ parse_git_branch() { [ -z "${RBRANCH-x}" ] && unset RBRANCH local BRANCH="${LBRANCH}${RBRANCH+ -> }${RBRANCH}" [ -z "${BRANCH-x}" ] || echo "($BRANCH)"|tr -s '()' + return 0 } set_label() { @@ -127,26 +128,41 @@ case "$TERM" in *) SCREEN="";; esac - # Base prompt - if [ "`id -u`" -eq 0 ]; then - PS1="\[$BRed\]$SCREEN\u@\h \[$BRed\]\[\e[m\]\[$IPurple\](\A)\[\e[m\]\$(set_label)\n\[$BRed\]${SYSSUBVOL}\w:\$(parse_git_branch) \[\e[m\]\[$BRed\]# " - else - PS1="\[$BIBlue\]$SCREEN\u@\h \[$BIBlue\]\[\e[m\]\[$IPurple\](\A)\[\e[m\]\$(set_label)\n\[$BIBlue\]${SYSSUBVOL}\w:\$(parse_git_branch) \[\e[m\]\[$BIBlue\]\$ " - fi +# # Base prompt +# if [ "`id -u`" -eq 0 ]; then +# PS1="\[$BRed\]${SCREEN}${SYSSUBVOL}\u@\h \[$BRed\]\[\e[m\]\[$IPurple\](\A)\[\e[m\]\$(set_label)\n\[$BRed\]${SYSSUBVOL}\w:\$(parse_git_branch) \[\e[m\]\[$BRed\]# " +# else +# PS1="\[$BIBlue\]${SCREEN}${SYSSUBVOL}\u@\h \[$BIBlue\]\[\e[m\]\[$IPurple\](\A)\[\e[m\]\$(set_label)\n\[$BIBlue\]${SYSSUBVOL}\w:\$(parse_git_branch) \[\e[m\]\[$BIBlue\]\$ " +# fi RETVAL0="\342\234\223" RETVALN0="\342\234\227 " ;; *) - # Base prompt - if [ "`id -u`" -eq 0 ]; then - PS1="\[$BRed\][$SYSSUBVOL]\u@\h \[$BIBlue\]\[\e[m\]\[$BIPurple\](\A)\[\e[m\]\[$BBlue\]\$(set_label)\n\[$BRed\]${SYSSUBVOL}\w:\$(parse_git_branch) \$ \[\e[m\]\[$Blue\]" - else - PS1="\[$BBlue\][$SYSSUBVOL]\u@\h \[$BIBlue\]\[\e[m\]\[$BIPurple\](\A)\[\e[m\]\[$BBlue\]\$(set_label)\n\[$BIBlue\]${SYSSUBVOL}\w:\$(parse_git_branch) \$ \[\e[m\]\[$Blue\]" - fi +# # Base prompt +# if [ "`id -u`" -eq 0 ]; then +# PS1="\[$BRed\][$SYSSUBVOL]\u@\h \[$BIBlue\]\[\e[m\]\[$BIPurple\](\A)\[\e[m\]\[$BBlue\]\$(set_label)\n\[$BRed\]${SYSSUBVOL}\w:\$(parse_git_branch) \$ \[\e[m\]\[$Blue\]" +# else +# PS1="\[$BBlue\][$SYSSUBVOL]\u@\h \[$BIBlue\]\[\e[m\]\[$BIPurple\](\A)\[\e[m\]\[$BBlue\]\$(set_label)\n\[$BIBlue\]${SYSSUBVOL}\w:\$(parse_git_branch) \$ \[\e[m\]\[$Blue\]" +# fi RETVAL0=":)" RETVALN0=":(" ;; esac -PS1="( \$? \$(if [[ \$? == 0 ]]; then echo \"\[$Green\]${RETVAL0}\"; else echo \"\[$Red\]${RETVALN0}\"; fi )\[\e[m\]) ${PS1}\[\e[m\]" + +# Base prompt +#if [ "`id -u`" -eq 0 ]; then +# PS1="\[$BRed\]${SCREEN}${SYSSUBVOL}\u@\h \[$BRed\]\[\e[m\]\[$IPurple\](\A)\[\e[m\]\$(set_label)\n\[$BRed\]${SYSSUBVOL}\w:\$(parse_git_branch) \[\e[m\]\[$BRed\]# " +#else +# PS1="\[$BIBlue\]${SCREEN}${SYSSUBVOL}\u@\h \[$BIBlue\]\[\e[m\]\[$IPurple\](\A)\[\e[m\]\$(set_label)\n\[$BIBlue\]${SYSSUBVOL}\w:\$(parse_git_branch) \[\e[m\]\[$BIBlue\]\$ " +#fi + +if [ "`id -u`" -eq 0 ]; then + PS1="\[$BRed\]${SCREEN}${SYSSUBVOL}\u@\h \[$BRed\]\[\e[m\]\[$IPurple\](\A)\[\e[m\]\$(set_label)\n\[$BRed\]${SYSSUBVOL}\w:\$(parse_git_branch) \[\e[m\]\[$BRed\]# " +else + PS1="\[$BIBlue\]${SCREEN}${SYSSUBVOL}\u@\h \[$BIBlue\]\[\e[m\]\[$IPurple\](\A)\[\e[m\]\$(set_label)\n\[$BIBlue\]${SYSSUBVOL}\w:\$(parse_git_branch) \[\e[m\]\[$BIBlue\]\$ " +fi + +PS1="( \$? \$(if [[ \$? == 0 ]]; then echo \"\[$Green\]${RETVAL0}\"; else echo \"\[$Red\]${RETVALN0}\"; fi )\[\e[m\]) ${PS1}\[\e[m\]" + #trap 'echo -ne "\e[0m"' DEBUG diff --git a/bashrc_add b/bashrc_add index 32e7645..be3fbcc 100755 --- a/bashrc_add +++ b/bashrc_add @@ -199,19 +199,18 @@ EOF _tmux_hook _umask_hook #_pkcs11module_hook - promptcommandmunge "_tmux_hook" - promptcommandmunge "_umask_hook" - #promptcommandmunge "_pkcs11module_hook" - promptcommandmunge "_bashrc_tmp_hook" - promptcommandmunge "_remote_ssh_agent_hook" + [[ $(type -t _umask_hook) == function ]] && promptcommandmunge "_umask_hook" + [[ $(type -t _tmux_hook) == function ]] && promptcommandmunge "_tmux_hook" + #[[ $(type -t _pkcs11module_hook) == function ]] && promptcommandmunge "_pkcs11module_hook" + [[ $(type -t _bashrc_tmp_hook) == function ]] && promptcommandmunge "_bashrc_tmp_hook" + [[ $(type -t _remote_ssh_agent_hook) == function ]] && promptcommandmunge "_remote_ssh_agent_hook" + #[[ $(type -t _ps1_hook) == function ]] && promptcommandmunge "_ps1_hook" which direnv >/dev/null && eval "$(direnv hook bash)" cat << EOF >> "${MSC_LOGFILE}" ==8<=== finished configure new shell ================ $(date) ===============8<== EOF - #else - # echo "non-interactive shell" >&2 SCRIPTEXIT # Start tmux if not defined as STARTTMUX in bashrc diff --git a/functions.sh b/functions.sh index 68de191..f1705d5 100755 --- a/functions.sh +++ b/functions.sh @@ -21,6 +21,29 @@ promptcommandmunge () { EXIT } +_ps1_hook() { + local EXIT="$?" # This needs to be first + PS1="" + + local RCol='\[\e[0m\]' + local Red='\[\e[0;31m\]' + local Gre='\[\e[0;32m\]' + local BYel='\[\e[1;33m\]' + local BBlu='\[\e[1;34m\]' + local Pur='\[\e[0;35m\]' + + echo EXIT $EXIT + if [ $EXIT != 0 ]; then + PS1+="${Red}\u${RCol}" # Add red if exit code non 0 + else + PS1+="${Gre}\u${RCol}" + fi + + PS1+="${RCol}@${BBlu}\h ${Pur}\W${BYel}$ ${RCol}" + + +} + _bashrc_tmp_hook() { if [ ! -z "${bashrctmp:-x}" ]; then @@ -96,7 +119,6 @@ function _tmux_hook() { if [ -n "${TMUX:-}" ]; then eval "$(tmux show-environment -s)" fi - } function _umask_hook { diff --git a/myshell_load_defaults b/myshell_load_defaults index e35cd6d..1679c6f 100644 --- a/myshell_load_defaults +++ b/myshell_load_defaults @@ -1,8 +1,10 @@ #!/bin/bash -# if we are root, exit after 5 Minutes case $(tty) in + # if we run on console, then terminate shell /dev/tty[0-9]*) + # if we are root, exit after 5 minutes + # if we are user, exit after 10 minutes case $(id -u) in 0) TMOUT=${MSC_ROOT_TMOUT:-500} @@ -104,14 +106,7 @@ if ! $SSHS; then fi fi -# if test ! $TMUX && test $SSH_TTY && test $TERM != screen && test $(systemctl status tmux@${USER}.service 1>/dev/null 2>&1; echo $? ) -eq 0; then -# : # STARTTMUXDEFAULT=${STARTTMUXREMOTEDEFAULT} -# logwarn "TEST1" -# else -# logwarn "TEST2" -# STARTTMUXDEFAULT=${STARTTMUXREMOTEDEFAULT} -# fi - logdebug "${STARTTMUXDEFAULT}" + logdebug "STARTTMUXDEFAULT: ${STARTTMUXDEFAULT}" unset -f pathmunge