dot

packages and services management
Log | Files | Refs | README

commit 8397da27026147bef789fadf618eda595dbe0f53
parent 1917c93fb033b611071e865daf57678065bd3c58
Author: sshbio <jd@ssh.bio>
Date:   Sun, 14 Aug 2016 00:19:28 +0200

irc: Finished the interface.

Diffstat:
Mbin/irc | 42+++++++++++++++++++++++++++---------------
1 file changed, 27 insertions(+), 15 deletions(-)

diff --git a/bin/irc b/bin/irc @@ -3,7 +3,7 @@ # \/ _____ ____ # /\ / ____\/ ___\ # / // / / /__ -# \/ \/ \____\ - http://tools.suckless.org/ii, forked from http://xero.nu +# \/ \/ \____\ - Irc client in 210 lines of shell script #=============================================================================== NICK="${NICK-$USER}" @@ -59,7 +59,9 @@ input() case "$cmd" in C | CONNECT | S | SERVER ) srv="$arg" - connect "$srv" & + if [ -z "$(ps ax -o args | grep "^nc $srv 6667")" ] + then connect "$srv" & + fi ;; M | MSG | PRIVMSG ) arg="${arg%% *} :${arg#* }" @@ -78,6 +80,10 @@ input() TOPIC | LIST ) write "$srv" "TOPIC ${arg-chan}" ;; + ID | IDENTIFY ) + write "$srv" "PRIVMSG NickServ :IDENTIFY $arg" + printf '\033[A\r\033[K> /IDENTIFY *****\v\r> ' + ;; '' ) write "$srv" "PRIVMSG $chan $arg" ;; @@ -105,7 +111,6 @@ input() # SPACE = %x20 ; space character # crlf = %x0D %x0A ; "carriage return" "linefeed" # -# output() { local srv="$1" user="$(tail "$DIR/NICK")" @@ -166,9 +171,6 @@ print_msg() ;; esac - # One line separator - printf "%${NICK_LEN}s |\n" - # Print the message printf '%s\n' "$trail" | fold -s -w $((78 - $NICK_LEN - ${#cmd})) \ | while read line @@ -189,12 +191,22 @@ trap 'find "$DIR" -type p -exec rm {} ";"; kill -9 0' INT EXIT [ -d "$DIR" ] || mkdir -p "$DIR" printf '%s\n' "$NICK" > "$DIR/NICK" -# Start interactive session -printf '> ' "$DIR" 1>&2 -[ -p "$DIR/IN" ] || mkfifo "$DIR/IN" -tail -f "$DIR/IN" | input & -while read cmd -do - printf '\033[A\r\033[K> ' 1>&2 - printf '%s\n' "$cmd" >> "$DIR/IN" -done +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 & + while read cmd + do + printf '> ' 1>&2 + printf '%s\n' "$cmd" >> "$DIR/IN" + done +else + IFS="$NL" + for file in $(find "$DIR" -mindepth 2 -type f) + do files="$files $file" + done + unset IFS + less -R $files +fi