summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authortaro <taro>2021-09-22 15:46:18 +0000
committertaro <taro>2021-09-22 15:46:18 +0000
commit11483560ba54a5c9c87accb0048596889ef01f46 (patch)
treec6edd78fe7bc8e6cfda5f159c70050e39cd567ca
parente8638bed5e35495e53063d467c25bcd0a671ffff (diff)
downloadgab-11483560ba54a5c9c87accb0048596889ef01f46.tar.gz
comenzamos
-rwxr-xr-xgab66
1 files changed, 66 insertions, 0 deletions
diff --git a/gab b/gab
new file mode 100755
index 0000000..5a0876d
--- /dev/null
+++ b/gab
@@ -0,0 +1,66 @@
+#!/usr/local/bin/bash
+# Gab es un cliente alternativo al programa de chat en colorfield.space
+# Reemplace la variable $file_path con la ruta a tu historial de chat
+# Se asume que cada línea de chat comienza con: "user_name >"
+# otros esquemas y formatos requerirán una modificación del script de awk
+# que se encuentra en las líneas 40 y 46
+# # # # # #->
+
+help_text=$'GAB - Una simple interfaz de chat\n\nsyntax: gab [bandera] [valor]\n\nbandera valor\n---------- ---------------\n-h, --help ninguno\n-m, --msg Mensaje entre comillas a enviar al chat\n-l, --log Un número entero con la cantidad de filas que quieres ver, por defecto 5'
+
+file_path=/var/gab/chatlog.txt
+title="GAB v1.0"
+last_date="Último mensaje: $(date -r $(stat -f %m $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 "Debe incluir un mensaje entre comillas dobles"
+ exit 1
+ else
+ msg=$(echo $2 | sed -e 's/\r$//g')
+ echo "$USER > $msg" >> $file_path
+ if [ $? -eq 0 ]
+ then
+ echo "Mensaje agregado exitosamente al chatlog"
+ exit 0
+ else
+ echo "Error agregando mensaje al 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 "Invalido: el valor debe ser entero"
+ exit 1
+ fi;;
+ -h | --help)
+ echo "$help_text"
+ exit 0;;
+ *)
+ echo "Unknown flag $1"
+ exit 1;;
+ esac
+fi
+
Un proyecto texto-plano.xyz