-
-
Save mry/0a17edb9faa327e4f7d723dc8298ddf6 to your computer and use it in GitHub Desktop.
Minecraft client chat log search
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env bash | |
# Minecraft folder | |
cd /Users/your_system_username/Library/Application\ Support/minecraft | |
function scan_logs { | |
VAL="$1" | |
# Search for query | |
if [ "$(echo ${#STR})" -ge 1 ]; then | |
VAL="$( echo "${VAL}" | grep -i ${STR} )" | |
fi | |
# Clean up the output | |
CLEAN="$( echo "${VAL}" | sed 's/\[Client thread\/INFO\]:*.\[CHAT\]//' )" | |
echo "$CLEAN" | |
} | |
if [ -z "$1" ]; then | |
# Help text | |
echo "Usage:" | |
echo "--list to show available log files" | |
echo "--log <file> [search] to print a log file" | |
echo "--follow to follow live chat output" | |
elif [ $1 == "--list" ]; then | |
# Iterate log files and print their names | |
pref="./logs/" | |
suf=".log.gz" | |
for i in ./logs/*log.gz; do | |
s="${i#$pref}" | |
s="${s%$suf}" | |
echo $s | |
done | |
echo "latest" | |
elif [ $1 == "--log" ]; then | |
FILE=$2 | |
STR=$3 | |
if [ -z "$2" ]; then | |
# No file was specified | |
echo "You must specify a log file!" | |
elif [ $2 == "latest" ]; then | |
# Read latest.log | |
VAL="$( grep -Fi '[chat]' ./logs/latest.log )" | |
scan_logs "$VAL" | |
else | |
# Read gzipped log file | |
VAL="$( zgrep -Fi '[chat]' ./logs/${FILE}.log.gz )" | |
scan_logs "$VAL" | |
fi | |
elif [ $1 == "--follow" ]; then | |
tail -f ./logs/latest.log | grep -Fi --line-buffered '[chat]' | sed 's/\[Client thread\/INFO\]:*.\[CHAT\]//' | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment