To modify the script to check multiple directories, you can create a separate file that lists the directories you want to check. Then, you can read this file in your script and iterate over the directories listed in it.
Here's how you can do it:
-
Create a file to list the directories:
Create a file named directories.txt and list the directories you want to check, one per line. For example:
/home/wovri
/home/user1
/home/user2
/home/user3
-
Modify the script to read from the file:
Update your script to read the directories from directories.txt and iterate over them.
#!/usr/bin/env fish
# Read the list of directories from the file
set DIRECTORIES (cat directories.txt)
# Iterate over each directory
for DIRECTORY in $DIRECTORIES
# Find all .git directories under the given path
for git_dir in (find $DIRECTORY -type d -name .git)
# Get the directory containing the .git folder
set repo_dir (dirname "$git_dir")
# Check if there are unstaged changes
if git -C "$repo_dir" status --porcelain | grep -q '^.[^ ]'
echo "Warning: Unstaged changes found in $repo_dir"
end
end
end
This script will read the list of directories from directories.txt, and for each directory, it will find all .git directories and check for unstaged changes.
Explanation:
-
Reading the Directories:
set DIRECTORIES (cat directories.txt): This command reads the contents of directories.txt and stores it in the DIRECTORIES variable.
-
Iterating Over Directories:
for DIRECTORY in $DIRECTORIES: This loop iterates over each directory listed in directories.txt.
-
Finding .git Directories and Checking for Unstaged Changes:
- The inner loop and the
git command remain the same as in your original script, but now they are executed for each directory listed in directories.txt.
This approach makes it easy to manage and update the list of directories without modifying the script itself.