penguin/utils

my env utils

commit 0a52f2201f46175b599f1e827aaa0dbd3f20fed1

author斟酌 鵬兄 <tgckpg@gmail.com>
date2022-08-11T13:31:05Z
subjectShow enabled sources
commit 0a52f2201f46175b599f1e827aaa0dbd3f20fed1
Author: 斟酌 鵬兄 <tgckpg@gmail.com>
Date:   2022-08-11T13:31:05Z

    Show enabled sources
---
 bash/bashrc/rbashrc | 28 +++++++++++++++++++++-------
 1 file changed, 21 insertions(+), 7 deletions(-)

diff --git a/bash/bashrc/rbashrc b/bash/bashrc/rbashrc
index 89763d0..10c0bca 100644
--- a/bash/bashrc/rbashrc
+++ b/bash/bashrc/rbashrc
@@ -1,3 +1,5 @@
+#!/bin/bash
+
 # If not running interactively, don't do anything
 case $- in
     *i*) ;;
@@ -90,10 +92,6 @@ function __download {
     fi
 }
 
-function _indent {
-    xargs -n1 printf '    %s\n'
-}
-
 function rbash_cache {
     local CACHE_FILE
     MLINK=$( echo "$1" | md5sum | cut -d' ' -f1 )
@@ -111,7 +109,7 @@ function rbash_cache {
 # User specific aliases and functions
 function rbash_load {
     local f path
-    echo "$1" | _indent
+    echo "    $1"
     f=`rbash_cache "$RBASH_REMOTE/$RBASH_REPO/raw/branch/master/$RBASH_PATH/$1"`
     source "$f"
 }
@@ -163,14 +161,30 @@ function rbash-run {
     "$f" "$@"
 }
 
-function rbash-list {
+function _require_jq {
     which jq 2>&1 > /dev/null
     if [ $? -ne 0 ]; then
         echo This command requires jq.
         return 1
     fi
+}
+
+function rbash-list {
+    _require_jq || return 1
     echo "Available sources:"
-    __download "$RBASH_REMOTE/api/v1/repos/$RBASH_REPO/contents/$RBASH_PATH/sources/" | jq -r '.[].name' | _indent
+    for i in `__download "$RBASH_REMOTE/api/v1/repos/$RBASH_REPO/contents/$RBASH_PATH/sources/" | jq -r '.[].name'`; do
+        grep -q -e "^rbash_load \"sources/$i\"\$" "$RBASH_CONFIG"
+        if [ $? -eq 0 ]; then
+            echo "  * $i"
+        else
+            echo "    $i"
+        fi
+    done
+}
+
+function rbash-enable {
+    _require_jq || return 1
+
 }
 
 export PS1='This is <MACHINE_NAME>\e[1;3<COLOR_CODE>m<MACHINE_COLORED_NAME>\e[0m: \w\n\$ '