tazirc rev 4
Add tazirc - SliTaz text mode IRC client
author | Christophe Lincoln <pankso@slitaz.org> |
---|---|
date | Tue Jan 14 21:39:39 2014 +0100 (2014-01-14) |
parents | 3b881ac93484 |
children | 3f7c06d80329 |
files | tazirc |
line diff
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/tazirc Tue Jan 14 21:39:39 2014 +0100 1.3 @@ -0,0 +1,110 @@ 1.4 +#!/bin/sh 1.5 +# 1.6 +# TazIRC - SliTaz IRC client: Keep it small! Maybe use a plugins system 1.7 +# We use a single temporary text file to send commands to the IRC server 1.8 +# and handle custom user commands such /q to quit. 1.9 +# 1.10 +# Copyright 2014 (C) SliTaz GNU/Linux - BSD License 1.11 +# Author: Christophe Lincoln <pankso@slitaz.org> 1.12 +# 1.13 +. /lib/libtaz.sh 1.14 + 1.15 +# Internationalization 1.16 +TEXTDOMAIN='tazirc' 1.17 +export TEXTDOMAIN 1.18 + 1.19 +if [ ! "$1" ] || [ ! "$2" ]; then 1.20 + cat << EOT 1.21 + 1.22 +$(boldify "$(gettext 'Usage:')") $(basename $0) [host] [nick] [--option]" 1.23 + 1.24 +$(boldify "$(gettext 'Options:')") 1.25 + --chan= $(gettext "Join specified channel after connection") 1.26 + --mode= $(gettext "Use specified mode. Default: +i") 1.27 + --port= $(gettext "Use specified port. Default: 6667") 1.28 + 1.29 +EOT 1.30 + exit 0 1.31 +fi 1.32 + 1.33 +# Cmdline --options= are parsed by libtaz.sh 1.34 +[ "$mode" ] || mode="+i" 1.35 +[ "$port" ] || port="6667" 1.36 +host="$1" && nick="$2" 1.37 +send="/tmp/tazirc/${host}.${nick}.$$.txt" 1.38 + 1.39 +# Clean up on exit 1.40 +trap "echo 'Exiting...' && rm -f $send" SIGINT INT TERM 1.41 +trap "kill 0" EXIT 1.42 +mkdir -p $(dirname $send) 1.43 + 1.44 +# 1.45 +# Functions 1.46 +# 1.47 + 1.48 +# Error message: error "Message blabla..." 1.49 +error() { 1.50 + echo "$(colorize 31 'ERROR:') $1" 1.51 +} 1.52 + 1.53 +# 1.54 +# Start: send login commands to connect to server then handle commands 1.55 +# 1.56 + 1.57 +# Introduce me! 1.58 +clear 1.59 +colorize 30 "TazIRC - SliTaz IRC Client" 1.60 +boldify "$(gettext 'Connecting to:') $host $([ $chan ] && echo \#${chan})" 1.61 +cat > ${send} << EOT 1.62 +NICK $nick 1.63 +USER $nick $mode * :$0 1.64 +EOT 1.65 +[ "$chan" ] && echo "JOIN #${chan}" >> ${send} 1.66 + 1.67 +# Connect and handle server messages 1.68 +(tail -f ${send} | busybox nc ${host} ${port} | while read MESSAGE 1.69 +do 1.70 + debug "$MESSAGE" 1.71 + case "$MESSAGE" in 1.72 + *" PRIVMSG "*) 1.73 + # Display channel messages 1.74 + user=$(echo "${MESSAGE%!*}" | sed s'/://') 1.75 + text=$(echo "${MESSAGE#* :}") 1.76 + echo "[$(date -u '+%R')] $(colorize 35 "$user"): $text" ;; 1.77 + *" MODE "*) 1.78 + echo "${MESSAGE#* }" ;; 1.79 + PING*) 1.80 + # Responding to ping 1.81 + echo "PONG${MESSAGE#PING}" >> ${send} ;; 1.82 + *) 1.83 + echo "${MESSAGE#* :}" ;; 1.84 + esac 1.85 +done) & 1.86 + 1.87 +# Handle user input commands/messages 1.88 +while read COMMAND 1.89 +do 1.90 + # tazirc> prompt ? 1.91 + # while true: echo -en "$(colorize 33 "tazirc")> "; read COMMAND 1.92 + case "$COMMAND" in 1.93 + "") continue ;; 1.94 + /JOIN*|/join*|/j*) 1.95 + chan="$(echo ${COMMAND} | cut -d '#' -f 2)" 1.96 + boldify "$(gettext 'Joining:') #$chan" 1.97 + echo "JOIN #$chan" >> ${send} ;; 1.98 + /QUIT|/quit|/q) 1.99 + boldify "$(gettext 'Diconnecting from:') $host" 1.100 + echo "QUIT" >> ${send} 1.101 + sleep 1 && rm -f ${send} && break ;; 1.102 + /*) 1.103 + echo "${COMMAND#/}" >> ${send} ;; 1.104 + *) 1.105 + if [ ! "$chan" ]; then 1.106 + error "$(gettext 'No channel to send to')" && continue 1.107 + fi 1.108 + echo "[$(date -u '+%R')] $(colorize 34 "$nick"): ${COMMAND}" 1.109 + echo "PRIVMSG #$chan :${COMMAND}" >> ${send} ;; 1.110 + esac 1.111 +done 1.112 + 1.113 +exit 0