wezterm icon indicating copy to clipboard operation
wezterm copied to clipboard

Add support for title stack via control sequence

Open codemedic opened this issue 1 year ago • 8 comments

Is your feature request related to a problem? Please describe. I noticed that the pane title set by SSH (openssh cli) on Linux does not get reset / reverted when the SSH session finishes.

As a workaround I tried adding a wrapper script that does the below.

  1. Save the title on stack
  2. run SSH command with given args, allowing SSH to set whatever title it wants
  3. When SSH command exits, the last thing the script does is to restore the title from stack.

Details can be found here. https://stackoverflow.com/a/20048874

#!/bin/sh
/bin/echo -ne '\033[22;0t'  # Save title on stack
ssh "$@"
/bin/echo -ne '\033[23;0t'  # Restore title from stack

The control sequence does not make any difference. I suspect they are not currently supported.

Describe the solution you'd like I would like to see title stacks supported in WezTerm; my favourite terminal app.

Describe alternatives you've considered I have considered using wezterm cli to do the same, but AFAIK there is no way to get the current title of the current pane.

Additional context None

codemedic avatar Jul 11 '24 13:07 codemedic

@wez Is there a workaround for this using the CLI?

codemedic avatar Jul 23 '24 22:07 codemedic

Did you try wezterm cli list? It can also output in json.

wez avatar Jul 23 '24 23:07 wez

Thanks, @wez. I didn't know that before. Let me see if I can formulate a workaround.

It would be nice if WezTerm would support the save and restore approach with the escape sequence.

codemedic avatar Jul 25 '24 19:07 codemedic

Hi @wez, I tried but no luck.

ssh() {
  local saved_title=$(wezterm cli list --format json | q -r ".[] | select(.pane_id==$WEZTERM_PANE) | .title")
  command ssh "$@"
  wezterm cli set-tab-title "$saved_title"
}

Saving the current pane title does work. wezterm cli set-tab-title is being invoked with the saved value but tab-title does not seem to change.

The command wezterm cli list --format json | jq -r ".[] | select(.pane_id==$WEZTERM_PANE)" gives the below output.

{
  "window_id": 1,
  "tab_id": 10,
  "pane_id": 16,
  "workspace": "default",
  "size": {
    "rows": 65,
    "cols": 319,
    "pixel_width": 2552,
    "pixel_height": 1365,
    "dpi": 96
  },
  "title": "user@host-abc:~",                // <-- not changed; set from SSH session
  "cwd": "file://host-local/home/user/",
  "cursor_x": 0,
  "cursor_y": 18,
  "cursor_shape": "Default",
  "cursor_visibility": "Visible",
  "left_col": 0,
  "top_row": 0,
  "tab_title": "bash",                       // <-- set by the attemp to restore title
  "window_title": "user@host-abc:~",
  "is_active": true,
  "is_zoomed": false,
  "tty_name": "/dev/pts/6"
}

codemedic avatar Jul 26 '24 00:07 codemedic

Sorry @wez there was an error in the script I posted .. copy paste error.

The error still.persists; just to be clear.

codemedic avatar Jul 26 '24 19:07 codemedic

@wez When you get a chance, can you please review my comments and script above to see if a workaround can be made. Thanks

codemedic avatar Jul 30 '24 13:07 codemedic

Sorry, but I have no time or interest in figuring out a workaround. I may consider implementing the stack feature in the future, but as of right now, I'm not spending any more time here.

wez avatar Jul 31 '24 14:07 wez

Is it at all possible to add a cli command for set-panel-title?

codemedic avatar Aug 06 '24 11:08 codemedic

I found a solution to this in a similar iterm2 issue. I added precmd () {print -Pn "\e]0;%~\a"}; to my .zshrc so that the shell sets the title to my cwd. You may have to play with the escape sequences to get the title you desire.

wryfi avatar Oct 29 '24 18:10 wryfi