2024-02-01 22:57:46 +00:00
|
|
|
#!/bin/bash
|
|
|
|
#
|
|
|
|
# cli.sh
|
|
|
|
# ------
|
|
|
|
#
|
|
|
|
# === Menu Driven ===
|
|
|
|
# Begin: Update or New Game or Exit
|
|
|
|
# Update: Select from recent or Quick Search
|
|
|
|
# New: Enter New Game. Return to Menu
|
|
|
|
# === CLI Driven ===
|
|
|
|
# -n New Game
|
|
|
|
# -u Update Game
|
|
|
|
|
|
|
|
db="db/games.rec"
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-01 22:57:46 +00:00
|
|
|
function main_menu {
|
|
|
|
cat<<EOF
|
2024-02-03 17:04:05 +00:00
|
|
|
|
|
|
|
== Main Menu ==
|
2024-02-01 22:57:46 +00:00
|
|
|
1. [U]pdate
|
|
|
|
2. [N]ew Game
|
|
|
|
3. [E]dit Game
|
|
|
|
4. [Q]uit
|
|
|
|
EOF
|
|
|
|
read -p "> " selection;
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-01 22:57:46 +00:00
|
|
|
function new_game () {
|
|
|
|
read -p "System: " system
|
|
|
|
read -p "Module: " module
|
|
|
|
cat<<EOF
|
|
|
|
Role:
|
|
|
|
1. [D]M
|
|
|
|
2. [P]layer
|
|
|
|
EOF
|
|
|
|
read -p "> " roleinput
|
|
|
|
cat<<EOF
|
|
|
|
Length:
|
|
|
|
1. [C]ampaign
|
|
|
|
2. [A]dventure
|
|
|
|
3. [O]neshot
|
|
|
|
EOF
|
|
|
|
read -p "> " lengthinput
|
|
|
|
read -p "Format: " format
|
|
|
|
|
|
|
|
case "$roleinput" in
|
|
|
|
"D" | "d" | 1) role="DM";;
|
|
|
|
"P" | "p" | 2) role="Player";;
|
|
|
|
"*") echo "Unknown Role!"; exit 1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
case "$lengthinput" in
|
|
|
|
"C" | "c" | 1) length="Campaign";;
|
|
|
|
"A" | "a" | 2) length="Adventure";;
|
|
|
|
"O" | "o" | 3) length="Oneshot";;
|
|
|
|
"*") echo "Unknown Length!"; exit 1;;
|
|
|
|
esac
|
|
|
|
|
|
|
|
recins $db --verbose -t Game \
|
|
|
|
-f "System" -v "$system" \
|
|
|
|
-f "Module" -v "$module" \
|
|
|
|
-f "Role" -v "$role" \
|
|
|
|
-f "Length" -v "$length" \
|
|
|
|
-f "Format" -v "$format" \
|
|
|
|
-f "Status" -v "Ongoing"
|
|
|
|
}
|
|
|
|
|
|
|
|
gamemenutmpl="{{Id}}. {{Module}} ({{System}})
|
|
|
|
"
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-01 22:57:46 +00:00
|
|
|
function edit_game () {
|
|
|
|
id="$1"
|
|
|
|
shift
|
|
|
|
recsel $db -t Game -e "Id = $id" \
|
|
|
|
| awk 'BEGIN { RS="\n" } { print NR ". " $0 }'
|
|
|
|
read -p "Number/[A]bort> " selection
|
|
|
|
case $selection in
|
|
|
|
"a" | "A" | "x" | "X" | "")
|
|
|
|
edit_menu;;
|
|
|
|
*)
|
|
|
|
fieldvalue=(`recsel $db -t Game -e "Id = $id" \
|
|
|
|
| awk 'BEGIN { RS="\n"; FS=": " } NR == s { print $1 " " $2 }' s="$selection"`)
|
|
|
|
echo "${fieldvalue[0]}: ${fieldvalue[1]}"
|
|
|
|
read -p "New value: " value
|
|
|
|
recset --verbose $db -t Game -e "Id = $id" -f "${fieldvalue[0]}" -s "$value";
|
|
|
|
edit_game $id;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-01 22:57:46 +00:00
|
|
|
function update () {
|
|
|
|
id="$1"
|
|
|
|
shift
|
2024-02-03 21:50:24 +00:00
|
|
|
read -p "Date> " created
|
2024-02-01 22:57:46 +00:00
|
|
|
tmp=$(mktemp)
|
|
|
|
$EDITOR "$tmp"
|
|
|
|
Text=$(< "$tmp")
|
2024-02-03 21:50:24 +00:00
|
|
|
recins --verbose $db -t Update -f Game -v "$id" -f Text -v "$Text" -f Created -v "$created"
|
2024-02-01 22:57:46 +00:00
|
|
|
recsel $db -t Update -q "$Text"
|
|
|
|
main_menu
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-03 22:03:05 +00:00
|
|
|
function recent_updates () {
|
|
|
|
count=`recsel -t Update $db -c`
|
2024-02-01 22:57:46 +00:00
|
|
|
recent="$((count - 7))"
|
2024-02-03 22:03:05 +00:00
|
|
|
recsel $db \
|
|
|
|
-t Update \
|
|
|
|
-e "Id > ${recent}" \
|
|
|
|
-j Game \
|
|
|
|
-p Game_Id:Id,Game_Module:Module,Game_System:System \
|
|
|
|
| recfmt "${gamemenutmpl}"
|
2024-02-01 22:57:46 +00:00
|
|
|
read -p "Number> " id
|
|
|
|
case $id in
|
|
|
|
"" | "b" | "B" | "x" | "X" | "q" | "Q")
|
|
|
|
update_menu;;
|
|
|
|
*)
|
|
|
|
update $id;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-03 22:03:05 +00:00
|
|
|
function search_updates () {
|
2024-02-01 22:57:46 +00:00
|
|
|
read -p "Query> " q
|
|
|
|
recsel $db -t Game -i -q "${q}" | recfmt "${gamemenutmpl}"
|
|
|
|
read -p "Number> " id
|
|
|
|
case id in
|
|
|
|
"" | "b" | "B" | "x" | "X" | "q" | "Q")
|
|
|
|
update_menu;;
|
|
|
|
*)
|
|
|
|
update $id;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-01 22:57:46 +00:00
|
|
|
function recent_games () {
|
|
|
|
count=`recsel -t Game $db -c`
|
|
|
|
recent="$((count - 7))"
|
|
|
|
recsel $db -t Game -e "Id > ${recent}" | recfmt "${gamemenutmpl}"
|
|
|
|
read -p "Number> " id
|
|
|
|
case $id in
|
|
|
|
"" | "b" | "B" | "x" | "X" | "q" | "Q")
|
|
|
|
edit_menu;;
|
|
|
|
*)
|
|
|
|
edit_game $id;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-01 22:57:46 +00:00
|
|
|
function search_games () {
|
|
|
|
read -p "Query> " q
|
|
|
|
recsel $db -t Game -i -q "${q}" | recfmt "${gamemenutmpl}"
|
|
|
|
read -p "Number> " id
|
|
|
|
case id in
|
|
|
|
"" | "b" | "B" | "x" | "X" | "q" | "Q")
|
|
|
|
edit_menu;;
|
|
|
|
*)
|
|
|
|
edit_game $id;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-01 22:57:46 +00:00
|
|
|
function update_menu () {
|
|
|
|
cat<<EOF
|
2024-02-03 17:04:05 +00:00
|
|
|
|
|
|
|
== Find Game To Update ==
|
2024-02-01 22:57:46 +00:00
|
|
|
1. [R]ecent Games
|
|
|
|
2. [S]earch
|
|
|
|
3. [M]ain menu
|
|
|
|
EOF
|
|
|
|
read -p "> " menu
|
|
|
|
|
|
|
|
case "$menu" in
|
|
|
|
1 | "r" | "R")
|
2024-02-03 22:03:05 +00:00
|
|
|
recent_updates;;
|
2024-02-01 22:57:46 +00:00
|
|
|
2 | "s" | "S")
|
2024-02-03 22:03:05 +00:00
|
|
|
search_updates;;
|
2024-02-01 22:57:46 +00:00
|
|
|
3 | "m" | "M" | "q" | "Q" | "b" | "B")
|
|
|
|
main_menu;;
|
|
|
|
*)
|
|
|
|
echo "Select a number or letter from the menu";edit_menu;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
2024-02-01 22:57:46 +00:00
|
|
|
function edit_menu () {
|
|
|
|
cat<<EOF
|
2024-02-03 17:04:05 +00:00
|
|
|
|
|
|
|
== Edit Existing Game ==
|
2024-02-01 22:57:46 +00:00
|
|
|
1. [R]ecent Games
|
|
|
|
2. [S]earch
|
|
|
|
3. [M]ain menu
|
|
|
|
EOF
|
|
|
|
read -p "> " menu
|
|
|
|
|
|
|
|
case "$menu" in
|
|
|
|
1 | "r" | "R")
|
|
|
|
recent_games;;
|
|
|
|
2 | "s" | "S")
|
|
|
|
search_games;;
|
|
|
|
3 | "m" | "M" | "q" | "Q" | "b" | "B")
|
|
|
|
main_menu;;
|
|
|
|
*)
|
|
|
|
echo "Select a number or letter from the menu";edit_menu;;
|
|
|
|
esac
|
|
|
|
}
|
|
|
|
|
2024-02-03 21:50:24 +00:00
|
|
|
|
|
|
|
|
|
|
|
function main () {
|
2024-02-01 22:57:46 +00:00
|
|
|
main_menu
|
|
|
|
|
|
|
|
case "$selection" in
|
|
|
|
1 | "u" | "U")
|
|
|
|
update_menu;;
|
|
|
|
2 | "n" | "N")
|
|
|
|
new_game;;
|
|
|
|
3 | "e" | "E")
|
|
|
|
edit_menu;;
|
|
|
|
4 | "x" | "X" | "q" | "Q")
|
|
|
|
echo "Byeeee";;
|
|
|
|
*)
|
|
|
|
echo "Select a letter or number from the menu";;
|
|
|
|
esac
|
2024-02-03 21:50:24 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
main
|