From 811d40cb1e32040438a5bcd88ab1bb7c76ea0331 Mon Sep 17 00:00:00 2001 From: edwark43 <97860398+edwark43@users.noreply.github.com> Date: Fri, 22 Mar 2024 07:25:12 -0400 Subject: [PATCH] Update colorscript --- misc/bin/colorscript | 75 ++------------------------------------------ 1 file changed, 3 insertions(+), 72 deletions(-) diff --git a/misc/bin/colorscript b/misc/bin/colorscript index ea255f4..5da11b4 100755 --- a/misc/bin/colorscript +++ b/misc/bin/colorscript @@ -1,24 +1,6 @@ #!/usr/bin/env bash # Simple CLI for shell-color-scripts - -if [[ "$DEV" -gt 0 ]]; then - DIR_COLORSCRIPTS="./colorscripts" -else - DIR_COLORSCRIPTS="$HOME/.local/share/asciiart" -fi - -if command -v find &>/dev/null; then - LS_CMD="$(command -v find) ${DIR_COLORSCRIPTS} -maxdepth 1 -type f" - LS_CMD_B="$(command -v find) ${DIR_COLORSCRIPTS}/blacklisted -maxdepth 1 -type f" -else - LS_CMD="$(command -v ls) ${DIR_COLORSCRIPTS}" - LS_CMD_B="$(command -v ls) ${DIR_COLORSCRIPTS}/blacklisted" -fi - -list_colorscripts="$($LS_CMD | xargs -I $ basename $ | cut -d ' ' -f 1 | nl)" -length_colorscripts="$($LS_CMD | wc -l)" -list_blacklist="$($LS_CMD_B 2>/dev/null | xargs -I $ basename $ | cut -d ' ' -f 1 | nl || "")" -length_blacklist="$($LS_CMD_B 2>/dev/null | wc -l || 0)" +DIR_COLORSCRIPTS="$HOME/.local/share/asciiart" fmt_help=" %-20s\t%-54s\n" function _help() { @@ -27,22 +9,8 @@ function _help() { echo "Usage: colorscript [OPTION] [SCRIPT NAME/INDEX]" printf "${fmt_help}" \ "-h, --help, help" "Print this help." \ - "-l, --list, list" "List all installed color scripts." \ "-r, --random, random" "Run a random color script." \ "-e, --exec, exec" "Run a specified color script by SCRIPT NAME or INDEX."\ - "-b, --blacklist, blacklist" "Blacklist a color script by SCRIPT NAME or INDEX." \ - "-u, --unblacklist, unblacklist" "Unblacklist a color script by SCRIPT NAME or INDEX." \ - "-a, --all, all" "List the outputs of all colorscripts with their SCRIPT NAME" -} - -function _list() { - echo "There are "$($LS_CMD | wc -l)" installed color scripts:" - echo "${list_colorscripts}" -} - -function _list_blacklist() { - echo "There are $length_blacklist blacklisted color scripts:" - echo "${list_blacklist}" } function _random() { @@ -71,7 +39,7 @@ function _run_by_name() { } function _run_by_index() { - if [[ "$1" -gt 0 && "$1" -le "${length_colorscripts}" ]]; then + if [[ "$1" -gt 0 && "$1" -lt "${length_colorscripts}" ]]; then colorscript="$(echo "${list_colorscripts}" | sed -n ${1}p \ | tr -d ' ' | tr '\t' ' ' | cut -d ' ' -f 2)" @@ -90,30 +58,6 @@ function _run_colorscript() { fi } -function _run_all() { - for s in $DIR_COLORSCRIPTS/* - do - echo "$(echo $s | awk -F '/' '{print $NF}'):" - echo "$($s)" - echo - done -} - -function _blacklist_colorscript() { # by name only - if [ ! -d "${DIR_COLORSCRIPTS}/blacklisted" ]; then - sudo mkdir "${DIR_COLORSCRIPTS}/blacklisted" - fi - sudo mv "${DIR_COLORSCRIPTS}/$1" "${DIR_COLORSCRIPTS}/blacklisted" -} - -function _unblacklist_colorscript() { # by name only - if [ -f "${DIR_COLORSCRIPTS}/blacklisted/$1" ]; then - sudo mv "${DIR_COLORSCRIPTS}/blacklisted/$1" "${DIR_COLORSCRIPTS}" - else - echo "Input error. Script $1 is not blacklisted!" - fi -} - case "$#" in 0) _help @@ -123,18 +67,9 @@ case "$#" in -h | --help | help) _help ;; - -l | --list | list) - _list - ;; - -b | --blacklist | blacklist) - _list_blacklist - ;; -r | --random | random) _random ;; - -a | --all | all) - _run_all - ;; *) echo "Input error." exit 1 @@ -144,10 +79,6 @@ case "$#" in 2) if [[ "$1" == "-e" || "$1" == "--exec" || "$1" == "exec" ]]; then _run_colorscript "$2" - elif [[ "$1" == "-b" || "$1" == "--blacklist" || "$1" == "blacklist" ]]; then - _blacklist_colorscript "$2" - elif [[ "$1" == "-u" || "$1" == "--unblacklist" || "$1" == "unblacklist" ]]; then - _unblacklist_colorscript "$2" else echo "Input error." exit 1 @@ -157,4 +88,4 @@ case "$#" in echo "Input error, too many arguments." exit 1 ;; -esac \ No newline at end of file +esac