Skip to content

Instantly share code, notes, and snippets.

@manciuszz
Last active December 19, 2021 22:49
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
Save manciuszz/4c0ce68cf971719710cfe53889a2206d to your computer and use it in GitHub Desktop.
PrimoCache shell script to preload data to cache.
#!/bin/sh
read_files_from_textfile() {
while IFS=$' \t\r\n' read -r directory || [ -n "$directory" ]; do
read_files_from_directory "$directory"
done < "$1"
}
read_files_from_directory() {
suffix=$([ $# -gt 1 ] && echo "ies" || echo "y");
echo "Loading director$suffix $@";
find "$1" -type f -exec cat {} + | dd of=/dev/null bs=1M status=progress
}
read_files() {
for path in "$@"; do
if [[ ${path##*.} == "txt" ]]; then
read_files_from_textfile "$path"
else
read_files_from_directory "$path"
fi
done
}
if [[ $# -gt 0 ]]; then
echo "Loading cache with PrimoCache!";
read_files "$@"
else
echo "No directories or text files were specified!";
fi

Usage

For ease-of-use setup an alias. For example:

alias prime-cache="C:/primecache-content.sh"

Then in the future, when you want to preload data, you'll be able to read from the current folder like so:

prime-cache .
# or 
prime-cache "D:\Games"
# or
prime-cache "D:\Game1Folder" "D:\Game2Folder"
# or from list
prime-cache ./preload-list.txt
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment