Compare commits

..

No commits in common. "fa5e97fbe7ac66b8242cee23396cfd3d79c318d6" and "d5805041f5cc197cf7867fbb26acfdb67049d9a7" have entirely different histories.

8 changed files with 152 additions and 230 deletions

View File

@ -151,9 +151,7 @@ idm_core__shell ()
echo "export IDM_BIN=${IDM_BIN:-$IDM_DIR_ROOT/bin/idmgr}" echo "export IDM_BIN=${IDM_BIN:-$IDM_DIR_ROOT/bin/idmgr}"
echo "export IDM_DIR_ROOT='$IDM_DIR_ROOT'" echo "export IDM_DIR_ROOT='$IDM_DIR_ROOT'"
#echo "IDM_SRC_WORDS='$IDM_SRC_WORDS $(lib_id_get_all_id | xargs)'" echo "IDM_SRC_WORDS='$IDM_SRC_WORDS $(lib_id_get_all_id | xargs)'"
echo "IDM_SRC_WORDS='$IDM_SRC_WORDS'"
echo "IDM_DIR_ID='$IDM_DIR_ID'"
tail -n +2 $IDM_DIR_ROOT/shell/bash.sh tail -n +2 $IDM_DIR_ROOT/shell/bash.sh
} }
@ -240,7 +238,6 @@ idm_mod_order ()
IDM_MOD_DEPS="$( tr ' ' '\n' <<<${IDM_MOD_DEPS} )" IDM_MOD_DEPS="$( tr ' ' '\n' <<<${IDM_MOD_DEPS} )"
# Output # Output
# TOCHECK? echo -e "$( xargs -I{} echo {} "$mod_name" <<<"$IDM_MOD_DEPS" )"
echo -e "$( xargs -n1 -I{} echo {} "$mod_name" <<<"$IDM_MOD_DEPS" )" echo -e "$( xargs -n1 -I{} echo {} "$mod_name" <<<"$IDM_MOD_DEPS" )"
done | tsort | grep -v 'core' | xargs done | tsort | grep -v 'core' | xargs
#) #)
@ -520,8 +517,6 @@ idm_core_init ()
idm_lib_order_set gpg 11 89 11 idm_lib_order_set gpg 11 89 11
#idm_lib_order_set git 50 50 50 #idm_lib_order_set git 50 50 50
#idm_lib_order_set tomb 50 50 50 #idm_lib_order_set tomb 50 50 50
idm_lib_order_set gh 50 50 50
idm_lib_order_set gitea 50 50 50
# Load external lib # Load external lib
idm_lib_load lib idm_lib_load lib
@ -621,9 +616,6 @@ idm_core_cli ()
if [[ -f "$IDM_ID_ENV" ]]; then if [[ -f "$IDM_ID_ENV" ]]; then
. "$IDM_ID_ENV" . "$IDM_ID_ENV"
fi fi
if [[ -f "$IDM_DIR_ID/$id.secrets" ]]; then
. "$IDM_DIR_ID/$id.secrets"
fi
# Dispatch # Dispatch
#lib_log DEBUG "menu=$menu action=${action:-_} id=$id opt=$opt" #lib_log DEBUG "menu=$menu action=${action:-_} id=$id opt=$opt"

View File

@ -1,43 +0,0 @@
## Environment vars
* `IDM_DEBUG`:
* Type: Bool
* Desc: Set true for shell debugging
### Core Config
* `IDM_BIN`:
* Type: String/Path
* desc: Path of the idmgr executable script
* `IDM_DIR_ROOT`:
* Type: String/Path
* desc: Path of the idmgr code/library path
* `IDM_NO_BG`:
* Type: Bool
* Default: false
* Desc: Disable background service start
* Note: Will not start ssh-agent or other services ...
* `IDM_DISABLE_AUTO`:
* Default: ''
* Type: Words
* Desc: Disable some module components
* Example:
* `IDM_DISABLE_AUTO+=" git__enable git__disable git__kill "`
* `IDM_DISABLE_AUTO+="ps1__ls"`
### Id
* `IDM_LAST_ID_SAVE`:
* Type: Bool
* Default: true
* desc: Should the last loaded ID saved
* `IDM_LAST_ID_AUTOLOAD`:
* Type: Bool
* Default: true
* desc: Should the last saved ID should be enabled at shell startup

