dot

packages and services management
Log | Files | Refs | README

commit 0178186084a71dc3517e24140dfa616b9ed54215
parent 4607eeaa8b116abf5154c84f85b07325dd843e9e
Author: Josuah Demangeonā  ā µ <mail@josuah.net>
Date:   Tue, 21 Feb 2017 23:28:26 +0100

Updated irc

Diffstat:
M.profile | 3++-
Mbin/irc | 80++++++++++++++++++++++++++++++++++++-------------------------------------------
2 files changed, 38 insertions(+), 45 deletions(-)

diff --git a/.profile b/.profile @@ -18,10 +18,11 @@ export MAIL="$HOME/mail/INBOX" # default commands export EDITOR='vis' VISUAL="$EDITOR" FCEDIT="$EDITOR" +export PAGER='less' MANPAGER='less -R' # dvtm export DVTM_TERM='screen' -export DVTM_PAGER='iode +R' +export DVTM_PAGER='less -R' # xdg base directory export XDG_DATA_HOME="$HOME/.local/share" diff --git a/bin/irc b/bin/irc @@ -1,11 +1,5 @@ #!/bin/sh -# __ -# \/ _____ ____ -# /\ / ____\/ ___\ -# / // / / /__ -# \/ \/ \____\ 2016-09-18 -#=============================================================================== -# Irc client in 300 lines of shell script +# Irc client in less than 300 lines of shell script # # With help of http://xero.nu, inspired by http://tools.suckless.org/ii @@ -17,12 +11,8 @@ NL=' DIR="$HOME/.cache/irc" -# FUNCTIONS -#------------------------------------------------------------------------------- - -# # Write a message to a server -# + write() { local srv="$1" msg="$2" @@ -30,9 +20,9 @@ write() printf '\r%s\n' "$msg" >> "$srv/IN" } -# + # Start netcat, identify the client and user, and monitor the response. -# + connect() { local srv="$1" @@ -53,9 +43,9 @@ connect() write "$srv" "USER $user +i * :$FULLNAME" } -# + # Parse command from user input and print IRC messages. -# + input() { local srv chan arg user @@ -116,7 +106,7 @@ input() done } -# + # Maintain the connection open and print formatted message # # message = [ ":" prefix SPACE ] command [ params ] crlf @@ -132,7 +122,7 @@ input() # # SPACE = %x20 ; space character # crlf = %x0D %x0A ; "carriage return" "linefeed" -# + parse_message() { local srv="$1" @@ -210,9 +200,9 @@ parse_message() esac } -# + # Print formatted message -# + print_msg() { local nick="$1" trail="$2" cmd="$3" srv="$4" chan="$5" @@ -254,27 +244,29 @@ print_msg() } -# ALGORYTHM -#------------------------------------------------------------------------------- - -# Kill background jobs and delete named pipes while quitting - -# Prepare the irc log directory -[ -d "$DIR" ] || mkdir -p "$DIR" -cd "$DIR" -printf '%s\n' "$NICK" > "NICK" - -case "$1" in --i ) - trap 'find . -name IN -exec rm {} ";"; kill -9 0' INT EXIT - input - ;; --o ) - IFS="$NL" - less $(find . -mindepth 2 -type f ! -name NICK) - unset IFS - ;; -* ) - printf 'USAGE:\tirc [-i|-o]\n' - ;; -esac +main() +{ + # Kill background jobs and delete named pipes while quitting + + # Prepare the irc log directory + [ -d "$DIR" ] || mkdir -p "$DIR" + cd "$DIR" + printf '%s\n' "$NICK" > "NICK" + + case "$1" in + -i ) + trap 'find . -name IN -exec rm {} ";"; kill -9 0' INT EXIT + input + ;; + -o ) + IFS="$NL" + less $(find . -mindepth 2 -type f ! -name NICK) + unset IFS + ;; + * ) + printf 'USAGE:\tirc [-i|-o]\n' + ;; + esac +} + +main "$@"