Skip to content

Commit

Permalink
use tabs instead of spaces
Browse files Browse the repository at this point in the history
  • Loading branch information
c00kiemon5ter committed Jan 11, 2013
1 parent e95a082 commit 11ea78d
Show file tree
Hide file tree
Showing 3 changed files with 163 additions and 149 deletions.
48 changes: 24 additions & 24 deletions connect.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@

# server info functions
freenode() {
server='irc.freenode.net'
channels="#foo #bar"
server='irc.freenode.net'
channels="#foo #bar"
}

oftc() {
server='irc.oftc.net'
channels="#xyz #abc"
server='irc.oftc.net'
channels="#xyz #abc"
}

# these match the functions above
Expand All @@ -22,31 +22,31 @@ chmod 700 "$ircdir"
chmod 600 "$ircdir"/*/ident &>/dev/null

for network in $networks; do
unset server channels port
"$network" # set the appropriate vars
unset server channels port
"$network" # set the appropriate vars

while true; do
# cleanup
rm -f "$ircdir/$server/in"
while true; do
# cleanup
rm -f "$ircdir/$server/in"

# connect to netwrok
# password is set through the env var synonym to the network name
iim -i "$ircdir" -n "$nick" -k "$network" -s "$server" -p "${port:-6667}" &
pid="$!"
# connect to netwrok
# password is set through the env var synonym to the network name
iim -i "$ircdir" -n "$nick" -k "$network" -s "$server" -p "${port:-6667}" &
pid="$!"

# wait for the connection
while ! test -p "$ircdir/$server/in"; do sleep .3; done
# wait for the connection
while ! test -p "$ircdir/$server/in"; do sleep .3; done

# auth to services
if [ -e "$ircdir/$server/ident" ]
then printf "/j nickserv identify %s\n" "$(cat "$ircdir/$server/ident")" > "$ircdir/$server/in"
fi && rm -f "$ircdir/$server/nickserv/out" # clean that up - ident passwd is in there
# auth to services
if [ -e "$ircdir/$server/ident" ]
then printf "/j nickserv identify %s\n" "$(cat "$ircdir/$server/ident")" > "$ircdir/$server/in"
fi && rm -f "$ircdir/$server/nickserv/out" # clean that up - ident passwd is in there

# join channels
printf "/j %s\n" $channels > "$ircdir/$server/in"
# join channels
printf "/j %s\n" $channels > "$ircdir/$server/in"

# if connection is lost reconnect
wait "$pid"
done &
# if connection is lost reconnect
wait "$pid"
done &
done

212 changes: 113 additions & 99 deletions iii.sh
Original file line number Diff line number Diff line change
Expand Up @@ -29,119 +29,133 @@ bar="------------------------------------------------------------" # trackbar
[ -e "$i/$n/$c/out" ] || { touch "$i/$n/$c/out" || exit 1; }

mark() {
tail -n1 "$i/$n/$c/out" | {
read -r date time nick mesg
[ "$mesg" != "$bar" ] && printf '%s -!- %.*s\n' "$(date +"%F %R")" "$f" "${bar}${bar}${bar}" >>"$i/$n/$c/out"
}
tail -n1 "$i/$n/$c/out" | {
read -r date time nick mesg
[ "$mesg" != "$bar" ] && printf '%s -!- %.*s\n' "$(date +"%F %R")" "$f" "${bar}${bar}${bar}" >>"$i/$n/$c/out"
}
}

trap "stty '$(stty -g)'; kill -TERM 0" EXIT
stty -echonl -echo

tail -f -n "$h" "$i/$n/$c/out" | while IFS= read -r mesg; do
date="${mesg%% *}" mesg="${mesg#* }"
time="${mesg%% *}" mesg="${mesg#* }"
nick="${mesg%% *}" mesg="${mesg#* }"
tail -f -n "$h" "$i/$n/$c/out" | while IFS= read -r mesg
do
date="${mesg%% *}" mesg="${mesg#* }"
time="${mesg%% *}" mesg="${mesg#* }"
nick="${mesg%% *}" mesg="${mesg#* }"

# strip '<nick>' to 'nick'
nick="${nick#<}" nick="${nick%>}"
# strip '<nick>' to 'nick'
nick="${nick#<}" nick="${nick%>}"

# do not notify of server messages
[ "$nick" != '-!-' ] && printf '\a'
# do not notify of server messages
[ "$nick" != '-!-' ] && printf '\a'

# highlight date if user was referenced in the message
case "$mesg" in *$u*) date="$(tput setaf $l)$date" ;; esac
# highlight date if user was referenced in the message
case "$mesg" in *$u*) date="$(tput setaf $l)$date" ;; esac

# pretify special symbols around words
# *bold* _underline_ /italics/ and underline urls
$r && mesg="$(echo "$mesg" | awk -vis="$(tput sitm; tput setaf 05)" -vie="$(tput ritm)${wht}" \
# pretify special symbols around words
# *bold* _underline_ /italics/ and underline urls
$r && mesg="$(echo "$mesg" | awk -vis="$(tput sitm; tput setaf 05)" -vie="$(tput ritm)${wht}" \
-vus="$(tput smul; tput setaf 03)" -vue="$(tput rmul)${wht}" \
-vbs="$(tput bold; tput setaf 01)" -vbe="$(tput sgr0)${wht}" \
-vls="$(tput smul; tput setaf 11)" -vle="$(tput rmul)${wht}" '
function replace(l, s, r) {
p = index(l, s) - 1
n = p + length(s) + 1
l = substr(l, 1, p) r substr(l, n)
return l
}
{
line = $0
for (i=1; i<=NF; i++)
if ($i ~ /^(http|ftp|ssh|www).+/) {
line = replace(line, $i, ls $i le)
} else if ($i ~ /^_[^_].*[^_]_$/) {
line = replace(line, $i, us substr($i, 2, length($i) - 2) ue)
} else if ($i ~ /^[*].*[*]$/) {
line = replace(line, $i, bs $i be)
} else if ($i ~ /^[/].*[/]$/) {
line = replace(line, $i, is $i ie)
}
print line
}
')"

# value between 1 and 14 - avoid black and white (though there's 7 and 8 in there)
# color value is based on the length and first and second letter of the nick
# you may want to uncomment and try another randomization function.
# -----
# those functions have been chosen based on the distribution of colors for
# the top 200 most messaged nicks on the channels I participate.
# as one goes down the list the distribution gets more and more unequal.
# ommited are functions that gave way too bad results (ie "%d & %d & %d").
# occurances of white (result:7) and black(result:8) have also been used as classification factors.
$r && clr="$(tput setaf $(( (( $(printf '%d ^ %d + %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d + %d + %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d * %d + %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d + %d ^ %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d ^ %d ^ %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d ^ %d * %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d * %d ^ %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d | %d * %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d & %d ^ %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"

# let server name have a static color across all randomization functions
$r && [ "$nick" == '-!-' ] && clr="$(tput setaf 14)"
case "$mesg" in ACTION*) mesg="$clr$nick$rst:${mesg#ACTION}" nick="*" clr="$grn" ;; esac

# fold lines breaking on spaces if message is greater than 'f' chars
echo "$mesg" | fold -s -w "$f" | \
while IFS= read -r line
do printf '\r%s %s %*.*s %s %s\n' "${blk}${date}" "${time}${clr}" "${m}" "${m}" "${nick}" "${blk}|${wht}" "${line}${rst}"
done
function replace(l, s, r) {
p = index(l, s) - 1
n = p + length(s) + 1
l = substr(l, 1, p) r substr(l, n)
return l
}
{
line = $0
for (i=1; i<=NF; i++)
if ($i ~ /^(http|ftp|ssh|www).+/) {
line = replace(line, $i, ls $i le)
} else if ($i ~ /^_[^_].*[^_]_$/) {
line = replace(line, $i, us substr($i, 2, length($i) - 2) ue)
} else if ($i ~ /^[*].*[*]$/) {
line = replace(line, $i, bs $i be)
} else if ($i ~ /^[/].*[/]$/) {
line = replace(line, $i, is $i ie)
}
print line
}
')"

# value between 1 and 14 - avoid black and white (though there's 7 and 8 in there)
# color value is based on the length and first and second letter of the nick
# you may want to uncomment and try another randomization function.
# -----
# those functions have been chosen based on the distribution of colors for
# the top 200 most messaged nicks on the channels I participate.
# as one goes down the list the distribution gets more and more unequal.
# ommited are functions that gave way too bad results (ie "%d & %d & %d").
# occurances of white (result:7) and black(result:8) have also been used as classification factors.
$r && clr="$(tput setaf $(( (( $(printf '%d ^ %d + %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d + %d + %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d * %d + %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d + %d ^ %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d ^ %d ^ %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d ^ %d * %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d * %d ^ %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d | %d * %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"
#$r && clr="$(tput setaf $(( (( $(printf '%d & %d ^ %d' "${#nick}" "'$nick" "'${nick#?}") ) % 14) + 1)))" || clr="$grn"

# let server name have a static color across all randomization functions
$r && [ "$nick" == '-!-' ] && clr="$(tput setaf 14)"
case "$mesg" in ACTION*) mesg="$clr$nick$rst:${mesg#ACTION}" nick="*" clr="$grn" ;; esac

# fold lines breaking on spaces if message is greater than 'f' chars
echo "$mesg" | fold -s -w "$f" | \
while IFS= read -r line
do printf '\r%s %s %*.*s %s %s\n' "${blk}${date}" "${time}${clr}" "${m}" "${m}" "${nick}" "${blk}|${wht}" "${line}${rst}"
done
done &

while IFS= read -r line; do
case "$line" in
'') continue
;;
:x) mark && break
;;
:q) break
;;
:m) mark
continue
;;
/wi" "*) line="/j nickserv info ${line#/wi}"
;;
/me" "*) line="ACTION${line#/me}"
;;
/names) line="/names $c"
;;
/op" "*) line="/j chanserv op $c ${line##* }"
;;
/deop" "*) line="/j chanserv deop $c ${line##* }"
;;
/bans) line="/j chanserv akick $c LIST"
;;
/ban" "*) line="/j chanserv akick $c ADD ${line##* } -- goodbye"
;;
/unban" "*) line="/j chanserv akick $c DEL ${line##* }"
;;
/t) line="/topic $c"
;;
esac
printf '%s\n' "$line"
case "$line" in
'')
continue
;;
:x)
mark && break
;;
:q)
break
;;
:m)
mark
continue
;;
/wi" "*)
line="/j nickserv info ${line#/wi}"
;;
/me" "*)
line="ACTION${line#/me}"
;;
/names)
line="/names $c"
;;
/op" "*)
line="/j chanserv op $c ${line##* }"
;;
/deop" "*)
line="/j chanserv deop $c ${line##* }"
;;
/bans)
line="/j chanserv akick $c LIST"
;;
/ban" "*)
line="/j chanserv akick $c ADD ${line##* } -- goodbye"
;;
/unban" "*)
line="/j chanserv akick $c DEL ${line##* }"
;;
/t)
line="/topic $c"
;;
esac
printf '%s\n' "$line"
done >"$i/$n/$c/in"

52 changes: 26 additions & 26 deletions notifiii.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,30 +11,30 @@ GREP_OPTIONS=""
trap 'kill -TERM -0' EXIT

inotifywait -m --exclude "/in$" --format "%w %f" -e modify -r "$i" | \
while read -r p f; do
# ignore notifications files other than 'out'
[ "$f" != "out" ] && continue
# ignore server messages
nickname="$(awk '{ n=$3 } END { print n }' "$p$f")"
[ "$nickname" = '<-!->' -o "$nickname" = '-!-' ] && continue

# break path down # p=/ircdir/network/channel/
p="${p#$i}" # p=/network/channel/
p="${p%/*}" # p=/network/channel
c="${p##*/}" # c=channel
p="${p%/*}" # p=/network
n="${p##*/}" # n=network
# if network is empty then action is on the network view
[ -z "$n" ] && n="$c" c=""