View File

@ -200,7 +200,6 @@ lib_id_get_all_config ()
lib_id_get_all_id () lib_id_get_all_id ()
{ {
local id=
for id in $( find $IDM_DIR_ID -type f -name '*.env' 2>/dev/null ); do for id in $( find $IDM_DIR_ID -type f -name '*.env' 2>/dev/null ); do
id=${id%%\.env} id=${id%%\.env}
echo "${id##*/}" echo "${id##*/}"

View File

@ -1,55 +0,0 @@
#!/bin/bash
#IDM_MOD_PS1_DEPS="s4 id pass gpg ssh"
#IDM_DISABLE_AUTO+="gh__ls"
## Prompt functions
##########################################
#SHELL_PS1="${SHELL_PS1:-${PS1}"
idm_gh ()
{
local action=${1-}
shift || true
idm_gh__ls
}
idm_gh__ls ()
{
local id=${1}
if [[ -n "${GH_TOKEN-}" ]] ; then
echo " enabled (repo: ${GH_REPO})"
else
echo " disabled"
fi
}
idm_gh__help ()
{
echo "Github CLI"
printf " %-20s: %s\n" "gh enable" "Enable gh token"
printf " %-20s: %s\n" "gh disable" "Disable gh token"
}
idm_gh__enable ()
{
if [[ -n "${gh_token-}" ]] ; then
echo "export GH_TOKEN=\"$gh_token\""
echo "export GH_REPO=\"$gh_repo\""
fi
}
idm_gh__disable ()
{
echo "unset GH_TOKEN"
echo "unset GH_REPO"
}
idm_gh__kill () { idm_gh__disable ${@-}; }

View File

@ -1,78 +0,0 @@
#!/bin/bash
#IDM_MOD_PS1_DEPS="s4 id pass gpg ssh"
#IDM_DISABLE_AUTO+="gitea__ls"
## Prompt functions
##########################################
#SHELL_PS1="${SHELL_PS1:-${PS1}"
idm_gitea ()
{
local action=${1-}
shift || true
idm_gitea__ls
}
idm_gitea__ls ()
{
local id=${1}
if [[ -n "${GITEA_LOGIN-}" ]] ; then
echo " enabled (repo: ${GITEA_LOGIN} ${GITEA_URL})"
else
echo " disabled"
fi
}
idm_gitea__help ()
{
echo "Github CLI"
printf " %-20s: %s\n" "gitea enable" "Enable gitea token"
printf " %-20s: %s\n" "gitea disable" "Disable gitea token"
}
idm_gitea__register ()
{
local gitea_url=$1
local gitea_login=$2
local gitea_token=$3
if tea login list -o simple | grep -q "^$gitea_login"; then
:
else
tea login add \
--url "$gitea_url" \
--name "$gitea_login" \
--token "$gitea_token" > /dev/null
>&2 echo "Tea login installed: $gitea_login ($gitea_url)"
fi
}
idm_gitea__enable ()
{
[[ -n "${gitea_url-}" ]] || return 0
[[ -n "${gitea_login-}" ]] || return 0
[[ -n "${gitea_token-}" ]] || return 0
idm_gitea__register $gitea_url $gitea_login $gitea_token
echo "export GITEA_SERVER_URL=\"$gitea_token\""
echo "export GITEA_LOGIN=\"$gitea_login\""
}
idm_gitea__disable ()
{
echo "unset GITEA_SERVER_URL"
echo "unset GITEA_LOGIN"
}
idm_gitea__kill () { idm_gitea__disable ${@-}; }

View File

@ -80,7 +80,6 @@ idm_gpg__enable ()
local id=${1} local id=${1}
lib_id_has_config $id lib_id_has_config $id
idm_gpg_header $id
# Source environment # Source environment
if [ -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env" ]; then if [ -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env" ]; then
@ -89,20 +88,15 @@ idm_gpg__enable ()
unset GPG_AGENT_INFO unset GPG_AGENT_INFO
fi fi
if [[ "${IDM_NO_BG:-false}" == true ]] || [[ -n "${DIRENV_IN_ENVRC-}" ]] ; then # Check if socket is present
lib_log WARN "Start of gpg-agent background process disabled because of: IDM_NO_BG=${IDM_NO_BG-} or DIRENV_IN_ENVRC=${DIRENV_IN_ENVRC-}" if [ ! -S "${GPG_AGENT_INFO-}" ]; then
else rm -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env"
idm_gpg_start $id
fi
# Check if socket is present # Show config to source
if [ ! -S "${GPG_AGENT_INFO-}" ]; then if [ -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env" ]; then
rm -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env" cat "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env"
idm_gpg_start $id
fi
# Show config to source
if [ -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env" ]; then
cat "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env"
fi
fi fi
# Export tty to the current shell # Export tty to the current shell

View File

@ -326,7 +326,7 @@ background() {
idm_ssh__agent_start() { idm_ssh__agent_start() {
# local socket=$1 # local socket=$1
local id=$1 local id=$1
local life=4w local life=5d
local socket_dir="${XDG_RUNTIME_DIR}/ssh-agent/${id}" local socket_dir="${XDG_RUNTIME_DIR}/ssh-agent/${id}"
local socket="${socket_dir}/socket" local socket="${socket_dir}/socket"

View File

@ -6,29 +6,20 @@ IDM_BIN=${IDM_BIN:-idmgr}
i () i ()
{ {
local IDM_SRC_IDS=$($IDM_BIN id names)
local result=
local idents=$()
local id=
for id in $( find $IDM_DIR_ID -type f -name '*.env' 2>/dev/null ); do
id=${id##*/}
idents="${idents:+$idents }${id%%\.env}"
done
local patterns=" ${IDM_SRC_WORDS} ${IDM_SRC_IDS} $idents" if grep -q " ${1:-NONE} " <<<" ${IDM_SRC_WORDS} "; then
if grep -q " ${1:-NONE} " <<<" $patterns "; then
result="$( $IDM_BIN $@)" result="$( $IDM_BIN $@)"
# Debug module # Debug module
if [ "${IDM_DEBUG-}" == "true" ]; then if [ "${ID_DEBUG-}" == "true" ]; then
>&2 echo "DEBUG: Source: $IDM_BIN $@" echo "DEBUG: Command: $IDM_BIN $@"
if [ "${result:-NONE}" == "NONE" ]; then if [ "${result:-NONE}" == "NONE" ]; then
>&2 echo "DEBUG: ======= ${result:-NONE}" echo "DEBUG: ======= ${result:-NONE}"
else else
>&2 echo "DEBUG: ======= Shell has sourced =======" echo "DEBUG: ======= Shell has sourced ======="
echo "${result:-NONE}" echo "${result:-NONE}"
>&2 echo "DEBUG: =======" echo "DEBUG: ======="
fi fi
fi fi
@ -36,10 +27,6 @@ i ()
eval "$result" eval "$result"
else else
if [ "${IDM_DEBUG-}" == "true" ]; then
>&2 echo "DEBUG: Command: $IDM_BIN $@"
>&2 echo "DEBUG: ======="
fi
$IDM_BIN $@ $IDM_BIN $@
fi fi
@ -48,16 +35,6 @@ i ()
i_restore_last_id () i_restore_last_id ()
{ {
[[ "$IDM_LAST_ID_AUTOLOAD" == 'true' ]] || return 0
# Restore from SHELL_ID
if [[ -n "${SHELL_ID:-}" ]]; then
i enable $SHELL_ID
return
fi
# Restore from last loaded shell
local IDM_DIR_CACHE=${IDM_DIR_CACHE:-${XDG_CACHE_HOME:-~/.cache}/idmgr} local IDM_DIR_CACHE=${IDM_DIR_CACHE:-${XDG_CACHE_HOME:-~/.cache}/idmgr}
local state_file=$IDM_DIR_CACHE/last_id local state_file=$IDM_DIR_CACHE/last_id
if [ -f "$state_file" ]; then if [ -f "$state_file" ]; then
@ -68,6 +45,7 @@ i_restore_last_id ()
i enable $id i enable $id
fi fi
fi fi
} }
@ -76,3 +54,138 @@ bind -x '"\C-b": i disable'
i_restore_last_id i_restore_last_id
# completion file for bash
# Copyright (C) 2012 - 2014 Jason A. Donenfeld <Jason@zx2c4.com> and
# Brian Mattern <rephorm@rephorm.com>. All Rights Reserved.
# This file is licensed under the GPLv2+. Please see COPYING for more information.
_pass_complete_entries () {
prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store/}"
prefix="${prefix%/}/"
suffix=".gpg"
autoexpand=${1:-0}
local IFS=$'\n'
local items=($(compgen -f $prefix$cur))
# Remember the value of the first item, to see if it is a directory. If
# it is a directory, then don't add a space to the completion
local firstitem=""
# Use counter, can't use ${#items[@]} as we skip hidden directories
local i=0
for item in ${items[@]}; do
[[ $item =~ /\.[^/]*$ ]] && continue
# if there is a unique match, and it is a directory with one entry
# autocomplete the subentry as well (recursively)
if [[ ${#items[@]} -eq 1 && $autoexpand -eq 1 ]]; then
while [[ -d $item ]]; do
local subitems=($(compgen -f "$item/"))
local filtereditems=( )
for item2 in "${subitems[@]}"; do
[[ $item2 =~ /\.[^/]*$ ]] && continue
filtereditems+=( "$item2" )
done
if [[ ${#filtereditems[@]} -eq 1 ]]; then
item="${filtereditems[0]}"
else
break
fi
done
fi
# append / to directories
[[ -d $item ]] && item="$item/"
item="${item%$suffix}"
COMPREPLY+=("${item#$prefix}")
if [[ $i -eq 0 ]]; then
firstitem=$item
fi
let i+=1
done
# The only time we want to add a space to the end is if there is only
# one match, and it is not a directory
if [[ $i -gt 1 || ( $i -eq 1 && -d $firstitem ) ]]; then
compopt -o nospace
fi
}
_pass_complete_folders () {
prefix="${PASSWORD_STORE_DIR:-$HOME/.password-store/}"
prefix="${prefix%/}/"
local IFS=$'\n'
local items=($(compgen -d $prefix$cur))
for item in ${items[@]}; do
[[ $item == $prefix.* ]] && continue
COMPREPLY+=("${item#$prefix}/")
done
}
_pass_complete_keys () {
local IFS=$'\n'
# Extract names and email addresses from gpg --list-keys
local keys="$(gpg2 --list-secret-keys --with-colons | cut -d : -f 10 | sort -u | sed '/^$/d')"
COMPREPLY+=($(compgen -W "${keys}" -- ${cur}))
}
_pass()
{
COMPREPLY=()
local cur="${COMP_WORDS[COMP_CWORD]}"
local commands="init ls find grep show insert generate edit rm mv cp git help version"
if [[ $COMP_CWORD -gt 1 ]]; then
local lastarg="${COMP_WORDS[$COMP_CWORD-1]}"
case "${COMP_WORDS[1]}" in
init)
if [[ $lastarg == "-p" || $lastarg == "--path" ]]; then
_pass_complete_folders
compopt -o nospace
else
COMPREPLY+=($(compgen -W "-p --path" -- ${cur}))
_pass_complete_keys
fi
;;
ls|list|edit)
_pass_complete_entries
;;
show|-*)
COMPREPLY+=($(compgen -W "-c --clip" -- ${cur}))
_pass_complete_entries 1
;;
insert)
COMPREPLY+=($(compgen -W "-e --echo -m --multiline -f --force" -- ${cur}))
_pass_complete_entries
;;
generate)
COMPREPLY+=($(compgen -W "-n --no-symbols -c --clip -f --force -i --in-place" -- ${cur}))
_pass_complete_entries
;;
cp|copy|mv|rename)
COMPREPLY+=($(compgen -W "-f --force" -- ${cur}))
_pass_complete_entries
;;
rm|remove|delete)
COMPREPLY+=($(compgen -W "-r --recursive -f --force" -- ${cur}))
_pass_complete_entries
;;
git)
COMPREPLY+=($(compgen -W "init push pull config log reflog rebase" -- ${cur}))
;;
esac
else
COMPREPLY+=($(compgen -W "${commands}" -- ${cur}))
_pass_complete_entries 1
fi
}
complete -o filenames -F _pass pass
# Show current identities
echo "INFO: idmgr has been loaded, use 'idmgr' or 'i' to call it"
#$IDM_BIN id ls