about summary refs log tree commit diff stats
path: root/src/config
diff options
context:
space:
mode:
Diffstat (limited to 'src/config')
-rw-r--r--src/config/chapath.nim5
-rw-r--r--src/config/config.nim14
2 files changed, 18 insertions, 1 deletions
diff --git a/src/config/chapath.nim b/src/config/chapath.nim
index caaf9435..8f1ff539 100644
--- a/src/config/chapath.nim
+++ b/src/config/chapath.nim
@@ -9,6 +9,8 @@ import js/tojs
 import types/opt
 import utils/twtstr
 
+const libexecPath {.strdefine.} = "${%CHA_BIN_DIR}/../libexec/chawan"
+
 type ChaPath* = distinct string
 
 func `$`*(p: ChaPath): string =
@@ -34,6 +36,7 @@ type
 
   ChaPathResult[T] = Result[T, ChaPathError]
 
+proc unquote*(p: ChaPath): ChaPathResult[string]
 proc unquote(p: string, starti: var int, terminal: Option[char]):
     ChaPathResult[string]
 
@@ -181,6 +184,8 @@ proc stateCurlyPerc(ctx: var UnquoteContext, c: char): ChaPathResult[void] =
   if c == '}':
     if ctx.identStr == "CHA_BIN_DIR":
       ctx.s &= getAppFileName().beforeLast('/')
+    elif ctx.identStr == "CHA_LIBEXEC_DIR":
+      ctx.s &= ?ChaPath(libexecPath).unquote()
     else:
       return err("Unknown internal variable " & ctx.identStr)
     ctx.identStr = ""
diff --git a/src/config/config.nim b/src/config/config.nim
index 1274e731..ae4a8f85 100644
--- a/src/config/config.nim
+++ b/src/config/config.nim
@@ -350,7 +350,14 @@ proc readUserStylesheet(dir, file: string): string =
 # of several individual configuration files known as mailcap files.
 proc getMailcap*(config: Config): tuple[mailcap: Mailcap, errs: seq[string]] =
   let configDir = getConfigDir() / "chawan" #TODO store this in config?
-  var mailcap: Mailcap
+  const gopherPath0 = ChaPath("${%CHA_LIBEXEC_DIR}/gopher2html -u %u")
+  let gopherPath = gopherPath0.unquote().get
+  var mailcap = @[MailcapEntry(
+    mt: "text",
+    subt: "gopher",
+    cmd: gopherPath,
+    flags: {HTMLOUTPUT}
+  )]
   var errs: seq[string]
   var found = false
   for p in config.external.mailcap:
@@ -363,6 +370,11 @@ proc getMailcap*(config: Config): tuple[mailcap: Mailcap, errs: seq[string]] =
         errs.add(res.error)
       found = true
   if not found:
+    mailcap.insert(MailcapEntry(
+      mt: "*",
+      subt: "*",
+      cmd: "xdg-open '%s'"
+    ), 0)
     return (DefaultMailcap, errs)
   return (mailcap, errs)