Anonymous avatar Anonymous committed 86b211e

update pcw_win.sh to deal with same channel on different server

Comments (0)

Files changed (1)

 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!
 TITLE="pcw"
 
 if ! tmux -L "$TITLE" list-sessions 2>/dev/null | grep -q "^$TITLE:"; then
-	tmux -L "$TITLE" new-session -d -s "$TITLE" -n "$(basename "$CPATH")" "srw -p \"$(basename "$CPATH")> \" cw_color.sh -i \"$OUT\" -o \"$IN\" -n \"$NICK\""
-elif ! tmux -L "$TITLE" list-windows -t "$TITLE" | grep -q " $(basename "$CPATH")[-*#!+~ ]"; then
-	tmux -L "$TITLE" new-window -d -t "$TITLE" -n "$(basename "$CPATH")" "srw -p \"$(basename "$CPATH")> \" cw_color.sh -i \"$OUT\" -o \"$IN\" -n \"$NICK\""
+	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
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.