Updated script to default to log. Added better output format via awk

This commit is contained in:
sloumdrone 2018-12-20 18:53:58 -08:00
parent d085b55953
commit 7f52b15d63
1 changed files with 20 additions and 10 deletions

30
gab
View File

@ -1,18 +1,24 @@
#!/bin/bash #!/bin/bash
# Gab is an alternate client to the chat program at colorfield.space # Gab is an alternate client to the chat program at colorfield.space
# It assumes that a file named gablog exists in the same directory as the script. # Replace the $file_path variable with the path to your chat log
# Gablog can be moved pretty much anywhere though. :) # 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="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" 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" title="GAB v1.0"
last_date="Last message: $(date -r ./gablog)" last_date="Last message: $(date -r $file_path)"
if [ -z "$1" ] if [ -z "$1" ]
then then
echo "No argument provided" echo $title
exit 1 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 else
case "$1" in case "$1" in
-m | --msg) -m | --msg)
@ -21,12 +27,14 @@ else
echo "Must pass a quoted string w/ the msg flag" echo "Must pass a quoted string w/ the msg flag"
exit 1 exit 1
else else
echo "$USER > $2" >> ./gablog echo "$USER > $2" >> $file_path
if [ $? -eq 0 ] if [ $? -eq 0 ]
then then
echo "Successfully added text to chatlog" echo "Successfully added text to chatlog"
exit 0
else else
echo "Error adding text to chatlog" echo "Error adding text to chatlog"
exit 1
fi fi
fi;; fi;;
-l | --log) -l | --log)
@ -35,18 +43,20 @@ else
echo $title echo $title
echo $last_date echo $last_date
echo "" echo ""
tail -n 5 ./gablog 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]+$ ]] elif [[ "$2" =~ ^[0-9]+$ ]]
then then
echo $title echo $title
echo $last_date echo $last_date
echo "" echo ""
tail -n $2 ./gablog 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 else
echo "Invalid: log value must be an integer" echo "Invalid: log value must be an integer"
exit 1 exit 1
fi;; fi;;
-h | --help) echo $help;; -h | --help)
echo "$help_text"
exit 0;;
*) *)
echo "Unknown flag $1" echo "Unknown flag $1"
exit 1;; exit 1;;