diff --git a/README.md b/README.md index b358d3f..3843fcc 100644 --- a/README.md +++ b/README.md @@ -34,6 +34,16 @@ wget git.io/colr.tar.gz ``` wget git.io/colr.zip ``` +### BASH SCRIPT ADDED +you can either make that bash script random_selector.sh as executable and then link it to your bashrc or zshrc file and set the var DEFAULT_DIRECTORY pointing to the directory where color-scripts are located. +``` +chmod +x random_selector.sh +``` +or if you have color-script file stored in a different place then you can pass it as a command line argument for example + +``` +./random_selector.sh +``` ## Contributions diff --git a/random_selector.sh b/random_selector.sh new file mode 100755 index 0000000..febba39 --- /dev/null +++ b/random_selector.sh @@ -0,0 +1,30 @@ +#!/bin/bash + +DEFAULT_DIRECTORY="./color-scripts" + +# Use the provided directory or fall back to the default +DIRECTORY="${1:-$DEFAULT_DIRECTORY}" + +if [ ! -d "$DIRECTORY" ]; then + echo "Directory $DIRECTORY does not exist." + exit 1 +fi + +files=("$DIRECTORY"/*) +executable_files=() + +for file in "${files[@]}"; do + if [ -x "$file" ]; then + executable_files+=("$file") + fi +done + +if [ ${#executable_files[@]} -eq 0 ]; then + echo "No executable files found in $DIRECTORY." + exit 1 +fi + +random_file="${executable_files[RANDOM % ${#executable_files[@]}]}" + +# Execute the selected file +"$random_file"