How to start zellij on every shell login like tmux #1721
-
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 3 replies
-
Hi, @breathiness! You can load a simple script with this command |
Beta Was this translation helpful? Give feedback.
-
This leads to infinite recursion if
I am trying to fix this in my shell (nushell). So far, I've come up with the following. This fixes case 1, but does not fix case 2 though. # List all the IP addresses of the machine
export def ip-list []: nothing -> table<ver: string, interface_addr: string> {
ip a
| split row (char newline)
| each { str trim }
| where ($it | str starts-with "inet")
| split column --collapse-empty --regex '\s+' ver interface_addr
}
# Attach zellij if the session is SSH
export def ssh-attach-zellij [] {
let x = (zellij list-sessions)
print $x
if ("ZELLIJ" in $env) {
# Don't nest zellij sessions
return
}
# Don't attach zellij in vscode integrated terminal
let blacklisted_binaries = ["code", "code-insiders"]
for binary in $blacklisted_binaries {
if ((which $binary | length) > 0) {
return
}
}
# If env does not have "SSH_CONNECTION", don't attach zellij
if ($env.SSH_CLIENT? | is-empty) {
return
}
# If ssh client is localhost, don't attach zellij
let ssh_client = ($env.SSH_CLIENT | split column --collapse-empty --regex
'\s+' src_ip src_port dst_port | first)
let src_ip = $ssh_client.src_ip
let localhost_ips = ["::1", "localhost", "127.0.0.1"]
if ($src_ip in $localhost_ips) {
print "SSH-ing from localhost, not attaching zellij"
return
}
if ((which ip | length) > 0) {
let ip_addresses = (
ip-list
| reduce -f [] {|it, acc| $acc | append ($it.interface_addr | split row "/" | first)}
)
if ($src_ip in $ip_addresses) {
print "SSH-ing from Local IP address, not attaching zellij"
return
}
}
# If env has "ZELLIJ_SSH_PANE_NAME", use that name to attach zellij
zellij attach -c ($env.ZELLIJ_SSH_PANE_NAME | default "ssh_zellij")
} |
Beta Was this translation helpful? Give feedback.
Hi, @breathiness!
You can load a simple script with this command
zellij setup --generate-auto-start <SHELL>
.Also, I hope this document will help you.