waypoint
This commit is contained in:
1 parent
db7a9c4324
commit
61e12cd0d5
1 file changed
+127
-13
+127
-13
@@ -1,29 +1,143 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
# break all args into a string
|
||||||
|
# all_args="$@"
|
||||||
|
# echo "args: $all_args"
|
||||||
|
# echo "arg number: $#"
|
||||||
|
# for arg in "$@"; do
|
||||||
|
#
|
||||||
|
# done
|
||||||
|
while getopts "w:b:pdc:" opt; do
|
||||||
|
case "$opt" in
|
||||||
|
w)
|
||||||
|
## break whitelist str into array
|
||||||
|
whitelist_array="${OPTARG[@]}"
|
||||||
|
echo "$whitelist_array"
|
||||||
|
IFS=' ' read -r -a whitelist <<< "$whitelist_array"
|
||||||
|
# echo $whitelist
|
||||||
|
|
||||||
|
# echo "opt"
|
||||||
|
# echo "$opt"
|
||||||
|
# declare -p opt
|
||||||
|
# echo
|
||||||
|
# echo "OPTARG"
|
||||||
|
# echo "$OPTARG"
|
||||||
|
# declare -p OPTARG
|
||||||
|
# echo "whitelist_array"
|
||||||
|
# echo "$whitelist_array"
|
||||||
|
# declare -p whitelist_array
|
||||||
|
# echo
|
||||||
|
# echo "whitelist"
|
||||||
|
# echo "$whitelist"
|
||||||
|
# declare -p whitelist
|
||||||
|
|
||||||
|
### start the whitelist group
|
||||||
|
#### prepended space to make final assembly cleaner
|
||||||
|
whitelist_find_str=' \('
|
||||||
|
#### whitelist counter so it knows its in the first position (to not add the -o)
|
||||||
|
whitelist_counter=0
|
||||||
|
### loop through array of whitelisted exts
|
||||||
|
for ext in "${whitelist}"; do
|
||||||
|
### only add -o after the first one
|
||||||
|
if [ $whitelist_counter -eq 0 ]; then
|
||||||
|
#### test if array has exactly one item
|
||||||
|
if [ ${#whitelist[@]} -eq 1 ]; then
|
||||||
|
##### Append space because its the only entry
|
||||||
|
whitelist_find_str+=" -iname \"*.${ext}\" "
|
||||||
|
else
|
||||||
|
##### no appended space on first one to make it neat with the -o's
|
||||||
|
whitelist_find_str+=" -iname \"*.${ext}\""
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
whitelist_find_str+=" -o -iname \"*.${ext}\" "
|
||||||
|
fi
|
||||||
|
|
||||||
|
### increment counter
|
||||||
|
whitelist_counter=$(($whitelist_counter + 1));
|
||||||
|
done
|
||||||
|
## finish the whitelist group
|
||||||
|
### appended space to make final assembly cleaner
|
||||||
|
whitelist_find_str+='\) '
|
||||||
|
;;
|
||||||
|
esac
|
||||||
|
done
|
||||||
|
echo "$whitelist_find_str"
|
||||||
|
|
||||||
|
exit 0
|
||||||
|
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
echo -e 'Usage:\n\tfind_ext.sh <str extensions whitelist> <str extensions blacklist>\n\tfind_ext.sh "jpg mp3 png" ["doc pdf svg"]'
|
echo -e 'Usage:\n\tfind_ext.sh <str extensions whitelist> <str extensions blacklist>\n\tfind_ext.sh "jpg mp3 png" ["doc pdf svg"]'
|
||||||
exit 1
|
exit 1
|
||||||
else
|
else
|
||||||
# start the whitelist group
|
|
||||||
whitelist_find_str='\('
|
|
||||||
|
|
||||||
# break whitelist str into array
|
# break whitelist str into array
|
||||||
IFS=' ' read -r -a whitelist <<< "$1"
|
IFS=' ' read -r -a whitelist <<< "$1"
|
||||||
|
|
||||||
# loop through array of whitelisted exts
|
# create the whitelisted find section text
|
||||||
|
## start the whitelist group
|
||||||
|
## prepended space to make final assembly cleaner
|
||||||
|
whitelist_find_str=' \('
|
||||||
|
## whitelist counter so it knows its in the first position (to not add the -o)
|
||||||
|
whitelist_counter=0
|
||||||
|
## loop through array of whitelisted exts
|
||||||
for ext in "${whitelist[@]}"; do
|
for ext in "${whitelist[@]}"; do
|
||||||
whitelist_find_str+=" -iname \" *.${ext}\" "
|
### only add -o after the first one
|
||||||
|
if [ $whitelist_counter -eq 0 ]; then
|
||||||
|
#### test if array has exactly one item
|
||||||
|
if [ ${#whitelist[@]} -eq 1 ]; then
|
||||||
|
##### Append space because its the only entry
|
||||||
|
whitelist_find_str+=" -iname \"*.${ext}\" "
|
||||||
|
else
|
||||||
|
##### no appended space on first one to make it neat with the -o's
|
||||||
|
whitelist_find_str+=" -iname \"*.${ext}\""
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
whitelist_find_str+=" -o -iname \"*.${ext}\" "
|
||||||
|
fi
|
||||||
|
|
||||||
|
### increment counter
|
||||||
|
whitelist_counter=$(($whitelist_counter + 1));
|
||||||
done
|
done
|
||||||
|
## finish the whitelist group
|
||||||
# finish the whitelist group
|
### appended space to make final assembly cleaner
|
||||||
whitelist_find_str+='/)'
|
whitelist_find_str+='\) '
|
||||||
|
|
||||||
echo "$whitelist_find_str";
|
|
||||||
|
|
||||||
# make find command
|
|
||||||
# find_cmd="find . "
|
|
||||||
fi
|
fi
|
||||||
|
|
||||||
if [ ! -z "$2" ]; then
|
if [ ! -z "$2" ]; then
|
||||||
# break blacklist str into array
|
# break blacklist str into array
|
||||||
IFS=' ' read -r -a blacklist <<< "$2"
|
IFS=' ' read -r -a blacklist <<< "$2"
|
||||||
|
|
||||||
|
# create the blacklist find section text
|
||||||
|
## start the whitelist group
|
||||||
|
## has the -not for blacklisting
|
||||||
|
## prepended space to make final assembly cleaner
|
||||||
|
blacklist_find_str=' -not \('
|
||||||
|
## whitelist counter so it knows its in the first position (to not add the -o)
|
||||||
|
blacklist_counter=0
|
||||||
|
## loop through array of whitelisted exts
|
||||||
|
for ext in "${blacklist[@]}"; do
|
||||||
|
### only add -o after the first one
|
||||||
|
if [ $blacklist_counter -eq 0 ]; then
|
||||||
|
#### test if array has exactly one item
|
||||||
|
if [ ${#blacklist[@]} -eq 1 ]; then
|
||||||
|
##### Append space because its the only entry
|
||||||
|
blacklist_find_str+=" -iname \"*.${ext}\" "
|
||||||
|
else
|
||||||
|
##### no appended space on first one to make it neat with the -o's
|
||||||
|
blacklist_find_str+=" -iname \"*.${ext}\""
|
||||||
|
fi
|
||||||
|
else
|
||||||
|
blaclklist_find_str+=" -o -iname \"*.${ext}\" "
|
||||||
|
fi
|
||||||
|
|
||||||
|
### increment counter
|
||||||
|
blacklist_counter=$(($whitelist_counter + 1));
|
||||||
|
done
|
||||||
|
## finish the whitelist group
|
||||||
|
### appended space to make final assembly cleaner
|
||||||
|
blacklist_find_str+='\) '
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
# assemble the find command
|
||||||
|
## "$PWD" used for dir instead of . to output absolute paths
|
||||||
|
find_str="find \"$PWD\"${whitelist_find_str}${blacklist_find_str}-print";
|
||||||
|
echo "$find_str"
|
||||||
|
bash -c "$find_str"
|
||||||
Reference in new issue
Block a user