How do I display the current "session" name or "sockname" of a screen session in the status bar? - gnu-screen

I run multiple screen sessions each created with 'screen -S name' and I would like to be able to display in the status bar the name I used to create the current screen session.
However, I cannot seem to accomplish this. Any ideas?

The easiest way to display the sessionname is
C-a :
sessionname
(without specifying a name after sessionname)
See the "CUSTOMIZATION" section in man screen

screen has two status bars, the caption bar and the hardstatus bar, both of which use the string escapes specified in the "STRING ESCAPES" section of man screen. Unfortunately, there is no escape that directly refers to the session name.
However, there is a hack that will allow you to do this.
screen passes the session name to the shell using the $STY variable. When the shell attempt to set the window title (using one of these methods) screen captures that attempt, and stores it in something it confusingly calls "the window hardstatus," which does have an escape that you can use: %h.
So if you have either the caption or hardstatus bar set to include %h and have the shell attempt to set the window title to $STY, then the %h will be replaced with the session name when the bar is displayed.

In current versions of screen, there is a flag %S for the hardstatus line.
MWE (.screenrc):
hardstatus on
hardstatus alwayslastline
hardstatus string "%S"
This displays the session name without the ID (like ${STY#*.}).
(Same answer to other questions here and here for completeness).

paraphrased from https://superuser.com/a/212520/151988, put this into your ~/.screenrc;
screen
screen $SHELL -c 'screen -X caption always "$STY"'

Super User has an answer to this that does not require $STY, instead using the backtick screen config command and screen -ls: https://superuser.com/a/212520

If nothing else works (as for me), as a workaround you can create a window with number 0 and set title to your screen name:
screen -S myscreen
C^a :title "myscreen"

As max_cantor says in the SuperUser Answer, an escape character for the session name should be added to version 4.1.0. It looks like the escape character function was added with a relatively small patch back in 2008. So if you're feeling brave, you can git yourself a copy of the development version 4.1.0 and try it out.
I'll try this with the development version when I get a chance.

"screen -X sessionname"
i'm using ssh,i thought this is a straight answer ,
sessionname will show at the screen bottom

Related

zsh completion: Disable ssh username completion

I am using the completion scripts that ship with ZSH (5.7.1) and I would like to turn off the autocompletion for usernames, but keep the completion for hostnames.
How can I do this?
Currently, there's an erroneous user that I can't figure out why it's being included (not in ~/.ssh/config, any identities, /etc/ssh, or any other location) and I figure it's probably easier to just disable username completion.
Example output is below; I want to remove the entire "login name" section rather than try and hunt down where unwanted-username is coming from.
$ ssh <tab>
-- login name --
unwanted-username
-- host --
example-host-1 example-host-1
I expect there is a zstyle command which can disable it, but I'm not sure the correct incantation. I expect this is the relevant configuration that needs to be changed:
$ zstyle | grep completion | grep ssh
:completion:*:ssh:* users hosts-domain hosts-host users hosts-ipaddr
However, I can't seem to get the correct incantation to remove the login name section.
To disable completion of login names, in that context, try:
zstyle ':completion:*:ssh:argument-1:*' tag-order hosts
or to merely hide them, try:
zstyle ':completion:*:ssh:*:users' hidden true
Pressing Ctrl-X h instead of tab is a good way to determine the relevant tags and context strings.
Seems odd that you have an erroneous user being completed. Check for a users-hosts style being set, possibly without mention of ssh in the context. The ignored-patterns style could be another way to deal with an erroneous match in the general case, for example:
zstyle ':completion:*:ssh:*:users' ignored-patterns erroneous-username
As you might discern from the name of the style, the last argument here can be a shell pattern with *, ? etc.

Change Integrated Terminal title in vscode

We can open command prompt in vscode by using the Integrated Terminal feature in View menu.
We can even open multiple terminals as shown below:
Is there any way I can change the title of the terminal ?
1: cmd.exe will be build terminal
2: cmd.exe will be watch terminal
I have gone through the integrated terminal documentation but I didn't find a way to do that.
Press in windows Ctrl + Shift + P and after type: Terminal: Rename, there you can change the terminal name/title
In v1.61 there is the ability to set the terminal names using variables. See terminal custom titles in release notes.
Terminal names are traditonally the name of the process they're
associated with. Thus, it can be difficult to distinguish between
them.
We now support configuring both title and description to help with
this using variables described in terminal.integrated.tabs.title and
terminal.integrated.tabs.description settings.
The current default values are:
{
"terminal.integrated.tabs.title": "${process}",
"terminal.integrated.tabs.description": "${task}${separator}${local}${separator}${cwdFolder}"
}
Variables available are:
${cwd} - The terminal's current working directory
${cwdFolder} - The terminal's current working directory.
${workspaceFolder} - The workspace in which the terminal was launched.
${local} - Indicates a local terminal in a remote workspace.
${process} - The name of the terminal process.
${separator} - A conditional separator (" - ") that only shows when surrounded by variables with values or static text.
${sequence} - The name provided to xterm.js by the process.
${task} - Indicates this terminal is associated with a task.
It looks like the ${task} variable is what you are looking for.
Sometimes, plugins will remove default keyboard shortcut bindings.
Look for "terminal.rename" in keyboard shortcuts then edit the keyboard shortcut to your preferred shortcut.
To apply your shortcut, make sure your cursor is focus in edit part of the window before you key in. Not at the terminal part.
In v1.41 there is a new command which can be used like so:
{
"key": "ctrl+t",
"command": "workbench.action.terminal.renameWithArg",
"args": {
"name": "remote"
}
}
if you have some frequently used name, like "remote" or "build" that you use often.
With VSCode 1.63 (Nov. 2021), entering "<blank>" (ie., empty string) as name will restore the default name for that terminal.
See issue 134020
For instance:
If my setting is ${cwd}${separator}${process} and I name a terminal "foo".
How do I reset "foo" back to the value of ${cwd}${separator}${process}?
My suggestion was that if you attempted to submit a blank name that would automatically reset to the value of your setting.

Renaming a Yakuake session from commandline

Yakuake provides a hotkey and a GUI way to rename commandline tabs/sessions.
I'd like to do the same via the command line, so I can script it and use it in an alias. (My goal is that if I use an alias which does an SSH to some server, then the tab is renamed according to this servers name...)
I tried the suggestions shown here Renaming a Konsole session from commandline after ssh so far no luck.
Since KDE4, one should use qdbus to control KDE apps (instead of deprecated and deleted DCOP).
For example, to change a title of the first session one may use:
qdbus org.kde.yakuake /Sessions/1 org.kde.konsole.Session.setTitle 1 "New title"
To explore available interfaces, methods and properties one may use qdbusviewer.
As a homework try to get a list of active sessions (before you going to change smth).
Like #fgysin pointed out, his command also works for me. BUT it needs the ` character and not " for the subcommand :
qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.activeSessionId
It gives :
qdbus org.kde.yakuake /yakuake/tabs org.kde.yakuake.setTabTitle `qdbus org.kde.yakuake /yakuake/sessions org.kde.yakuake.activeSessionId` "NEW TAB TITLE";

GNU screen: how to check current scrollback value?

In GNU screen, I know that I can change the scrollback (buffer size) using this command:
<Ctrl-a>:scrollback 10000
as well as adding this line in .screenrc:
defscrollback 10000
But How do I check what the current value is? (For clarification, looking at the .screenrc file and locating the line with defscrollback is not the solution I'm looking for.)
Thanks!
As soon as you enter scrollback mode (CtrlA then Esc), you should see a status line like
Copy mode - Column 71 Line 25(+3000) (80,25)
The 3000 is the scrollback size. As long as you're in scrollback mode, you can use CtrlG to see a shorter version of that status line. If you're no longer at the bottom, the +3000 will be changed to show how far you've scrolled back. It tells how many lines are available above the currently displayed region, so +0 means you've scrolled back all the way.
You can also issue the command Ctrl-A i to get the value of the scrollback size currently set for that particular window.

listing current working directory when seeing all open shells in a screen session

I use screen and start a couple of shells within it. Now, if I list all shells using Ctrl-a " , then, all the windows are listed with a generic "bash" label. How can I change this, for e.g. so that they also list the current working directory of that window also.
Never mind, I figured it out. What is displayed via the Ctrl-A " sequence is the xterm window name, so you have to set that to something else.
So, for bash, put this in the .bashrc
PROMPT_COMMAND='
if [ $TERM = "screen" ]; then
echo -n -e "\033k$MYPWD\033\\"
fi
'