Navigation Menu

Skip to content

Instantly share code, notes, and snippets.

@thingsiplay
Created July 28, 2021 17:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save thingsiplay/21f92ab90cfbb75afc49a4624389c462 to your computer and use it in GitHub Desktop.
Save thingsiplay/21f92ab90cfbb75afc49a4624389c462 to your computer and use it in GitHub Desktop.
lpl - Read entries from RetroArch .lpl playlist files in JSON format (powered by jq)
#!/bin/env bash
# lpl - Read entries from RetroArch .lpl playlist files in JSON format
#
# USAGE
# See `lpl -h`
#
# DEPENDENCIES
# getopts - Arguments parser (Bash built-in function)
# readlink - Get fullpath from path (standard program)
# jq - JSON parser (external program)
# DEFAULTS
QUERY="path"
FILE="$HOME/.config/retroarch/content_history.lpl"
INDEX=""
# PARSE ARGUMENTS
while getopts "hq:f:i:" flag
do
if [ "$flag" == "h" ]
then
echo "lpl [-h] [-q QUERY] [-f FILE] [-i INDEX]"
echo ""
echo "EXAMPLES:"
echo " lpl"
echo " lpl -q core_path"
echo " lpl -f "$HOME/.config/retroarch/playlists/Atari - 2600.lpl" -i 0"
echo ""
echo "QUERY:"
echo " keyname to read values from: 'path', 'label', 'core_path'," \
"'core_name', 'crc32', 'db_name', 'default_core_path'," \
"'default_core_name', defaults to: '$QUERY'"
echo ""
echo "FILE:"
echo " path to RetroArch .lpl playlist file in JSON format," \
"defaults to: '$FILE'"
echo ""
echo "INDEX:"
echo " integer to limit output of entries, 0=first, 1=second," \
"-1=last, an empty value will get all entries," \
"defaults to: '$INDEX'"
echo ""
echo "2021 Tuncay D."
exit 0
fi
if [ "$flag" == "q" ]
then
QUERY="$OPTARG"
fi
if [ "$flag" == "f" ]
then
FILE="$OPTARG"
fi
if [ "$flag" == "i" ]
then
INDEX="$OPTARG"
fi
done
FILE=$(readlink -f "$FILE")
if [ "$QUERY" == "default_core_path" ]
then
QUERY_EXPANDED=".default_core_path"
elif [ "$QUERY" == "default_core_name" ]
then
QUERY_EXPANDED=".default_core_name"
else
QUERY_EXPANDED=".items[$INDEX]? | select(.$QUERY != null) | .$QUERY"
fi
jq --raw-output "$QUERY_EXPANDED" "$FILE"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment