diff options
| author | Derek Taylor <derek@distrotube.com> | 2022-01-20 23:31:34 +0000 |
|---|---|---|
| committer | Derek Taylor <derek@distrotube.com> | 2022-01-20 23:31:34 +0000 |
| commit | 2cf1cd67563ea9cbc7954193e44da3e9eb948242 (patch) | |
| tree | 42d620dd56190ab55b9b339f50a774450cd58546 | |
| parent | Merge branch 'atcasanova-master-patch-32131' into 'master' (diff) | |
| parent | Aadded option to blacklist a colorscript (diff) | |
Merge branch 'master' into 'master'
Aadded option to blacklist a colorscript
See merge request dwt1/shell-color-scripts!15
| -rwxr-xr-x | colorscript.sh | 24 | ||||
| -rw-r--r-- | zsh_completion/_colorscript | 14 |
2 files changed, 33 insertions, 5 deletions
diff --git a/colorscript.sh b/colorscript.sh index 5623196..3d30375 100755 --- a/colorscript.sh +++ b/colorscript.sh @@ -3,10 +3,16 @@ # Simple CLI for shell-color-scripts DIR_COLORSCRIPTS="/opt/shell-color-scripts/colorscripts" -LS_CMD="$(command -v ls)" +if command -v find &>/dev/null; then + LS_CMD="$(command -v find) ${DIR_COLORSCRIPTS} -maxdepth 1 -type f" +else + LS_CMD="$(command -v ls) ${DIR_COLORSCRIPTS}" +fi + +list_colorscripts="$($LS_CMD | xargs -I $ basename $ | cut -d ' ' -f 1 | nl)" +length_colorscripts="$($LS_CMD | wc -l)" + fmt_help=" %-20s\t%-54s\n" -list_colorscripts="$($LS_CMD "${DIR_COLORSCRIPTS}" | cut -d ' ' -f 1 | nl)" -length_colorscripts="$($LS_CMD "${DIR_COLORSCRIPTS}" | wc -l)" function _help() { echo "Description: A collection of terminal color scripts." echo "" @@ -16,11 +22,12 @@ function _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." \ "-a, --all, all" "List the outputs of all colorscripts with their SCRIPT NAME" } function _list() { - echo "There are "$($LS_CMD "${DIR_COLORSCRIPTS}" | wc -l)" installed color scripts:" + echo "There are "$($LS_CMD | wc -l)" installed color scripts:" echo "${list_colorscripts}" } @@ -78,6 +85,13 @@ function _run_all() { 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" +} + case "$#" in 0) _help @@ -105,6 +119,8 @@ 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" else echo "Input error." exit 1 diff --git a/zsh_completion/_colorscript b/zsh_completion/_colorscript index d558f60..0912461 100644 --- a/zsh_completion/_colorscript +++ b/zsh_completion/_colorscript @@ -1,6 +1,11 @@ #compdef colorscript DIR_COLORSCRIPTS="/opt/shell-color-scripts/colorscripts" +if command -v find &>/dev/null; then + LS_CMD="$(command -v find) ${DIR_COLORSCRIPTS} -maxdepth 1 -type f | xargs -I$ basename $" +else + LS_CMD="$(command -v ls) ${DIR_COLORSCRIPTS} | xargs -I$ basename $" +fi function _colorscript { local curcontext="$curcontext" state line @@ -15,12 +20,19 @@ function _colorscript { _arguments "1:subcmd:((help:'Print help'\ list:'List all color scripts.'\ exec:'Run a specific color script.'\ + blacklist:'Blacklist a specific color script.'\ + all:'Run all the color scripts.'\ random:'Run a random color script.'))" ;; *) case $words[2] in "exec") - for colorscript in $(/usr/bin/ls ${DIR_COLORSCRIPTS}); do + for colorscript in $(sh -c $LS_CMD); do + compadd ${colorscript} + done + ;; + "blacklist") + for colorscript in $(sh -c $LS_CMD); do compadd ${colorscript} done ;; |