Compare commits
No commits in common. "fa5e97fbe7ac66b8242cee23396cfd3d79c318d6" and "d5805041f5cc197cf7867fbb26acfdb67049d9a7" have entirely different histories.
fa5e97fbe7
...
d5805041f5
10
bin/idmgr
10
bin/idmgr
@ -151,9 +151,7 @@ idm_core__shell ()
|
||||
|
||||
echo "export IDM_BIN=${IDM_BIN:-$IDM_DIR_ROOT/bin/idmgr}"
|
||||
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'"
|
||||
echo "IDM_DIR_ID='$IDM_DIR_ID'"
|
||||
echo "IDM_SRC_WORDS='$IDM_SRC_WORDS $(lib_id_get_all_id | xargs)'"
|
||||
|
||||
tail -n +2 $IDM_DIR_ROOT/shell/bash.sh
|
||||
}
|
||||
@ -240,7 +238,6 @@ idm_mod_order ()
|
||||
IDM_MOD_DEPS="$( tr ' ' '\n' <<<${IDM_MOD_DEPS} )"
|
||||
|
||||
# Output
|
||||
# TOCHECK? echo -e "$( xargs -I{} echo {} "$mod_name" <<<"$IDM_MOD_DEPS" )"
|
||||
echo -e "$( xargs -n1 -I{} echo {} "$mod_name" <<<"$IDM_MOD_DEPS" )"
|
||||
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 git 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
|
||||
idm_lib_load lib
|
||||
@ -621,9 +616,6 @@ idm_core_cli ()
|
||||
if [[ -f "$IDM_ID_ENV" ]]; then
|
||||
. "$IDM_ID_ENV"
|
||||
fi
|
||||
if [[ -f "$IDM_DIR_ID/$id.secrets" ]]; then
|
||||
. "$IDM_DIR_ID/$id.secrets"
|
||||
fi
|
||||
|
||||
# Dispatch
|
||||
#lib_log DEBUG "menu=$menu action=${action:-_} id=$id opt=$opt"
|
||||
|
||||
@ -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
|
||||
@ -200,7 +200,6 @@ lib_id_get_all_config ()
|
||||
|
||||
lib_id_get_all_id ()
|
||||
{
|
||||
local id=
|
||||
for id in $( find $IDM_DIR_ID -type f -name '*.env' 2>/dev/null ); do
|
||||
id=${id%%\.env}
|
||||
echo "${id##*/}"
|
||||
|
||||
@ -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 ${@-}; }
|
||||
@ -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 ${@-}; }
|
||||
@ -80,7 +80,6 @@ idm_gpg__enable ()
|
||||
|
||||
local id=${1}
|
||||
lib_id_has_config $id
|
||||
idm_gpg_header $id
|
||||
|
||||
# Source environment
|
||||
if [ -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env" ]; then
|
||||
@ -89,20 +88,15 @@ idm_gpg__enable ()
|
||||
unset GPG_AGENT_INFO
|
||||
fi
|
||||
|
||||
if [[ "${IDM_NO_BG:-false}" == true ]] || [[ -n "${DIRENV_IN_ENVRC-}" ]] ; then
|
||||
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-}"
|
||||
else
|
||||
# Check if socket is present
|
||||
if [ ! -S "${GPG_AGENT_INFO-}" ]; then
|
||||
rm -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env"
|
||||
idm_gpg_start $id
|
||||
fi
|
||||
|
||||
# Check if socket is present
|
||||
if [ ! -S "${GPG_AGENT_INFO-}" ]; then
|
||||
rm -f "${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
|
||||
# Show config to source
|
||||
if [ -f "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env" ]; then
|
||||
cat "${XDG_RUNTIME_DIR}/pgp-agent/${id}/env"
|
||||
fi
|
||||
|
||||
# Export tty to the current shell
|
||||
|
||||
@ -326,7 +326,7 @@ background() {
|
||||
idm_ssh__agent_start() {
|
||||
# local socket=$1
|
||||
local id=$1
|
||||
local life=4w
|
||||
local life=5d
|
||||
|
||||
local socket_dir="${XDG_RUNTIME_DIR}/ssh-agent/${id}"
|
||||
local socket="${socket_dir}/socket"
|
||||
|
||||
171
shell/bash.sh
171
shell/bash.sh
@ -6,29 +6,20 @@ IDM_BIN=${IDM_BIN:-idmgr}
|
||||
|
||||
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} " <<<" $patterns "; then
|
||||
if grep -q " ${1:-NONE} " <<<" ${IDM_SRC_WORDS} "; then
|
||||
|
||||
result="$( $IDM_BIN $@)"
|
||||
|
||||
# Debug module
|
||||
if [ "${IDM_DEBUG-}" == "true" ]; then
|
||||
>&2 echo "DEBUG: Source: $IDM_BIN $@"
|
||||
if [ "${ID_DEBUG-}" == "true" ]; then
|
||||
echo "DEBUG: Command: $IDM_BIN $@"
|
||||
if [ "${result:-NONE}" == "NONE" ]; then
|
||||
>&2 echo "DEBUG: ======= ${result:-NONE}"
|
||||
echo "DEBUG: ======= ${result:-NONE}"
|
||||
else
|
||||
>&2 echo "DEBUG: ======= Shell has sourced ======="
|
||||
echo "DEBUG: ======= Shell has sourced ======="
|
||||
echo "${result:-NONE}"
|
||||
>&2 echo "DEBUG: ======="
|
||||
echo "DEBUG: ======="
|
||||
fi
|
||||
fi
|
||||
|
||||
@ -36,10 +27,6 @@ i ()
|
||||
eval "$result"
|
||||
|
||||
else
|
||||
if [ "${IDM_DEBUG-}" == "true" ]; then
|
||||
>&2 echo "DEBUG: Command: $IDM_BIN $@"
|
||||
>&2 echo "DEBUG: ======="
|
||||
fi
|
||||
$IDM_BIN $@
|
||||
fi
|
||||
|
||||
@ -48,16 +35,6 @@ i ()
|
||||
|
||||
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 state_file=$IDM_DIR_CACHE/last_id
|
||||
if [ -f "$state_file" ]; then
|
||||
@ -68,6 +45,7 @@ i_restore_last_id ()
|
||||
i enable $id
|
||||
fi
|
||||
fi
|
||||
|
||||
}
|
||||
|
||||
|
||||
@ -76,3 +54,138 @@ bind -x '"\C-b": i disable'
|
||||
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
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user