From 92dda7f46d9149cd970f9210ba7acf638d306fe7 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?b=CA=B0edoh=E2=82=82=20sw=C3=A9?= Date: Sun, 12 Jan 2025 23:36:02 +0500 Subject: [PATCH] Allow changing nicknames + minor fixes. --- README.md | 6 ++++-- dobroho_vechora.bash | 15 +++++++++++---- 2 files changed, 15 insertions(+), 6 deletions(-) diff --git a/README.md b/README.md index 1bf000f..72a3674 100644 --- a/README.md +++ b/README.md @@ -17,7 +17,7 @@ Available commands: * I: Calls the editor (from VISUAL variable, if unset EDITOR is used. If both unset vi is used) and send the message if it is not empty. -* i: Send the next string from stdout +* i: Send the next string from stdout. * L: Ask the server for current chat buffer's length. @@ -29,9 +29,11 @@ Available commands: * q: Exit. -* e: Toggle encryption +* e: Toggle encryption. * E: Set encryption password. (Can also be set via "DOBROHO_VECHORA_ENCRYPTION_PASSWORD" environment variable.) +* n: Change nickname. + Client prints "?" on unknown commands. diff --git a/dobroho_vechora.bash b/dobroho_vechora.bash index 2dd1927..bcacd97 100755 --- a/dobroho_vechora.bash +++ b/dobroho_vechora.bash @@ -16,7 +16,10 @@ print_usage() { [ -z "${port}" ] && print_usage 'No port given.' [ -z "${5}" ] || print_usage 'Too many arguments.' -[ -z "${nick}" ] || nick="<${nick}> " +on_nick_set() { + [ -z "${nick}" ] || nick="<${nick}> " +} +on_nick_set open_socket() { exec 3<> "/dev/tcp/${ip}/${port}" @@ -115,7 +118,7 @@ wait_for_messages() { length=0 enc=0 while :; do - read cmd + read -r cmd case "${cmd}" in I) tmp="$(mktemp)" @@ -124,7 +127,7 @@ while :; do rm "${tmp}" ;; i) - read a + read -r a send_message 0"${nick}$(echo "${a}" | encrypt)" ;; L) @@ -151,7 +154,7 @@ while :; do exit ;; E) - read -s DOBROHO_VECHORA_ENCRYPTION_PASSWORD + read -r -s DOBROHO_VECHORA_ENCRYPTION_PASSWORD export DOBROHO_VECHORA_ENCRYPTION_PASSWORD ;; e) @@ -167,6 +170,10 @@ while :; do echo 0 fi ;; + n) + read -r nick + on_nick_set + ;; *) echo '?' ;;