membrane-term

lread 2021-12-07T21:39:30.188400Z

Ok, I thought I understood shell launching with dash, but I do not understand yet. Will have to look at alacritty, contour, kitty terminal code more closely. On my macOS they all:

$ echo $0
-zsh

lread 2021-12-07T21:39:53.188700Z

How’d that - prefix get there?

lread 2021-12-07T21:42:44.190700Z

I am probably getting confused with argv[0] is that I thought that was the first arg to the shell, but it is the shell itself? I should go study the code more.

phronmophobic 2021-12-07T21:43:28.191300Z

yes, argv[0] is the program itself

phronmophobic 2021-12-07T21:43:42.191800Z

the first arg is actually argv[1]

phronmophobic 2021-12-07T21:43:46.192100Z

I think this comes from c

lread 2021-12-07T21:43:57.192300Z

Right… my C is very rusty.

phronmophobic 2021-12-07T21:44:11.192600Z

rust probably does it too, right?

lread 2021-12-07T21:44:37.193Z

My Rust is non-existent.

2
phronmophobic 2021-12-07T21:45:06.193600Z

same

lread 2021-12-07T21:45:29.194Z

So can you invoke a shell in this way from the terminal?

lread 2021-12-07T21:47:07.194800Z

Hmm… learning about execexec -l bash

phronmophobic 2021-12-07T21:47:10.195Z

I don't think so. I think it's when you use execvp or equivalent

phronmophobic 2021-12-07T21:47:17.195200Z

yea

phronmophobic 2021-12-07T21:48:02.195800Z

although, when you're already inside a terminal, I think most of the stuff that the login would provide is already setup

lread 2021-12-07T21:48:41.196300Z

yeah, true, just trying to understand the mechanics…

phronmophobic 2021-12-07T21:49:36.197100Z

I think it's more of an issue if you start the process outside of a terminal, for example: https://github.com/alacritty/alacritty/issues/645#issuecomment-313363581

lread 2021-12-07T21:51:11.198600Z

So the leading dash is merely an indicator? If I exec an abitrary command like this, no harm?

phronmophobic 2021-12-07T21:52:33.198900Z

depends on the arbitrary command, right?

lread 2021-12-07T21:57:23.200700Z

Well, we are introducing :command so anything, the user specifies really. (I clearly don’t understand the mechanics of this dash prefix yet).

lread 2021-12-07T21:58:58.201900Z

Nor how to express with pty4j yet, but can explore.

phronmophobic 2021-12-07T21:59:31.202500Z

so interestingly, execvp allows you to specify argv separately from the executable path. many apis don't allow you to execute something with a different argv[0] since it's pretty rare

phronmophobic 2021-12-07T21:59:44.202800Z

trying to see if pty4j allows this

phronmophobic 2021-12-07T22:03:31.204400Z

so, it seems like it's possible, but it seems like the API we're currently using doesn't allow it. We might need to use a lower level API if we want to support this https://github.com/JetBrains/pty4j/blob/dd6ad8fdbae5c4c407ba165dd7f3c32dea68ecbc/src/com/pty4j/unix/UnixPtyProcess.java ie. don't use PtyProcessBuilder on Mac, https://github.com/JetBrains/pty4j/blob/dd6ad8fdbae5c4c407ba165dd7f3c32dea68ecbc/src/com/pty4j/PtyProcessBuilder.java#L132

lread 2021-12-07T22:06:19.205700Z

An easier (for us) alternative would be to use -l or --login.

lread 2021-12-07T22:06:59.206500Z

But this loses the leading - on the $0 which some folks might expect. (I assume that’s why the leading dash is preferred?)

phronmophobic 2021-12-07T22:07:51.207100Z

as far as I can tell, it seems like they should theoretically do the same thing

phronmophobic 2021-12-07T22:08:40.207900Z

I was suggesting that the leading - is preferred to avoid any incidental differences

phronmophobic 2021-12-07T22:09:55.208900Z

I guess it's also a way to avoid trying to decide if we should or shouldn't append --login depending on the value of $SHELL if we do use that as a fallback default

lread 2021-12-07T22:13:19.211600Z

