66 lines
1.8 KiB
Bash
Executable File
66 lines
1.8 KiB
Bash
Executable File
#!/bin/bash
|
|
# Gab is an alternate client to the chat program at colorfield.space
|
|
# Replace the $file_path variable with the path to your chat log
|
|
# It is assumed that each line of chat starts as follows: "user_name >"
|
|
# other schemes or formats will require modification of the awk script
|
|
# found on lines 40 & 46
|
|
# # # # # #->
|
|
|
|
help_text=$'GAB - A simple chat interface\n\nsyntax: gab [flag] [value]\n\nflag value\n---------- ---------------\n-h, --help none\n-m, --msg Quoted text with the msg being added to chat\n-l, --log An integer representing the number of rows you\'d like to view, default 5'
|
|
|
|
file_path=./test.txt
|
|
title="GAB v1.0"
|
|
last_date="Last message: $(date -r $file_path)"
|
|
|
|
if [ -z "$1" ]
|
|
then
|
|
echo $title
|
|
echo $last_date
|
|
echo ""
|
|
tail -n 5 $file_path | awk '{out="\033[7m " $1 " \033[0m "; for (i=3; i<=NF; i++) {out=out" "$i}; print out ORS "- - -"}'
|
|
|
|
else
|
|
case "$1" in
|
|
-m | --msg)
|
|
if [ -z "$2" ]
|
|
then
|
|
echo "Must pass a quoted string w/ the msg flag"
|
|
exit 1
|
|
else
|
|
echo "$USER > $2" >> $file_path
|
|
if [ $? -eq 0 ]
|
|
then
|
|
echo "Successfully added text to chatlog"
|
|
exit 0
|
|
else
|
|
echo "Error adding text to chatlog"
|
|
exit 1
|
|
fi
|
|
fi;;
|
|
-l | --log)
|
|
if [ -z "$2" ]
|
|
then
|
|
echo $title
|
|
echo $last_date
|
|
echo ""
|
|
tail -n 5 $file_path | awk '{out="\033[7m " $1 " \033[0m "; for (i=3; i<=NF; i++) {out=out" "$i}; print out ORS "- - -"}'
|
|
elif [[ "$2" =~ ^[0-9]+$ ]]
|
|
then
|
|
echo $title
|
|
echo $last_date
|
|
echo ""
|
|
tail -n $2 $file_path | awk '{out="\033[7m " $1 " \033[0m "; for (i=3; i<=NF; i++) {out=out" "$i}; print out ORS "- - -"}'
|
|
else
|
|
echo "Invalid: log value must be an integer"
|
|
exit 1
|
|
fi;;
|
|
-h | --help)
|
|
echo "$help_text"
|
|
exit 0;;
|
|
*)
|
|
echo "Unknown flag $1"
|
|
exit 1;;
|
|
esac
|
|
fi
|
|
|