Environment of a Session
The command of a Session gets the environment of the daemon, with a few changes that nomux makes. The holder makes them.
This matters when a service manager starts the daemon: launchd gives a job PATH=/usr/bin:/bin:/usr/sbin:/sbin and no TERM and no LANG, and a systemd user service has no TERM.
The output on this page is the real output of nomux 0.5.0 on Linux. The home directory of the runs is shown as /home/user.
What the command gets
Section titled “What the command gets”| Source | Variables |
|---|---|
| The daemon | Each variable of the environment of the daemon, except the ones in the next rows. |
| nomux, always | TERM=xterm-256color, COLORTERM=truecolor, NOMUX_SESSION_ID, NOMUX_SOCK and NOMUX_TOKEN. A value of the daemon is replaced. |
| nomux, if the daemon has no locale | LC_CTYPE=C.UTF-8 on Linux and LC_CTYPE=UTF-8 on macOS: a character set of UTF-8. Only if LC_ALL, LC_CTYPE and LANG have no value. |
| Never passed | COLUMNS, LINES, TERM_PROGRAM and TERM_PROGRAM_VERSION. They describe the terminal of the program that started the daemon. |
The three variables of nomux:
| Variable | Value |
|---|---|
NOMUX_SESSION_ID |
The session identifier. |
NOMUX_SOCK |
The socket of the daemon. |
NOMUX_TOKEN |
A random token of 128 bits, new at each start of the holder. |
A program in the Session uses them to say which Session it is in, for example nomux status set (Agent status) and nomux hook (Agent adapters and hooks).
The token proves that a request comes from a process of the Session. The processes of the Session inherit it. A process of the same user outside the Session can read the environment of a process of the Session, thus the token is not a defence against it. No log, no journal and no file of nomux has the token. A restore gives the Session a new token.
An example
Section titled “An example”Here the daemon started with a small environment, as a service manager gives it: TERM=screen, COLUMNS=120, LINES=40 and TERM_PROGRAM=demo, and no locale. The shell variable small holds that environment. The command of the Session printed its environment. The value of the token is replaced with <hidden> in the command.
$ small="env -i HOME=$HOME PATH=$HOME/.local/bin:/usr/bin:/bin TERM=screen COLUMNS=120 LINES=40 TERM_PROGRAM=demo"$ cd ~/project$ $small nomux lsno sessions$ $small nomux new --cmd sh -c 'env | sort | sed "s/^NOMUX_TOKEN=.*/NOMUX_TOKEN=<hidden>/"; sleep 3600'd4r34zip$ nomux capture d4r34zipCOLORTERM=truecolorHOME=/home/userLC_CTYPE=C.UTF-8NOMUX_SESSION_ID=d4r34zipNOMUX_SOCK=/home/user/.nomux/run/nomuxd.sockNOMUX_TOKEN=<hidden>PATH=/home/user/.local/bin:/usr/bin:/binPWD=/home/user/projectSHLVL=1TERM=xterm-256color_=/usr/bin/envTERM=screenof the daemon becamexterm-256color.COLUMNS,LINESandTERM_PROGRAMare gone.- The daemon had no locale, thus the Session got
LC_CTYPE=C.UTF-8.
A daemon that has a locale keeps it. Here the daemon started with LANG=tr_TR.UTF-8 and the same small environment:
$ $small nomux new --cmd sh -c 'env | sort | grep -E "^(LANG|LC_|TERM|COLORTERM)"; sleep 3600'gak3ck3g$ nomux capture gak3ck3gCOLORTERM=truecolorLANG=tr_TR.UTF-8TERM=xterm-256colornomux adds no LC_CTYPE then. (In that run, small was env -i HOME=$HOME PATH=$HOME/.local/bin:/usr/bin:/bin LANG=tr_TR.UTF-8, and the daemon was new.)
Why TERM is not the terminal of your client
Section titled “Why TERM is not the terminal of your client”The terminal of a Session is the terminal of nomux, which follows xterm. A Session has clients with different terminals at different times. So TERM is always xterm-256color, and COLORTERM is always truecolor.
What does not pass from the client
Section titled “What does not pass from the client”The environment of the terminal that runs nomux new does not go to the Session. The control protocol has no field for it. If the daemon started from your terminal, it has the environment of that terminal at that time, and the Session gets it. The next client with another environment does not change it.
Thus a client with a different locale, or with variables like SSH_AUTH_SOCK or DISPLAY, does not give them to its Session. Issue #75 is open for this gap.
Give Sessions a language
Section titled “Give Sessions a language”A daemon of a service manager can have no locale. Then the C library uses the locale C, which has no characters outside ASCII. The fallback of nomux gives a UTF-8 character set. It does not give a language, a format of dates or a format of numbers.
To give each Session a language, give LANG to the service:
- Linux:
Environment=in the unit thatnomux daemon install-servicewrote (~/.config/systemd/user/nomuxd.service), for exampleEnvironment=LANG=en_US.UTF-8. - macOS:
EnvironmentVariablesin the launchd agent (~/Library/LaunchAgents/sh.nomux.nomuxd.plist).
The Linux and macOS lines come from the documents of nomux. They were not run for this page.
Restore and the pool
Section titled “Restore and the pool”- A restore starts the command again with the environment of the daemon at the time of the restore, with the same rules.
- A shell from the holder pool gets the same environment, because no part comes from the client. The pooled shell changes to the directory of the Session before its first prompt, so
PWDis the directory of the Session. The holder pool page says how. - A Session on a remote Host has the environment of the daemon of that Host.