This project is a fork of tabbed. (A name needs to be found tho). It enables terminal emulators like alacritty to follow the previous working directory when opening a new tab. For now, the only patched terminal to support this protocol is alacritty, see my fork : https://github.com/SCOTT-HAMILTON/alacritty
A nix shell is configured so that you can get this setup running in a few commands. This shell builds the tabbed fork and this alacritty fork.
- First install nix see https://nixos.org/guides/install-nix.html I higly recommand you to check out the above link but normally this command should be enough :
$ sh <(curl -L https://nixos.org/nix/install) --daemon
- Navigate to this repo
$ cd ~/path/to/where/you/cloned/my/tabbed/fork
- enter the nix shell :
$ nix-shell
- (in the nix shell) build the alacritty fork :
$ cargo build
- (still in the nix shell) run the tabbed alacritty :
$ tabbed -cr 2 -w "--xembed-tcp-port" ./target/debug/alacritty --embed ""
Bonus for hackers
6. (still in the nix shell) run the tabbed alacritty and put debug logs in a separate file :
$ tabbed -cr 2 -w "--xembed-tcp-port" ./target/debug/alacritty --embed "" 2>&1 | ./filter_output.pl 'debug-' debug_logs /dev/stdout 2>&1
When spawning a new alacritty window, tabbed also forks a child process that will communicate with this alacritty window through ZeroMQ Rep/Req sockets (Req->tabbed, Rep->the client, cf 0MQ API). A child is referred to as a client in tabbed
Each tabbed client is identified by an XID, which is the X11 Identifier of the alacritty window it's responsible of, (cf https://metacpan.org/pod/X11::Xlib#DESCRIPTION)
The tabbed client doesn't know its window's XID when spawned, it needs to ask for it.
The messages involved are :
XID?
and XID:138412034
Now that the client is authentified, in other words, now that it knows its associated window's XID, it can enter the following two state loops :
The PWD is the shell's working directory of the current focused window.
It changes each time the user executes a cd /somewhere/
command.
The message involved is : PWD:/home/user
When entering sleep mode, the tabbed client also sends a message informing the window that it should also enter the sleep mode, same goes to the turbo mode. These modes are critical for limiting CPU usage.
Since the user can change the working directory at anytime, the client has to ask for it constantly. And so it needs to transmit the flow of answers to the tabbed parent process. This is the key system that allows it to follow the working directories. Because the tabbed parent process always knows the PWD of the currently focused window's shell, it can spawn a new one at the good location.
The messages involved are : sleep
, turbo
and PWD?
Tabbed is released under the MIT/X Consortium License This few patches are released under the MIT License
References that helped
- qubes-os markdown conventions : https://www.qubes-os.org/doc/doc-guidelines/#markdown-conventions
- Linux man pages : https://linux.die.net/man/
- TcpStream rust doc : https://docs.rs/mio/0.5.1/mio/tcp/struct.TcpStream.html
- mermaid-js documentation : https://mermaid-js.github.io/mermaid/#/stateDiagram