pcw /

# 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 make sure you have a 256 color terminal, or edit
# accordingly


#exec urxvt -title "$CPATH" -e srw -l -p "$(basename "$CPATH")> " -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 part to cw etc. like the other examples

if ! tmux list-sessions | grep -q "^$TITLE"; then
	tmux new-session -d -s "$TITLE" -n "$(basename "$CPATH")" "srw -p \"$(basename "$CPATH")> \" -i \"$OUT\" -o \"$IN\" -n \"$NICK\""
elif ! tmux list-windows -t "$TITLE" | grep -q "$(basename "$CPATH")"; then
	tmux new-window -d -t "$TITLE" -n "$(basename "$CPATH")" "srw -p \"$(basename "$CPATH")> \" -i \"$OUT\" -o \"$IN\" -n \"$NICK\""

# 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")> " -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 it gzips the old out files everytime you startup
# again.  (This is the one I use, along with
# exec urxvt -title "$CPATH" -e srw -w -p "$(basename "$CPATH")> " -i "$OUT" -o "$IN" -n "$NICK"
# If you want to use 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 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
# "$CPATH" "$NICK"