aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorbptato <nincsnevem662@gmail.com>2024-11-12 21:20:55 +0100
committerbptato <nincsnevem662@gmail.com>2024-11-12 21:44:44 +0100
commitb16d3454ea16d87b84607e8330ca3c3b0ac0a8f7 (patch)
treef0de97854c29c72088fb69268c20041cedf7005f
parentfe23b27b2880590424584c13662a7ec5d0721d16 (diff)
downloadchawan-b16d3454ea16d87b84607e8330ca3c3b0ac0a8f7.tar.gz
config.toml: respect TMPDIR
also, fix a bug in the chapath parser so that param expansion actually works
-rw-r--r--doc/cha.14
-rw-r--r--res/config.toml6
-rw-r--r--src/config/chapath.nim16
-rw-r--r--todo1
4 files changed, 17 insertions, 10 deletions
diff --git a/doc/cha.1 b/doc/cha.1
index 2813dcc5..435482b2 100644
--- a/doc/cha.1
+++ b/doc/cha.1
@@ -105,6 +105,10 @@ named \fI\-o\fR, you can open it using \fIcha \fB--\fR \fI-o\fR.
Certain environment variables are read and used by Chawan.
.TP
+\fBTMPDIR\fR
+When set, the default configuration stores temporary files and IPC
+sockets inside this directory (and \fI/tmp\fR otherwise.)
+.TP
\fBHTTP_HOME\fR, \fBWWW_HOME\fR
When set, Chawan starts in visual mode by default and opens the page specified
by one of these variables. (\fBHTTP_HOME\fR takes precedence over
diff --git a/res/config.toml b/res/config.toml
index 9fa79079..b44b716f 100644
--- a/res/config.toml
+++ b/res/config.toml
@@ -266,11 +266,11 @@ urimethodmap = [
"/etc/urimethodmap",
"/usr/local/etc/w3m/urimethodmap"
]
-tmpdir = "/tmp/cha-tmp-$LOGNAME"
-sockdir = "/tmp/cha-sock-$LOGNAME"
+tmpdir = "${TMPDIR:-/tmp}/cha-tmp-$LOGNAME"
+sockdir = "${TMPDIR:-/tmp}/cha-sock-$LOGNAME"
editor = "${EDITOR:-vi}"
cgi-dir = ["$CHA_CONFIG_DIR/cgi-bin", "$CHA_LIBEXEC_DIR/cgi-bin"]
-download-dir = "/tmp/"
+download-dir = "${TMPDIR:-/tmp}/"
w3m-cgi-compat = false
[network]
diff --git a/src/config/chapath.nim b/src/config/chapath.nim
index 9878e09b..e6a2a84c 100644
--- a/src/config/chapath.nim
+++ b/src/config/chapath.nim
@@ -28,7 +28,7 @@ type
UnquoteState = enum
usNormal, usTilde, usDollar, usIdent, usBslash, usCurlyStart, usCurly,
- usCurlyHash, usCurlyPerc, usCurlyColon, usCurlyExpand, usDone
+ usCurlyHash, usCurlyPerc, usCurlyColon, usCurlyExpand
ChaPathError = string
@@ -38,7 +38,7 @@ proc unquote*(p: ChaPath): ChaPathResult[string]
proc unquote(p: string; starti: var int; terminal: Option[char]):
ChaPathResult[string]
-proc stateNormal(ctx: var UnquoteContext; c: char) =
+proc stateNormal(ctx: var UnquoteContext; c: char): bool =
case c
of '$': ctx.state = usDollar
of '\\': ctx.state = usBslash
@@ -48,9 +48,10 @@ proc stateNormal(ctx: var UnquoteContext; c: char) =
else:
ctx.s &= c
elif ctx.terminal.isSome and ctx.terminal.get == c:
- ctx.state = usDone
+ return false
else:
ctx.s &= c
+ return true
proc flushTilde(ctx: var UnquoteContext) =
if ctx.identStr == "":
@@ -136,6 +137,7 @@ proc stateCurly(ctx: var UnquoteContext; c: char): ChaPathResult[void] =
case c
of '}':
ctx.s &= $getEnv(ctx.identStr)
+ ctx.identStr = ""
ctx.state = usNormal
return ok()
of '$': # allow $ as first char only
@@ -233,6 +235,7 @@ proc flushCurlyExpand(ctx: var UnquoteContext; word: string):
ctx.s &= word
else: assert false
ctx.subChar = '\0'
+ ctx.identStr = ""
ctx.hasColon = false
ctx.state = usNormal
return ok()
@@ -249,7 +252,9 @@ proc unquote(p: string; starti: var int; terminal: Option[char]):
while ctx.i < p.len:
let c = p[ctx.i]
case ctx.state
- of usNormal: ctx.stateNormal(c)
+ of usNormal:
+ if not ctx.stateNormal(c):
+ break
of usTilde: ctx.stateTilde(c)
of usBslash: ctx.stateBSlash(c)
of usDollar: ?ctx.stateDollar(c)
@@ -260,10 +265,9 @@ proc unquote(p: string; starti: var int; terminal: Option[char]):
of usCurlyPerc: ?ctx.stateCurlyPerc(c)
of usCurlyColon: ?ctx.stateCurlyColon(c)
of usCurlyExpand: ?ctx.stateCurlyExpand(c)
- of usDone: break
inc ctx.i
case ctx.state
- of usNormal, usDone: discard
+ of usNormal: discard
of usTilde: ctx.flushTilde()
of usBslash: ctx.s &= '\\'
of usDollar: ctx.s &= '$'
diff --git a/todo b/todo
index 439b6cc4..3585d5cf 100644
--- a/todo
+++ b/todo
@@ -11,7 +11,6 @@ display:
- dark mode (basically max Y)
- override bgcolor ourselves when terminal fails to report it
config:
-- important: fix crash on missing /tmp dir with default config
- important: config editor
- switch from table arrays to tables
- better siteconf URL matching