From 43e3965be29e6d0f6a1e5056863d9da30db8dea2 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Sep 2024 00:44:06 +0800 Subject: [PATCH 1/3] bash script added --- README.md | 10 ++++++++++ random_selector.sh | 30 ++++++++++++++++++++++++++++++ 2 files changed, 40 insertions(+) create mode 100755 random_selector.sh diff --git a/README.md b/README.md index b358d3f..d4fda83 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 +``` +chmod +x random_selector.sh +``` +or if you have color-script file stored in a different place then you can pass it as argument for example + +``` +./random_selector.sh +``` ## Contributions diff --git a/random_selector.sh b/random_selector.sh new file mode 100755 index 0000000..baf49d3 --- /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" From f828ca215f56cdf7d844b7c7d70c2dc536d59797 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Sep 2024 00:50:28 +0800 Subject: [PATCH 2/3] mistake fix --- random_selector.sh | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/random_selector.sh b/random_selector.sh index baf49d3..febba39 100755 --- a/random_selector.sh +++ b/random_selector.sh @@ -1,6 +1,6 @@ #!/bin/bash -DEFAULT_DIRECTORY="color-scripts" +DEFAULT_DIRECTORY="./color-scripts" # Use the provided directory or fall back to the default DIRECTORY="${1:-$DEFAULT_DIRECTORY}" From 84b14586118f6501c70b178c5cd28492216d5782 Mon Sep 17 00:00:00 2001 From: root Date: Wed, 4 Sep 2024 00:53:28 +0800 Subject: [PATCH 3/3] readme update --- README.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index d4fda83..3843fcc 100644 --- a/README.md +++ b/README.md @@ -35,11 +35,11 @@ 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 +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 argument for example +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