Skip to content

bash script added #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
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"