-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathff
executable file
·36 lines (28 loc) · 831 Bytes
/
ff
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
#!/bin/bash
# Usage: ff -d "target,.git" -f "lock,abi"
# Parse options
while getopts "d:f:" opt; do
case $opt in
d) directories=$OPTARG ;;
f) filetypes=$OPTARG ;;
\?) echo "Usage: ff -d \"dir1,dir2\" -f \"ext1,ext2\"" >&2; exit 1 ;;
esac
done
# Convert comma-separated lists to arrays
IFS=',' read -r -a dir_array <<< "$directories"
IFS=',' read -r -a filetype_array <<< "$filetypes"
# Build the find command
find_command="find ."
# Add directory exclusion conditions
for dir in "${dir_array[@]}"; do
find_command+=" -type d -name $dir -prune -o"
done
# Add file exclusion conditions
find_command+=" -type f"
for ext in "${filetype_array[@]}"; do
find_command+=" ! -name \"*.$ext\""
done
# Add the print action at the end
find_command+=" -print"
# Execute the generated find command
eval "$find_command"