#!/bin/bash IDM_MOD_DEPS="id" ## Required functions ########################################## # Debug and shortcuts _git () { idm_git__bin ${@-}; } idm_git_f () { local id=$1 local cmd=$2 shift 2 local opts=${*-} trap '' INT TERM EXIT idm_validate id_config $id idm_vars_git_local $id set -e idm_git_${cmd#idm_git_} $opts rc=$? set -e if [ "$rc" -eq 0 ]; then idm_exit 0 "Returns $rc" else idm_exit $rc WARN "Called: 'idm_git_${cmd#idm_git_} ${opts:+$opts }'" fi } idm_git () { local action=$1 local id=$2 shift 2 local opts=${*-} idm_validate id_config $id idm_vars_git_local $id idm_git__bin $action $opts } idm_git_help () { echo "Git" printf " %-20s: %s\n" "git ls" "List maanged files" printf " " } idm_git_ls () { local id=$1 idm_validate id_config $id idm_vars_git_local $id _git ls-files | sed 's/^/ ~\//' | idm_log DUMP - } idm_git_enable () { local id=$1 idm_validate id_config $id idm_vars_git_local $id cat < /dev/null 2>&1 } idm_git__has_commits () { if idm_git__is_repo $id; then find "$git_dir" -type f &>/dev/null && return 0 fi return 1 } idm_git__is_all_commited () { [ "$( _git status -s | wc -l)" -eq 0 ] } ## Other internal functions ############################## idm_git__get_files_of_interest () { local id=${1} find_args="-maxdepth 2 -type f " { find $HOME/.ssh/ $find_args -name "${id}*" 2>/dev/null find $HOME/.ssh/known_hosts.d/ $find_args -name "${id}*" 2>/dev/null find $GNUPGHOME/private-keys-v1.d/ $find_args 2>/dev/null find $PASSWORD_STORE_DIR/ $find_args 2>/dev/null find $IDM_DIR_ID/ $find_args -name "$id*" 2>/dev/null } | sed -E "s@$HOME/?@@g" } ## User functions ############################## idm_git_init () { local id=$1 shift local opts=${@-} idm_validate id_config $id idm_vars_git_local $id if idm_git__is_repo ; then idm_log WARN "Do you want to override the esixting repo?" idm_cli_timeout 1 || idm_exit 1 "User cancelled" fi _git init $opts idm_log NOTICE "Repository has been created into '$git_dir'" # Generate _git config --add include.path "$git_config" idm_tomb__gen_git_config > $git_config } idm_tomb__gen_git_config () { ( cat <