dot

packages and services management
Log | Files | Refs | README

commit 9e5a146c7b4e51abb4cb5239a0951c025827793b
parent 8397da27026147bef789fadf618eda595dbe0f53
Author: sshbio <jd@ssh.bio>
Date:   Sun, 14 Aug 2016 01:01:14 +0200

irc: Added support for paragraphs (empty line separator)

Diffstat:
Mbin/irc | 26++++++++++++++++++--------
1 file changed, 18 insertions(+), 8 deletions(-)

diff --git a/bin/irc b/bin/irc @@ -3,7 +3,7 @@ # \/ _____ ____ # /\ / ____\/ ___\ # / // / / /__ -# \/ \/ \____\ - Irc client in 210 lines of shell script +# \/ \/ \____\ - Irc client in 222 lines of shell script #=============================================================================== NICK="${NICK-$USER}" @@ -66,8 +66,7 @@ input() M | MSG | PRIVMSG ) arg="${arg%% *} :${arg#* }" write "$srv" "PRIVMSG $arg" - printf '%s' ":$user!localhost PRIVMSG $arg" \ - | output "$srv" + printf '%s' ":$user!local PRIVMSG $arg" | output "$srv" ;; J | JOIN ) chan="$arg" @@ -113,13 +112,13 @@ input() # output() { - local srv="$1" user="$(tail "$DIR/NICK")" + local srv="$1" user="$(tail "$DIR/NICK")" cmd params middle chan last while read msg do # Parse server message - local prefix='' nick='' trail='' cmd params middle chan + local prefix='' nick='' trail='' sep='' msg="${msg#$CR}" msg="${msg%$CR}" if [ -z "${msg##:*}" ] @@ -140,14 +139,23 @@ output() # Execute action + # Check if the last command was the + if [ ! "$(printf %s "$last" | grep -F "$chan $cmd $nick")" ] + then sep='yes' + fi + case "$cmd" in PING ) write "$srv" "PONG $params" ;; * ) - print_msg "$nick" "$trail" "$cmd" >> "$DIR/$srv/$chan" + print_msg "$nick" "$trail" "$cmd" "$sep" \ + >> "$DIR/$srv/$chan" ;; esac + + last="$(printf '%s %s %s\n' "$chan $cmd $nick" + printf '%s\n' "$last" | grep -vF "$chan")" done } @@ -156,7 +164,7 @@ output() # print_msg() { - local nick="$1" trail="$2" cmd="$3" user="$(tail "$DIR/NICK")" + local nick="$1" trail="$2" cmd="$3" sep="$4" user="$(tail "$DIR/NICK")" case "$cmd" in QUIT ) cmd='<' ;; @@ -171,6 +179,8 @@ print_msg() ;; esac + [ "$sep" ] && printf "%${NICK_LEN}s |\n" + # Print the message printf '%s\n' "$trail" | fold -s -w $((78 - $NICK_LEN - ${#cmd})) \ | while read line @@ -194,9 +204,9 @@ printf '%s\n' "$NICK" > "$DIR/NICK" if [ "$(ps ax -o args | grep -F "$DIR/IN" | wc -l)" -le 1 ] then # Start interactive session - printf '> ' "$DIR" 1>&2 [ -p "$DIR/IN" ] || mkfifo "$DIR/IN" tail -f "$DIR/IN" | input & + printf '> ' 1>&2 while read cmd do printf '> ' 1>&2