From 3e46d7f6c8e0da7437dabfa77c49093e13d822f8 Mon Sep 17 00:00:00 2001 From: mrjk Date: Sat, 10 Feb 2018 23:50:38 -0500 Subject: [PATCH] Fix: Many little bugs and ps1 management --- bin/idmgr | 11 ++++++----- lib/idmgr_mod_id.sh | 4 ++-- lib/idmgr_mod_ps1.sh | 23 +++++++++-------------- shell/bash.sh | 1 + 4 files changed, 18 insertions(+), 21 deletions(-) diff --git a/bin/idmgr b/bin/idmgr index b27c411..a3888f7 100755 --- a/bin/idmgr +++ b/bin/idmgr @@ -168,7 +168,7 @@ idm_get () ;; id_config) - if [ -f "$value" ]; then + if [ -f "$IDM_DIR_ID/$value.env" ]; then echo "id=$value" cat $IDM_DIR_ID/$value.env else @@ -193,7 +193,9 @@ idm_validate () [[ "$value" =~ ^[a-zA-Z0-9_-]+$ ]] && return ;; id_config) - [[ -f "$IDM_DIR_ID/$value.env" ]] && return + if [[ -f "$IDM_DIR_ID/$value.env" ]]; then + return 0 + fi ;; is_enabled) [ ! -z "${SHELL_ID}" ] && return @@ -520,7 +522,7 @@ idm_menu_main () id=$1 elif idm_validate id_config ${2-} ; then menu=core - action=ls + action=$1 id=$2 shift 2 && opt=${@} || true elif idm_validate id_config ${3-} ; then @@ -574,8 +576,7 @@ idm_menu_main () return $? fi - idm_log DEBUG "menu=$menu action=$action id=$id opt=$opt" - idm_exit 1 "Command not matched" + idm_exit 1 "Command not matched: menu=$menu action=$action id=$id opt=$opt" } diff --git a/lib/idmgr_mod_id.sh b/lib/idmgr_mod_id.sh index e2cffa1..5780b5c 100644 --- a/lib/idmgr_mod_id.sh +++ b/lib/idmgr_mod_id.sh @@ -67,7 +67,7 @@ idm_id_enable() idm_id_new () { - local id=${1} + local id=${2:-$1} # Local checks idm_validate id $id || idm_exit 1 "Id '$id' is not valid" @@ -123,7 +123,7 @@ idm_id_ls () # Parse the config echo $( eval "$(idm_get id_config $id)" - echo "$active:$id:${common_name-} (${email-})" + echo "$active:$id::::${common_name-} (${email-})" ) done | column -t -s: -o' ' | idm_log DUMP - } diff --git a/lib/idmgr_mod_ps1.sh b/lib/idmgr_mod_ps1.sh index 107c6ce..04c8fe9 100644 --- a/lib/idmgr_mod_ps1.sh +++ b/lib/idmgr_mod_ps1.sh @@ -5,7 +5,7 @@ IDM_MOD_DEPS="id pass gpg ssh" ## Prompt functions ########################################## -SHELL_PS1="${SHELL_PS1:-[\\u@\\h \\W]\\$ }" +#SHELL_PS1="${SHELL_PS1:-${PS1}" idm_ps1 () { @@ -40,24 +40,19 @@ idm_ps1_help () idm_ps1_enable () { local id=${1} - -# \033]00m\] # for shell -#\[\033]01;31m\] for ps1 - - id="\[\033[0;34m\]($id)\[\033[00m\]" - PS1="$id ${PS1:-$SHELL_PS1}" - echo "export PS1='$PS1'" - echo "export SHELL_PS1='$PS1'" + echo "export PS1=\"$id \${IDM_SHELL_PS1}\"" + + # Notes about colors: + # \033]00m\] # for shell + # \[\033]01;31m\] for ps1 + } idm_ps1_disable () { - local id=${1} - PS1=$( sed "s/$id[^a-z]* //" <<<${PS1:-$SHELL_PS1} ) - PS1='[\u@\h \W]\$ ' - echo "export PS1='$PS1'" - echo "export SHELL_PS1='$PS1'" + echo "export PS1=\"\${IDM_SHELL_PS1}\"" + return } idm_ps1_kill () { idm_ps1_disable ${@-}; } diff --git a/shell/bash.sh b/shell/bash.sh index ca8fa26..35a4c1c 100644 --- a/shell/bash.sh +++ b/shell/bash.sh @@ -1,5 +1,6 @@ #!/bin/bash +export IDM_SHELL_PS1=${IDM_SHELL_PS1:-${PS1-}} IDM_SRC_WORDS=${IDM_SRC_WORDS-} IDM_BIN=${IDM_BIN:-idmgr}