Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

zellij attach opens on top of current session #3411

Open
sonofviking opened this issue Jun 9, 2024 · 1 comment
Open

zellij attach opens on top of current session #3411

sonofviking opened this issue Jun 9, 2024 · 1 comment

Comments

@sonofviking
Copy link

Issue description

I am trying to write a script that opens zellij inside of a certain project, setting the name of the session to that project (folder). Whenever I try to run zellij attach inside of another zellij session, it opens that attached within the session instead of replacing it.

To go back to the original session I'd have to kill the attached session as attaching to the original would glitch out zellij

Minimal reproduction

zellij attach --create-background "session-to-attach" # Create a session in the background
zellij -s "current" # open a named zellij session

# From within 'current'
zellij attach session-to-attach

This is what should happen to the status-bar (I have the compact-bar configured).

image

To show what happens when trying to reattach to the 'current' session.

zellij attach current

Note that this is the entire vertical of my monitor, rendering the zellij session useless.

image

Other relevant information

zellij version: 0.40.1

The session I was trying to write (akin to ThePrimeagen's sessionizer script)

#!/usr/bin/env bash

if [[ $# -eq 1 ]]; then
    selected=$1
else
    selected=$(find ~/Projects $XDG_CONFIG_HOME ~/.local/bin -mindepth 1 -maxdepth 1 -type d | fzf)
fi

if [[ -z $selected ]]; then
    exit 0
fi

selected_name=$(basename "$selected" | tr . _)
zellij_running=$(pgrep zellij)

if [[ -z $ZELLIJ ]] && [[ -z $zellij_running ]]; then
    echo "name: $selected_name, selected: $selected"
    zellij attach $selected_name --create options --default-cwd $selected
    exit 0
fi

is_already_session=$(zellij list-sessions --short --no-formatting | rg $selected_name)
current_session=$(zellij list-sessions -n | rg "(current)" | sed 's/\s.*//')

if [[  $current_session == $selected_name ]]; then
    exit 0
fi

if [[ -z $is_already_session ]]; then
    zellij attach --create-background $selected_name options --default-cwd $selected
fi

#zellij -s $selected_name run -- zellij kill-session $current_session

# Attach does not seem to work the way i'd expect it to, should probably open issue on zellij github about this
zellij attach $selected_name
@Peeeaje
Copy link

Peeeaje commented Jun 21, 2024

Zellij doesn't have and doesn't aim to implement switching commands so you need to implement such plugin.
(I remember the maintainer said it is the role of plugin system)

I wrote that for my own. (sessionizer too btw)
https://github.com/Peeeaje/zellij-switch-session

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants