Initial commit of basic script
This commit is contained in:
commit
d085b55953
|
@ -0,0 +1,55 @@
|
|||
#!/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. :)
|
||||
# # # # # #->
|
||||
|
||||
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"
|
||||
|
||||
title="GAB v1.0"
|
||||
last_date="Last message: $(date -r ./gablog)"
|
||||
|
||||
if [ -z "$1" ]
|
||||
then
|
||||
echo "No argument provided"
|
||||
exit 1
|
||||
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" >> ./gablog
|
||||
if [ $? -eq 0 ]
|
||||
then
|
||||
echo "Successfully added text to chatlog"
|
||||
else
|
||||
echo "Error adding text to chatlog"
|
||||
fi
|
||||
fi;;
|
||||
-l | --log)
|
||||
if [ -z "$2" ]
|
||||
then
|
||||
echo $title
|
||||
echo $last_date
|
||||
echo ""
|
||||
tail -n 5 ./gablog
|
||||
elif [[ "$2" =~ ^[0-9]+$ ]]
|
||||
then
|
||||
echo $title
|
||||
echo $last_date
|
||||
echo ""
|
||||
tail -n $2 ./gablog
|
||||
else
|
||||
echo "Invalid: log value must be an integer"
|
||||
exit 1
|
||||
fi;;
|
||||
-h | --help) echo $help;;
|
||||
*)
|
||||
echo "Unknown flag $1"
|
||||
exit 1;;
|
||||
esac
|
||||
fi
|
||||
|
Loading…
Reference in New Issue