blob: 5a0876d9ef7a4e04df23761cd48580a4946abf8b (
plain) (
blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
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
|