opts="h=50 i="$i" n="$n" c="$c""

## spawn a new tmux window named <channel> in a tmux session named IRC
env $opts tmiii.sh

# ## spawn a new urxvt terminal with IRC-<channel> class name
# if ! xwininfo -root -children | sed -n 's,^ \+\(0x[^ ]\+\).*("\([^"]*\)" "\([^"]*\)").*\+,"\1 \2 \3",p' | grep "${c:-$n} URxvt"
# then env $opts urxvtc -name "IRC-${c:-$n}" -e iii.sh
# fi
done
while read -r p f; do
# ignore notifications files other than 'out'
[ "$f" != "out" ] && continue
# ignore server messages
nickname="$(awk '{ n=$3 } END { print n }' "$p$f")"
[ "$nickname" = '<-!->' -o "$nickname" = '-!-' ] && continue

# break path down # p=/ircdir/network/channel/
p="${p#$i}" # p=/network/channel/
p="${p%/*}" # p=/network/channel
c="${p##*/}" # c=channel
p="${p%/*}" # p=/network
n="${p##*/}" # n=network
# if network is empty then action is on the network view
[ -z "$n" ] && n="$c" c=""

opts="h=50 i="$i" n="$n" c="$c""

## spawn a new tmux window named <channel> in a tmux session named IRC
env $opts tmiii.sh

# ## spawn a new urxvt terminal with IRC-<channel> class name
# if ! xwininfo -root -children | sed -n 's,^ \+\(0x[^ ]\+\).*("\([^"]*\)" "\([^"]*\)").*\+,"\1 \2 \3",p' | grep "${c:-$n} URxvt"
# then env $opts urxvtc -name "IRC-${c:-$n}" -e iii.sh
# fi
done

0 comments on commit 11ea78d

Please sign in to comment.