Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <path to folder where color-script is located>
```

## Contributions

Expand Down
30 changes: 30 additions & 0 deletions random_selector.sh
Original file line number Diff line number Diff line change
@@ -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"