penguin/utils

my env utils

commit 3574300184e23b27c4bf64c46bcbada03c54308e

author斟酌 鵬兄 <tgckpg@gmail.com>
date2022-08-11T12:46:58Z
subjectmoved gpg-agent into config
commit 3574300184e23b27c4bf64c46bcbada03c54308e
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2022-08-11T12:46:58Z

    moved gpg-agent into config
---
 bash/bashrc/package.sh           | 15 ------------
 bash/bashrc/rbashrc              | 51 +++++++++++++---------------------------
 bash/bashrc/sources/15_gpg-agent | 21 +++++++++++++++++
 3 files changed, 37 insertions(+), 50 deletions(-)

diff --git a/bash/bashrc/package.sh b/bash/bashrc/package.sh
index 1595e8f..f410059 100644
--- a/bash/bashrc/package.sh
+++ b/bash/bashrc/package.sh
@@ -23,18 +23,3 @@ function __func_help() {
 #   echo "Usage:" ${FUNCNAME[1]} $1
     echo "       ${FUNCNAME[1]} $1"
 }
-
-# Run through all sources
-SDIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"/sources
-
-if [ -d "$SDIR" ]; then
-    echo "Begin source:"
-    for i in $( find $SDIR -maxdepth 1 -type f -perm $PERM | sort )
-    do
-        echo "  Source:" $( basename $i )
-        . $i
-        if [[ $? -ne 0 ]]; then
-            echo "    .. failed"
-        fi
-    done
-fi
diff --git a/bash/bashrc/rbashrc b/bash/bashrc/rbashrc
index 1b04c73..132fd99 100644
--- a/bash/bashrc/rbashrc
+++ b/bash/bashrc/rbashrc
@@ -7,6 +7,7 @@ esac
 __SCRIPT=$BASH_SOURCE
 RBASH_HOME="$HOME/.rbash"
 RBASH_SOURCES="$RBASH_HOME/sources"
+RBASH_CONFIG="$RBASH_HOME/config"
 
 # Source global definitions
 if [ -f /etc/bashrc ]; then
@@ -72,26 +73,6 @@ if ! shopt -oq posix; then
   fi
 fi
 
-which gpg-agent 2>&1 > /dev/null
-if [ $? -eq 0 ]; then
-    GPG_ENV="$HOME/.gnupg/environment"
-
-    function __start_agent {
-        gpg-agent --daemon > "${GPG_ENV}"
-        chmod 600 "${GPG_ENV}"
-        . "${GPG_ENV}" > /dev/null
-    }
-
-    if [ -f "${GPG_ENV}" ]; then
-        . "${GPG_ENV}" > /dev/null
-
-        gpg-agent > /dev/null 2>&1
-        [ "$?" -ne 0 ] && { __start_agent; }
-    else
-        __start_agent;
-    fi
-fi
-
 function __download {
     which curl 2>&1 > /dev/null
     if [ $? -eq 0 ]; then
@@ -167,30 +148,30 @@ function rbash_run {
     "$f" "$@"
 }
 
-export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
-export EDITOR=vim
-
 # User specific aliases and functions
 function rbash_load {
     local f path
     echo "  $1"
-    path="sources/$1"
-    f=`rbash_cache "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/$path"`
+    f=`rbash_cache "https://git.k8s.astropenguin.net/penguin/utils/raw/branch/master/bash/bashrc/$1"`
     source "$f"
 }
 
+export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '
+export EDITOR=vim
+
 # Create default source config
-if [ ! -f "$RBASH_HOME/source.conf" ]; then
-    cat <<___DEFAULT___ > "$RBASH_HOME/source.conf"
+if [ ! -f "$RBASH_CONFIG" ]; then
+    cat <<___DEFAULT___ > "$RBASH_CONFIG"
 echo "Source:"
-rbash_load "package.sh" 1
-rbash_load "10_aliases"
-rbash_load "12_shortcuts"
-rbash_load "20_fast-greps"
-rbash_load "40_go-command"
-rbash_load "41_pivot-command"
+rbash_load "package.sh"
+rbash_load "sources/10_aliases"
+rbash_load "sources/12_shortcuts"
+rbash_load "sources/15_gpg-agent"
+rbash_load "sources/20_fast-greps"
+rbash_load "sources/40_go-command"
+rbash_load "sources/41_pivot-command"
 ___DEFAULT___
-    chmod 600 "$RBASH_HOME/source.conf"
+    chmod 600 "$RBASH_CONFIG"
 fi
 
-source "$RBASH_HOME/source.conf"
+source "$RBASH_CONFIG"
diff --git a/bash/bashrc/sources/15_gpg-agent b/bash/bashrc/sources/15_gpg-agent
new file mode 100644
index 0000000..56bef87
--- /dev/null
+++ b/bash/bashrc/sources/15_gpg-agent
@@ -0,0 +1,21 @@
+#!/bin/bash
+
+which gpg-agent 2>&1 > /dev/null
+if [ $? -eq 0 ]; then
+    GPG_ENV="$HOME/.gnupg/environment"
+
+    function __start_agent {
+        gpg-agent --daemon > "${GPG_ENV}"
+        chmod 600 "${GPG_ENV}"
+        . "${GPG_ENV}" > /dev/null
+    }
+
+    if [ -f "${GPG_ENV}" ]; then
+        . "${GPG_ENV}" > /dev/null
+
+        gpg-agent > /dev/null 2>&1
+        [ "$?" -ne 0 ] && { __start_agent; }
+    else
+        __start_agent;
+    fi
+fi