commit 1349e4b

Hubert Hirtz  ·  2020-08-20 11:34:22 +0000 UTC
parent 9a9a00d
Change %c to %b and add %h
2 files changed,  +16, -10
M app.go
M app.go
+13, -7
 1@@ -135,7 +135,7 @@ func (app *App) handleIRCEvent(ev irc.Event) {
 2 			app.win.AddLine(ui.Home, l)
 3 			app.win.TypingStop(ui.Home, ev.Nick)
 4 			app.lastQuery = ev.Nick
 5-			app.notifyHighlight("", ev.Nick, ev.Content)
 6+			app.notifyHighlight(ui.Home, ev.Nick, ev.Content)
 7 		} else if ev.Command == "NOTICE" {
 8 			l := ui.LineFromIRCMessage(ev.Time, ev.Nick, ev.Content, true, false)
 9 			app.win.AddLine("", l)
10@@ -266,16 +266,22 @@ func (app *App) isHighlight(nick, content string) bool {
11 	return false
12 }
13 
14-func (app *App) notifyHighlight(context, nick, content string) {
15+func (app *App) notifyHighlight(buffer, nick, content string) {
16 	sh, err := exec.LookPath("sh")
17 	if err != nil {
18 		return
19 	}
20-	command := app.cfg.OnHighlight
21-	command = strings.Replace(command, "%%", "%", -1)
22-	command = strings.Replace(command, "%c", context, -1)
23-	command = strings.Replace(command, "%n", nick, -1)
24-	command = strings.Replace(command, "%m", cleanMessage(content), -1)
25+	here := "0"
26+	if buffer == app.win.CurrentBuffer() {
27+		here = "1"
28+	}
29+	r := strings.NewReplacer(
30+		"%%", "%",
31+		"%b", buffer,
32+		"%h", here,
33+		"%n", nick,
34+		"%m", cleanMessage(content))
35+	command := r.Replace(app.cfg.OnHighlight)
36 	exec.Command(sh, "-c", command).Run()
37 }
38 
+3, -3
 1@@ -44,8 +44,8 @@ Some settings are required, the others are optional.
 2 :< *Description*
 3 |  %%
 4 :  literal %
 5-|  %c
 6-:  message context (channel name if available, otherwise empty)
 7+|  %b
 8+:  buffer where the message appeared
 9 |  %m
10 :  content of the message
11 |  %n
12@@ -77,7 +77,7 @@ password: A secure password, I guess?
13 highlights:
14 	- guest
15 	- senpai
16-on-highlight: 'notify-send "[%c] %n" "%m"'
17+on-highlight: 'if [ %h -eq 0 ]; then notify-send "[%b] %n" "%m"; fi'
18 nick-column-width: 12
19 ```
20