From 7f52b15d639a0cb740bf8230c22e011ed855ede8 Mon Sep 17 00:00:00 2001 From: sloumdrone Date: Thu, 20 Dec 2018 18:53:58 -0800 Subject: [PATCH] Updated script to default to log. Added better output format via awk --- gab | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/gab b/gab index 6403d21..6dba580 100755 --- a/gab +++ b/gab @@ -1,18 +1,24 @@ #!/bin/bash # 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. -# Gablog can be moved pretty much anywhere though. :) +# 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="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" -last_date="Last message: $(date -r ./gablog)" +last_date="Last message: $(date -r $file_path)" if [ -z "$1" ] then - echo "No argument provided" - exit 1 + 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) @@ -21,12 +27,14 @@ else echo "Must pass a quoted string w/ the msg flag" exit 1 else - echo "$USER > $2" >> ./gablog + 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) @@ -35,18 +43,20 @@ else echo $title echo $last_date 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]+$ ]] then echo $title echo $last_date 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 echo "Invalid: log value must be an integer" exit 1 fi;; - -h | --help) echo $help;; + -h | --help) + echo "$help_text" + exit 0;; *) echo "Unknown flag $1" exit 1;;