diff --git a/chat/chat b/chat/chat index d4f00dd..c6d1bf1 100755 --- a/chat/chat +++ b/chat/chat @@ -1,11 +1,17 @@ #!/bin/bash -path="/var/log/users" - -if [ "$1" = "root" ] || [ "$1" = "" ]; then -file=$(cat $HOME/.log/last.txt) -else -file=$(cat /home/$1/.log/last.txt) -fi - -tail -f $file +send() +{ + user=$(echo $1 | awk -F@ '{print $1}') + vm=$(echo $1 | awk -F@ '{print $2}') + echo "Send to ${user}@${vm}" + p2vm $vm exec 'echo -e "\\n'$c_white_bg$c_black$USER'@'$HOSTNAME$c_ $(date +%D\ %T)' '$c_cyan${@:2}$c_'" >> /home/'$user'/.chat' -sy +} +repl() +{ + read -re -p "chat> " mess + echo -e "$c_white_bg$c_black$USER@$HOSTNAME$c_ $(date +%D\ %T) $c_cyan$mess$c_" + send $1 $mess + repl $1 +} +[[ -z $2 ]] && repl $1 || send $@