Dev: Many little improvement, output reduxx

DONE:
- Reduce wasted output blank lines
- Simplifie ls output on all modules
- Remove sterr output on ls
- Clean function syntax (for hier output)
- Fix a bug on missing pid for ssh-agent
- Remove portion of debug traces (mod_ssh)
This commit is contained in:
mrjk 2018-02-27 21:57:59 -05:00
parent 30f457a9a0
commit 131e5c8db1
6 changed files with 100 additions and 67 deletions

View File

@ -99,7 +99,7 @@ idm_core__ls ()
local id=${1}
#set -x
idm_core_exec_mod $id __ls "\n%s ls" ${IDM_MOD_ORDER//:/ }
idm_core_exec_mod $id __ls "%s ls" ${IDM_MOD_ORDER//:/ }
}
@ -243,14 +243,26 @@ idm_core_exec_mod ()
#set +x
#lib_log INFO "Loading module $i ..."
[ "$sep" == "_" ] || lib_log NOTICE "$(printf "$sep" $i )"
#${val} $id || \
# {
# # DO NOT DISABLE THIS BLOCK, that force plugin to load in anyway
# true
# lib_log WARN "Module $i failed in some way ... ($action)"
# }
export IDM_MOD_EXEC=chain
${val} $id || \
{
# DO NOT DISABLE THIS BLOCK, that force plugin to load in anyway
true
local rc=0
out="$( ${val} $id || rc=$? )"
if [ "$rc" -eq 0 -a ! -z "$out" ]; then
[ "$sep" == "_" ] ||
lib_log NOTICE "$(printf "$sep" $i )"
echo -e "$out\n"
elif [ "$rc" -ne 0 ]; then
lib_log WARN "Module $i failed in some way ... ($action)"
}
echo -e "$out\n"
fi
else
echo ""
lib_log INFO "Skip module $i"

View File

@ -22,11 +22,11 @@ idm_cloud__ls ()
if lib_id_is_enabled $id; then
if [ -f "${OS_CLOUD-}" ]; then
echo " enabled ($OS_CLOUD)"
else
echo " disabled (config is absent ${OS_CLOUD:-${OS_CLOUD:+$OS_CLOUD}})"
#else
# echo " disabled (config is absent ${OS_CLOUD:-${OS_CLOUD:+$OS_CLOUD}})"
fi
else
echo " disabled"
#else
# echo " disabled"
fi
}

View File

@ -66,7 +66,10 @@ idm_gpg__ls ()
local id=${1}
lib_id_is_enabled $id || return 0
gpg --list-keys | sed 's/^/ /' #| lib_log DUMP -
{
gpg --list-keys 2>/dev/null \
|| true
} | sed 's/^/ /' #| lib_log DUMP -
}
idm_gpg__new ()

View File

@ -33,7 +33,10 @@ idm_pass__ls ()
local id=${1}
lib_id_is_enabled $id || return 0
PASSWORD_STORE_DIR=~/.config/pass/${id} pass ls | sed 's/^/ /'
{
PASSWORD_STORE_DIR=~/.config/pass/${id} \
pass ls || true
} 2>/dev/null | sed 's/^/ /'
}
idm_pass__help ()

View File

@ -58,7 +58,7 @@ idm_ssh__ls ()
lib_id_is_enabled $id || return 0
{ ssh-add $opt || true ; } | sed 's/^/ /'
{ ssh-add $opt || true ; } 2>/dev/null | sed 's/^/ /'
}
idm_ssh__disable ()
@ -97,7 +97,8 @@ idm_ssh__enable ()
}
# LOGOUT
idm_ssh__kill () {
idm_ssh__kill ()
{
#set -x
@ -178,26 +179,27 @@ idm_ssh__agent_start() {
}
idm_ssh__agent_clean () {
idm_ssh__agent_clean ()
{
local id=$1
local socket=$2
local pid=${3:-0}
# We should kill all agents ....
if [ "${pid}" == '0' ]; then
set +x
#set +x
pid=$(grep -a "$socket" /proc/*/cmdline \
| grep -a -v 'thread-self' \
| strings -s' ' -1 \
| sed -E 's@ /proc/@ \n/proc/@g'
)
set -x
#set -x
pid="$( sed -E 's@/proc/([0-9]*)/.*@\1@' <<<"$pid" )"
fi
set -x
#set -x
# Remove process
if [ "$pid" != '0' ]; then
if [ "$pid" != '0' -a "$pid" -gt 0 ]; then
kill $pid
fi

View File

@ -70,15 +70,23 @@ idm_tomb__ls ()
{
local id=$1
# Show files if there are some
if [ -d "$IDM_CONFIG_DIR/enc/" ]; then
echo " Tombs:"
find $IDM_CONFIG_DIR/enc/ -type f -name "*.tomb" | sed "s@$HOME@ ~@"
fi
# Leave if not enabled
lib_id_is_enabled $id &&
return 0
if lib_id_is_enabled $id; then
# Status vars
local tomb_status=
local tomb_date=
local tomb_show=0
local git_status=
local git_date=
local git_show=0
# Load local vars
idm_tomb_header $id
@ -88,6 +96,7 @@ idm_tomb__ls ()
tomb_status=present
tomb_date=$( lib_date_diff_human $(find $git_tomb_enc -printf "%Ts") )
tomb_date=", $tomb_date old"
tomb_show=1
else
tomb_status=absent
fi
@ -98,9 +107,12 @@ idm_tomb__ls ()
#git_date=$( lib_date_diff_human $(find $git_tomb_dir -maxdepth 0 -printf "%Ts") )
#git_date=" $git_date"
else
git_status=closed
git_status="absent (closed)"
fi
# Leave if nothing to show
[ $(( $git_show + $tomb_show )) -eq 0 ] && return
# Display
echo " Status:"
printf " %-20s: %s\n" "encrypted tomb" "$tomb_status${tomb_date}"
@ -108,15 +120,16 @@ idm_tomb__ls ()
printf " %-20s: %s\n" "tomb git status" "$git_status${git_date}"
printf " %-20s: %s\n" "tomb git dir" "$git_tomb_dir"
# Check if local repo is enabled
lib_git_is_repo id &>/dev/null ||
return 0
# Show git remotes
if lib_git_is_repo id &>/dev/null ; then
echo " Git remotes:"
lib_git id remote -v | sed 's/^/ /'
echo " Last commits:"
lib_git id l --color=always | sed 's/^/ /'
echo
fi
fi
}