Skip to content

Instantly share code, notes, and snippets.

@tir38
Created December 29, 2017 16:49
Show Gist options
  • Save tir38/60391e59061300bcf9b2dda24148b359 to your computer and use it in GitHub Desktop.
Save tir38/60391e59061300bcf9b2dda24148b359 to your computer and use it in GitHub Desktop.
Find a random file within an Android project (excluding generated files)
echo "Finding random file..."
# get all files in root dir
files=$(find . -type f)
# iterate over file list and filter out some things
saved_index=0
all_file_count=0
while read -r line; do
all_file_count=$(($all_file_count+1));
# filter out files in .idea dir
if [[ $line == *"/.idea"* ]]; then
continue
fi
# filter out files in .git dir
if [[ $line == *"/.git"* ]]; then
continue
fi
# filter out files in .build dirs
if [[ $line == *"/build"* ]]; then
continue
fi
saved_files[$saved_index]="$line";
saved_index=$(($saved_index+1));
done <<< "$files"
# echo "${all_file_count} files scanned"
# echo "${saved_index} files added to list"
# generate random number from range
random_number=$(($RANDOM%$saved_index))
# echo "random file index: ${random_number}"
echo "Your random file is:"
echo ${saved_files[$random_number]}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment