2

In bash, when I type screen -x and press tab twice, I get a list of all the running sessions.

In zsh, when I type screen -ls and press tab twice, I get a list of all the running sessions and can tab through them, eventually select one when pressing enter, but this then executes screen -ls session-name when pressing enter again.

What I want in zsh is to get a behavior for -x similar to -ls, so that I don't have to type the session name or select the session and go back and change ls to x.

I can't find the code which implements the screen -ln tab-behavior in order to also implement it for -x, I've been searching/grepping through the list of .oh-my-zsh plugins but am getting nowhere.

Any help is appreciated, or maybe some workflow tips. I use screen a lot and most of it is via screen -x.

4
  • 1
    screen -xTAB in zsh should list the attached screen sessions, while screen -lsTAB should list all screen sessions whether they're attached or not. Jun 5, 2023 at 14:16
  • 1
    You can always do screen -x -S <Tab> to complete any screen session with -x, or modify a copy of the _screen file to change the behaviour. Jun 5, 2023 at 14:20
  • @StéphaneChazelas Thank you, very interesting the fact about that it lists already attached screens. I just checked and indeed that is the behavior. How can I change that?
    – Daniel F
    Jun 5, 2023 at 14:21
  • Also thanks for the screen -x -S <Tab> workaround, works just like what I'm after.
    – Daniel F
    Jun 5, 2023 at 14:23

1 Answer 1

3

The code is in _screen (completion is provided natively by zsh, it's not an additional plugin). Zsh completes all sessions for -ls but only attached sessions for -x.

-x is intended to “Attach to a not detached screen session” (per the manual). But it also works if the session is detached. So both behaviors make sense. Ideally, this should be a configuration option for zsh's completion.

To get the behavior you want instead of the current behavior, you need to change the line

  '-x[attach to a not detached screen (multi display mode)]: :->attached-sessions' \

to

  '-x[attach to a not detached screen (multi display mode)]: :->any-sessions' \

Here's some code you can put in your init file to monkey-patch the completion function to get the behavior you want. It needs to go after compinit (so after the oh-my-zsh lines if you use oh-my-zsh).

# Monkey-patch the screen completion function to complete all sessions
# after -x, not just detached sessions.
autoload +X _screen # load immediately
set -o extendedglob # needed for (#b) and # below and generally a good
                    # thing to have in interactive shells
functions[_screen]=${functions[_screen]/(#b)(\'-x[^:]#:[^:]#:->)attached-sessions(\')/${match[1]}any-sessions${match[2]}}
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .