Updated script to default to log. Added better output format via awk
This commit is contained in:
parent
d085b55953
commit
7f52b15d63
30
gab
30
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;;
|
||||
|
|
Loading…
Reference in New Issue