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

Faster way or conveniences for attaching to session by name #1169

Closed
colemickens opened this issue Mar 4, 2022 · 2 comments
Closed

Faster way or conveniences for attaching to session by name #1169

colemickens opened this issue Mar 4, 2022 · 2 comments
Labels
enhancement New feature or request

Comments

@colemickens
Copy link

Hi,

It looks like clap does not yet support runtime-provided completion support (clap-rs/clap#1232), hence I'm not sure there's an easy path to providing completion for session names.

However, attaching to a session implies that someone is loading the entire zellij UI interactive inactively anyway.

What if zellij attach or zellij attach -m offered an interactive menu for the user to select a session?

Alternatively, would it be possible to allow zellij attach f to match a session named foobar-awesome, assuming there are no other sessions starting with f ?

I guess one last no-zellij-change-needed option would be to setup some sort of shell keybind so that I could pipe zellij list-sessions into skim or something? Does someone else have something they like for this?

@a-kenji
Copy link
Contributor

a-kenji commented Mar 4, 2022

Hey! Thank you for taking the time for opening this issue.

hence I'm not sure there's an easy path to providing completion for session names.

There is sadly not, but we could append functions to the completions.
The negative here would be that this is very shell dependent, but it could be reasonable to support the shells as good as we can.
There is an issue that has a great example: #1030

What if zellij attach or zellij attach -m offered an interactive menu for the user to select a session?

That would be awesome, I think connecting to your last point, maybe we could even support fzf/skim and family choosers similarly.
That way the maintenance burden would be not as high with still full functionality.

Alternatively, would it be possible to allow zellij attach f to match a session named foobar-awesome, assuming there are no other sessions starting with f ?

So, that is another possibly good idea. Just for the first letter, and maybe restrict the possibility of automatically generating the same first letter, in order to make this functionality more useful.

I guess one last no-zellij-change-needed option would be to setup some sort of shell keybind so that I could pipe zellij list-sessions into skim or something? Does someone else have something they like for this?

In my window manager I have bound something similar to this
(I have removed some very specific integration I use):

#!/usr/bin/env bash

ZJ_SESSIONS=$(zellij list-sessions)
NO_SESSIONS=$(echo "${ZJ_SESSIONS}" | wc -l)
TERMINAL=alacritty

if [ "${NO_SESSIONS}" -ge 2 ]; then
    "${TERMINAL}" -e zellij attach \
    "$(echo "${ZJ_SESSIONS}" | rofi -dmenu -l "${NO_SESSIONS}")"
else
   "${TERMINAL}" -e zellij attach -c
fi

But you can also remove the terminal and use it from an already
existing terminal:

#!/usr/bin/env bash

ZJ_SESSIONS=$(zellij list-sessions)
NO_SESSION=$(echo "${ZJ_SESSIONS}" | wc -l)

zellij attach 1>/dev/null || \
    zellij attach \
    "$(echo "${ZJ_SESSIONS}" | rofi -dmenu -l "${NO_SESSION}")"

and switch it with skim:

#!/usr/bin/env bash
ZJ_SESSIONS=$(zellij list-sessions)
NO_SESSIONS=$(echo "${ZJ_SESSIONS}" | wc -l)

if [ "${NO_SESSIONS}" -ge 2 ]; then
    zellij attach \
    "$(echo "${ZJ_SESSIONS}" | sk)"
else
   zellij attach -c
fi

@a-kenji a-kenji added the enhancement New feature or request label Mar 4, 2022
raphCode added a commit that referenced this issue Apr 28, 2022
This make attaching to sessions more convenient since only the first character(s) of the
session name must be typed.
If this prefix matches multiple sessions and is therefore ambiguous, zellij will complain
and show all sessions names starting with these characters.
If any session name matches the given string exact, it is attached immediately, therefore
it is always possible to attach to every session, even if the set of session names is not
prefix-free.
raphCode added a commit that referenced this issue Apr 28, 2022
This make attaching to sessions more convenient since only the first character(s) of the
session name must be typed.
If this prefix matches multiple sessions and is therefore ambiguous, zellij will complain
and show all sessions names starting with these characters.
If any session name matches the given string exact, it is attached immediately, therefore
it is always possible to attach to every session, even if the set of session names is not
prefix-free.
raphCode added a commit that referenced this issue May 3, 2022
* feat: Attach sessions by unique name prefix (#1169)

This makes attaching to sessions more convenient since only the first character(s) of the
session name must be typed.
If this prefix matches multiple sessions and is therefore ambiguous, zellij will complain
and show all sessions names starting with these characters.
If any session name matches the given string exact, it is attached immediately, therefore
it is always possible to attach to every session, even if the set of session names is not
prefix-free.

* Add feature to changelog

* Try to fix flaky e2e test
@a-kenji
Copy link
Contributor

a-kenji commented Jun 15, 2022

This is now implemented!

@a-kenji a-kenji closed this as completed Jun 15, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants