Expand a leading ~, and say what the failing command said
Three things, two of which are the same failure seen from opposite ends. **A working directory of `~/repos/ai-app` never worked.** Everything crossing to the remote side is single-quoted, which is right for paths, model names and prompts alike -- unquoted they would be shell syntax rather than data. It is wrong for exactly one character: `~` means "expand me", and quoting is what stops expansion. So the remote shell was handed the literal four-character directory `~` and correctly said it did not exist, which reads as the path being wrong rather than the quoting. Paths now go through `quote_path`, which emits `"$HOME"` for a leading `~/` and single-quotes the rest. The variable expands, the expansion is not re-split or globbed because it is double-quoted, and nothing after it gains a meaning -- there is a test that pushes a quote-and-semicolon injection through the tilde branch and gets back one absurd path rather than three commands. `$HOME` is set by every shell this can land in, so this does not depend on the remote side being POSIX; verified by running the generated script under both sh and fish, which is what the dev VM actually uses. **The phone could not have told you any of that.** The exit report kept the last line of stderr, and a shell's error message ends with a blank line -- so the last line was empty, the report was a bare exit status, and the seven lines of fish complaining sat in the server's log where nobody holding a phone is looking. It now keeps the last 50 lines in a ring and reports them with blank lines trimmed from both ends. The tests use the real fish `cd` failure as their fixture. **The status bar was unreadable.** `isAppearanceLightStatusBars` was hardcoded to `true` -- dark icons -- which was right against the default light surface and wrong the moment the app wore Mocha. It now asks the scheme's own background for its luminance, so changing the palette cannot reintroduce it. **And the address field takes `user@host:port`.** One field rather than two, because that is how an address is written everywhere else and a port that is nearly always 22 does not deserve its own box on a phone keyboard. Absent means absent rather than 22: the backend already decides that default, and writing it here would be a second answer in a second place. A colon only means "port" when it can -- brackets for IPv6 as ssh writes them, otherwise exactly one colon followed by digits. Looked at on the emulator: the status bar, and the form, whose label I then shortened because it wrapped onto a second line and made that field taller than the two beside it.
This commit is contained in:
1 parent
31135e3f22
commit
2a1bc84c1e
4 files changed
+202
-26
No files matched your search
@@ -237,7 +237,6 @@ private fun AddSetupDialog(
|
||||
val scope = rememberCoroutineScope()
|
||||
var name by remember { mutableStateOf("") }
|
||||
var address by remember { mutableStateOf("") }
|
||||
var port by remember { mutableStateOf("") }
|
||||
var identity by remember { mutableStateOf("") }
|
||||
var tested by remember { mutableStateOf<String?>(null) }
|
||||
var testing by remember { mutableStateOf(false) }
|
||||
@@ -246,10 +245,11 @@ private fun AddSetupDialog(
|
||||
address
|
||||
.trim()
|
||||
.takeIf { it.isNotEmpty() }
|
||||
?.let {
|
||||
?.let { typed ->
|
||||
val (host, typedPort) = splitHostAndPort(typed)
|
||||
SshDetails(
|
||||
address = it,
|
||||
port = port.trim().toIntOrNull(),
|
||||
address = host,
|
||||
port = typedPort,
|
||||
identityFile = identity.trim().ifEmpty { null },
|
||||
)
|
||||
}
|
||||
@@ -275,13 +275,10 @@ private fun AddSetupDialog(
|
||||
OutlinedTextField(
|
||||
value = address,
|
||||
onValueChange = { address = it },
|
||||
label = { Text("user@host (blank = this machine)") },
|
||||
singleLine = true,
|
||||
)
|
||||
OutlinedTextField(
|
||||
value = port,
|
||||
onValueChange = { port = it },
|
||||
label = { Text("Port (blank = 22)") },
|
||||
// Just the shape. What a blank one means is said once, in the text above
|
||||
// this form -- repeating it here wrapped the label onto a second line and
|
||||
// made this field taller than the two beside it for no information.
|
||||
label = { Text("user@host[:port]") },
|
||||
singleLine = true,
|
||||
)
|
||||
OutlinedTextField(
|
||||
@@ -367,3 +364,33 @@ private fun RenameDialog(setup: Setup, onDismiss: () -> Unit, onRename: (String)
|
||||
dismissButton = { TextButton(onClick = onDismiss) { Text("Cancel") } },
|
||||
)
|
||||
}
|
||||
|
||||
/**
|
||||
* Splits `user@host:port` into its two halves, with the port left null when none was typed.
|
||||
*
|
||||
* One field rather than two because that is how an address is written and read everywhere else --
|
||||
* and because a port that is almost always 22 does not deserve a box of its own on a phone
|
||||
* keyboard. Null rather than 22: the backend already decides the default, and writing 22 here would
|
||||
* put a second answer to that question in a second place.
|
||||
*
|
||||
* A colon only means "port" when it can. A bracketed IPv6 literal is unwrapped as ssh writes it,
|
||||
* `[::1]:22`; a bare `::1` keeps every colon, because an address with several is an address, not an
|
||||
* address and a port. So the rule is: brackets, or exactly one colon followed by digits.
|
||||
*/
|
||||
private fun splitHostAndPort(typed: String): Pair<String, Int?> {
|
||||
if (typed.startsWith("[")) {
|
||||
val close = typed.indexOf(']')
|
||||
if (close > 0) {
|
||||
val host = typed.substring(1, close)
|
||||
val rest = typed.substring(close + 1)
|
||||
val port = rest.removePrefix(":").toIntOrNull().takeIf { rest.startsWith(":") }
|
||||
return host to port
|
||||
}
|
||||
}
|
||||
if (typed.count { it == ':' } == 1) {
|
||||
val host = typed.substringBeforeLast(':')
|
||||
val port = typed.substringAfterLast(':').toIntOrNull()
|
||||
if (port != null && host.isNotEmpty()) return host to port
|
||||
}
|
||||
return typed to null
|
||||
}
|
||||
Reference in new issue
Block a user