Skip to content

Commit

Permalink
feat: add command "one <mod> info"
Browse files Browse the repository at this point in the history
  • Loading branch information
adoyle-h committed Feb 14, 2023
1 parent d998cb0 commit 175327c
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 0 deletions.
64 changes: 64 additions & 0 deletions bash/mod.bash
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,17 @@ get_weight() {
fi
}

get_enabled_link_to() {
local name=$1
local path
shopt -s nullglob
path=$(echo "$ENABLED_DIR/"*---"$name.$t.bash")
shopt -u nullglob
if [[ -n $path ]]; then
readlink "$path"
fi
}

enable_file() {
local name=$1
local filepath=$2
Expand Down Expand Up @@ -366,3 +377,56 @@ list_mods() {
}

# -----------------------------------------------------------------------------

metafor () {
local keyword=$1;
# Copy from composure.sh
sed -n "/$keyword / s/['\";]*\$//;s/^[ ]*\(: _\)*$keyword ['\"]*\([^([].*\)*\$/\2/p"
}

info_mod() {
local name=$1
local filepath

filepath=$(search_mod "$name")

local ABOUT URL SCRIPT ONE_LOAD_PRIORITY

local enabled link_to
link_to=$(get_enabled_link_to "$name")

if [[ -n $filepath ]]; then
if [[ -n $link_to ]]; then
echo "Enabled: true"
echo "Link to: $link_to"
else
echo "Enabled: false"
fi
ABOUT=$(metafor about-plugin <"$filepath")
ONE_LOAD_PRIORITY=$(get_weight "$filepath")
[[ -n ${ABOUT:-} ]] && echo "About: $ABOUT";
[[ -n ${ONE_LOAD_PRIORITY:-} ]] && echo "Priority: $ONE_LOAD_PRIORITY";
else
local opt_path
opt_path=$(search_mod "$name.opt")

if [[ -n $opt_path ]]; then
# shellcheck disable=1090
(source "$opt_path" && {
if [[ -n $link_to ]]; then
echo "Enabled: true"
echo "Link to: $link_to"
else
echo "Enabled: false"
fi
[[ -n ${ABOUT:-} ]] && echo "About: $ABOUT";
[[ -n ${ONE_LOAD_PRIORITY:-} ]] && echo "Priority: $ONE_LOAD_PRIORITY";
echo "Opt File: $opt_path"
[[ -n ${URL:-} ]] && echo "URL: $URL";
[[ -n ${SCRIPT:-} ]] && echo "Script: $SCRIPT";
})
else
echo "No found $t '$name'." >&2
fi
fi
}
2 changes: 2 additions & 0 deletions one-cmds/plugin
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,8 @@ case "$action" in

d|disable) if (( $# == 0 )); then usage; else disable_it "$@"; fi ;;

i|info) if (( $# == 0 )); then usage; else info_mod "$1"; fi ;;

w|which) if (( $# == 0 )); then usage; else search_mod "$1"; fi ;;

*)
Expand Down

0 comments on commit 175327c

Please sign in to comment.