Source

pcw / pcw_win.sh

Full commit
Evan Gates d58275d 













Evan Gates dcb07c3 


Evan Gates d58275d 
Evan Gates 99b91d9 




Evan Gates dcb07c3 
Evan Gates 86b211e 



















Evan Gates dcb07c3 




Evan Gates a7e8606 
Evan Gates dcb07c3 
Evan Gates 830aeff 
Evan Gates 86b211e 


Evan Gates dcb07c3 
Evan Gates 4f8a3fb 
Evan Gates d58275d 

Evan Gates dcb07c3 
Evan Gates d58275d 

Evan Gates dcb07c3 

Evan Gates 4f8a3fb 
Evan Gates dcb07c3 






Evan Gates d58275d 




Evan Gates dcb07c3 
Evan Gates d58275d 

Evan Gates fcb92b5 
Evan Gates d58275d 
#!/bin/sh
#
# This is the script run by pcw when you join a new channel or a new message
# comes in.  CPATH is the path to the directory, OUT and IN are the out file
# in fifo respectively, and NICK is the nick passed to pcw or the empty string
# if no nick was passed in.
#
# These are just a few examples, and I trust that you can figure out how to do
# other stuff.  Of note, pcw decides when to run the command based on the
# status of the last command it ran for a given 'path'.  If the child is still
# alive it will not run the command again (helpful for open terminals).  This
# does mean however that some ideas won't work out of the box, for instance
# using urxvtc or screen.  You should be able to keep track of some stuff here
# in order to decide whether or not to launch a new window, have fun!
#
# NOTE: if you use cw_color.sh make sure you have a 256 color terminal, or edit
#       cw_color.sh accordingly

CPATH="$1"
OUT="$2"
IN="$3"
NICK="$4"


# possible labels for channels (ran into trouble with same channel name on
# multiple servers e.g. nickserv)
#
# /path/to/prefix/irc.server.net/#channel -> #channel
#CHAN="$(basename "$CPATH")"
#
# /path/to/prefix/irc.server.net/#channel -> irc.server.net/#channel
#CHAN="$(basename "$(dirname "$CPATH")")/$(basename "$CPATH")"
#
# /path/to/prefix/irc.server.net/#channel -> i.s.n/#channel
#CHAN="$(basename "$(dirname "$CPATH")" | sed 's/\([^.]\)[^.]*\(\.\|$\)/\1\2/g')/$(basename "$CPATH")"
#
# /path/to/prefix/irc.server.net/#channel -> server/#channel
CHAN="$(basename "$(dirname "$CPATH")")"
while [ "${CHAN#*.}" != "$CHAN" -o "${CHAN%.*}" != "$CHAN" ]; do
	CHAN="${CHAN%.*}"
	CHAN="${CHAN#*.}"
done
CHAN="${CHAN:+$CHAN/}$(basename "$CPATH")"

#exec urxvt -title "$CPATH" -e srw -l -p "$(basename "$CPATH")> " cw_color.sh -i "$OUT" -o "$IN" -n "$NICK"

# Open a new tmux window for each channel, this one has been requested for a while, and now it works!
# make sure to add 'set -g default-terminal "screen-256color"' to your ~/.tmux.conf
# if you don't want color, you can change the cw_color.sh part to cw etc. like the other examples
TITLE="pcw"

if ! tmux -L "$TITLE" list-sessions 2>/dev/null | grep -q "^$TITLE:"; then
	tmux -L "$TITLE" new-session -d -s "$TITLE" -n "$CHAN" "srw -p \"$CHAN> \" cw_color.sh -i \"$OUT\" -o \"$IN\" -n \"$NICK\""
elif ! tmux -L "$TITLE" list-windows -t "$TITLE" | grep -q " $CHAN[-*#!+~ ]"; then
	tmux -L "$TITLE" new-window -d -t "$TITLE" -n "$CHAN" "srw -p \"$CHAN> \" cw_color.sh -i \"$OUT\" -o \"$IN\" -n \"$NICK\""
fi

# The default command
# exec urxvt -title "$CPATH" -e srw -p "$(basename "$CPATH")> " cw "$OUT" "$IN"

# If for some reason you really don't want to use srw...
# exec urxvt -title "$CPATH" -e cw "$OUT" "$IN"

# For colors, bell on nick, better line wrapping etc. (this is what i use)
# exec urxvt -title "$CPATH" -e srw -p "$(basename "$CPATH")> " cw_color.sh -i "$OUT" -o "$IN" -n "$NICK"

# And to add reflowing text when the window changes size.  Although beware, in
# this case reflow means reprint the whole file at the new width.  This can be
# slow, but if you use chat.sh it gzips the old out files everytime you startup
# again.  (This is the one I use, along with chat.sh)
# exec urxvt -title "$CPATH" -e srw -w -p "$(basename "$CPATH")> " cw_color.sh -i "$OUT" -o "$IN" -n "$NICK"
 
# If you want to use tabbed (http://tools.suckless.org/tabbed) so each new
# channel has it's own tab.  Start tabbed with -d then export the window id as
# pcw_window_id (or whatever you want...) then start pcw.  It should be fairly
# simple to do that in a script, use cw_color.sh if you want the colors etc.
# exec urxvt -embed "$pcw_window_id" -title "$CPATH", -e srw -p "$(basename "$CPATH")> " cw "$OUT" "$IN"

# If you want notifications in dzen, then click on a specific message to spawn
# a terminal for that channel.
# NOTE: alpha quality at best, more of a proof of concept, but have fun with it
# pcw_notify.sh "$CPATH" "$NICK"