Yeah, this way, the user controls the :command and we don’t tack anything on. On macOS we would default to <$SHELL val> --login else /bin/bash --login . But if those defaults do not work for the user, they can specify what they like via :command.

lread 2021-12-07T22:15:03.212500Z

But other terminals seem to be doing the - prefix. So not conforming to that, is a negative.

phronmophobic 2021-12-07T22:16:36.214100Z

so we currently call PtyProcess/exec , which is just a simple wrapper around https://github.com/JetBrains/pty4j/blob/dd6ad8fdbae5c4c407ba165dd7f3c32dea68ecbc/src/com/pty4j/unix/UnixPtyProcess.java#L283. On macOS, we could just call PtyHelpers/execPty directly.

lread 2021-12-07T22:25:27.217Z

Yeah… https://github.com/JetBrains/pty4j/blob/dd6ad8fdbae5c4c407ba165dd7f3c32dea68ecbc/src/com/pty4j/unix/PtyHelpers.java#L383? Probably worth exploring. But if the user specifies a non-shell thingy for :command do we still prefix with -? For example let’s say they want to run top , would it be harmful override argv[0] with -top?

👍 1
phronmophobic 2021-12-07T22:26:45.218Z

I think that's why this hack exists. most programs don't actually care what it's in argv[0]

phronmophobic 2021-12-07T22:28:03.218900Z

so it should be fine to prefix it for any command

lread 2021-12-07T22:28:24.219300Z

I suppose if it does, by some odd chance, become a problem, we could address.

lread 2021-12-07T22:29:18.220300Z

Without understanding nor appreciating the history (and perhaps cleverness?) of this dash prefix it seems rather icky to me.

phronmophobic 2021-12-07T22:29:37.220800Z

I think it would also be ok to only prefix for default and default fallbacks

lread 2021-12-07T22:30:44.222Z

But if I want to run a different shell via :command ?

phronmophobic 2021-12-07T22:31:09.222400Z

then you should be able to also supply the --login arg if that's what you want

phronmophobic 2021-12-07T22:34:30.225300Z

here's the story I have in my head. for whatever reason, macOS decides all your terminal config should be in .bash_profile , which only is run as part of a login shell. this works mostly fine, but the user's shell is stored in the /etc/passwd db, which only supplies a single argument for the shell. the hack/workaround is this stupid - convention

lread 2021-12-07T22:34:37.225500Z

Sure, that’s an alternative too. Maybe seems a bit odd that we can only support the dash prefix with the defaults.

phronmophobic 2021-12-07T22:35:55.227Z

sure, I don't have a strong opinion as to whether to prefix all commands with - or just the defaults

lread 2021-12-07T22:36:15.227600Z

But introducing a :dash-prefix-command boolean option for macOS only seems a bit odd too maybe?

phronmophobic 2021-12-07T22:36:51.228400Z

the case for not requiring it for defaults is that, presumably, the user that specifies commands knows the shell and its arguments whereas we don't actually know the shell and its args if we use $SHELL as a fallback

lread 2021-12-07T22:39:34.230200Z

I wonder how many other folks working on terminals have had this same conversation? simple_smile With a few expletives towards Apple in the mix.

🤣 1
phronmophobic 2021-12-07T22:40:06.230800Z

the whole idea of emulating the vt100 decades later is kind of comical on its own 😛

lread 2021-12-07T22:40:30.231400Z

Yeah! Very true!

phronmophobic 2021-12-07T22:40:56.231800Z

not only do we emulate it, it's a critically piece of infrastructure to a large percentage of modern programming work!

phronmophobic 2021-12-07T22:41:36.232600Z

I don't think :dash-prefix-command is necessary, but I'm not totally sure that it wouldn't be useful for someone. my usual approach would be to not include it, but create an issue that someone could comment or upvote if they have a use case for it.

phronmophobic 2021-12-07T22:42:02.233300Z

however, I'm pretty open to whatever you think is best

lread 2021-12-07T22:43:30.234600Z

How about… we start with… <flips coin>… adding the dash prefix to all argv[0]s (default or not) on macOS? I think I should summarize this convo in the issue tho. Will do that.

👍 1
🎉 1