How to send ctrl+shift+6 as ansi escape sequence? - windows-subsystem-for-linux

Trying to find the ANSI escape sequence for sending the keys ctrl+shift+6 in the format \u001b.. .
I recently tried switching over to only using Windows Terminal instead of SecureCRT/Putty but i'm having issues terminating Cisco telnet/console sessions that uses ctrl+shift+6 and then x.
The terminal does not seem to recognize this or isn't forwarding it the same way as SecureCRT/Putty because nothing happens. The session is established over term VTY100 if that has any use, and the SSH-session is initiated from a Zsh-shell in a Redhat7 jumphost, the base connection comes from my Ubuntu WSL2-box.
I think I found a possible workaround as Windows Terminals allows keybinding an ansi escape sequence, but I'm unable to figure out what the sequence would look like?
Send arbitrary text input to the shell. As an example the input "text\n" will write "text" followed by a newline to the shell.
ANSI escape sequences may be used, but escape codes like \x1b must be written as \u001b. For instance "\u001b[A" will behave as if the up arrow button had been pressed.
By default this exact keybinding is used by Windows Terminal to open a new tab but I removed that.

The question is
Trying to find the ASCII escape sequence for sending the keys ctrl+shift+6 in the format \u001b.. .
That's referring to ctrl^, which usually is 0x1e (hexadecimal) or 036 (octal).
Based on the comment which you quoted, that would be expressed as "\u001e".
If Windows Terminal assigns that to a different code, you might open a bug report, because its developers intend to imitate xterm.

Related

How do I send the same command to a subset of all windows in a screen session

In the answer to this post Corey Henderson explains how you can use the at and stuff commands in screen to send commands to all windows of a screen session at once. I would like to know how I can stuff the input buffers to some windows at the same time. In other words, I would like to use a filter to specify which windows should receive the input and which should not.
It would be great if I could filter on the window number instead of the user name or the window name because bash likes to change the window name sometimes and it is inconvenient to modify the .bashrc on multiple machines. Also, sometimes I don't have control over which user I am running the command as.
So far I have only been able to run a command on either the currently active window or all windows at once.
The only way I have found to do windows filtering when using the atcommand is by using windows names.
By default screen's windows names are set after the actual command name of the program created in the window, for me this is usually bash. But windows names can be changed to whatever you prefer with Ctrl+A. If your windows' names change dynamically, check you don't have Dynamic Titles enabled.
So in practice that means you can give related windows a common prefix and then use at "prefix#" stuff "command" to execute the command only on those windows whose names matches the filter.
Imagine we have the following windows opened in our screen session:
0$ front1 - 1$ front2 - 2$ back1 - 3$ back2 - 4$ back3 - 5$ db1 - 6$ db2
The next command would send the service ntpd stop command to windows starting by the string back, that is back1, back2, back3:
at "back#" stuff "service ntpd stop^M"

Extract userInfo from JSCH stream

I am trying to implement an online terminal UI with jsch as backend.
I need to display the userinfo ie [username#Machine ~]$ information in the UI.
Since the outputstream simply sends the bytes, it is difficult to distinguish the userinfo with the real command output. Is there any way to distinguish the same?
In general, no.
If you have a shell channel, all you see is the output from the user's remote shell, including the prompt and the actual command output. You can try to parse that. In simple cases this will work, but in general it is impossible, as every command could output a prompt-like string.
The username should be known to you (it should be the same as you used for login), the server name is a bit trickier.
An idea worth exploring might be to set a special prompt delimited by character sequences which are unlikely to occur in "normal" command output – set the PROMPT variable in your shell.
You could circumvent that problem by not using actually a shell channel, but an individual exec channel for each command – but then you'll have to interpret commands like cd yourself and keep track of the current directory, and add a cd command before the actual command in each exec channel. You might want to have an sftp channel open in parallel to keep track of the directories (and list files, and so on).

Gnu Emacs: tab-completion for psql running within sql.el process

I enjoy running Postgres client "psql" under psql.el while interacting with a .sql file in a separate window. Sometimes, I want to use tab-completion within the the buffer running the psql process to find the name of an appropriate table name. However, I can not figure out how to cause the desired result.
A very related question has been asked here: https://superuser.com/questions/236574/how-can-i-send-a-literal-tab-to-bash-in-emacs-shell-mode
without any successful suggestions.
Thanks in advance!
SetJmp
Usually programs that designed for interactive use (when they own terminal) disable interactive features (like history for UP/DOWN, completion for TAB) when used in pipe.
Emacs usually use pipes for external processes. So interactive features are disabled.
Even if you send TAB, your client program does not interpret it for you as you want.
You can read man/help for your program and try force interactive mode by providing command line switch (like --login for GNU Bash).
To send TAB eval:
(defun my-comint-send-string (string)
"Send string to comint buffers. Useful for *compilation* read-only buffer."
(interactive
(list (read-input "Type string: " nil 'my-comint-send-hist-list)))
(comint-send-string (get-buffer-process (current-buffer)) string))
(define-key XXX-mode-map [C-return] 'my-comint-send-string)
and use such key sequence: C-RET C-q TAB RET.
But this may not work if buffering is enabled for stdio of your program (to flush input you must send \n too)...
Mostly same problem discussed at Bash autocompletion in Emacs shell-mode
NOTE M-x term use pseudo terminal so all interactive program work as desired. But in this mode you lose any Emacs editing capabilities...

How to log Command Line activity? [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
DOS command to Display result on console and redirect the output to a file
tried various Google searches but nothing seemed to solve my problem.
Basically I'm working for a company who need me to work with their in place database and extract the various data need for reports. They are using Sqlite (please, I've heard enough comments about how it might not be the best choice for a DB, so leave them out) and I either want all my activity on Windows command prompt to be logged, or at least everything I do from the Sqlite command line to appear in a .txt, just in case I need to refer back to it later.
Can anybody here explain to me how to do this? I'm a bit of a beginner and need this stuff broken down step by step. Not done anything like this before.
Cheers!
I'm reasonably certain you can't do this directly -- i.e., the Windows command prompt doesn't provide a way to log the input you provide to it. You can capture outputs (e.g., from commands you run), but for your purposes that's probably not adequate.
You probably need to create a "shell" of your own that takes inputs from the user, logs each one, sends it on to the command prompt, captures the output from the command prompt, and logs that as well.
In an answer to a previous question, I posted some code that handles most of what you need to do. The big difference is that you'll want to look in its handle_output (for example) and instead of just displaying the captured output to the console, write it to a file as well. As it stands right now, that example redirects the child's standard input to come from a file, but changing it to read from the console instead should be fairly straightforward -- you'll basically use a function about like the handle_output and handle_error that it already includes, but instead of displaying output, you'll read input from the user, and each line you'll 1) write to the log, and 2) send to the child via anonymous pipe (much like handle_output and handle_error read from anonymous pipes).

Key mapping for putty or putty alternative

at my work we're trying to find a replacement for an old telnet client that we use to connect to an SCO Unix server running an old program. I have found that I can almost get putty to do everything required - setting it to SCO function keys lets me use the F1 to F12 correctly and setting the translation character set to CP437 draws all the lines correctly.
The problem is that the program we use on the server pretty much requires the use of custom key mapping. That is we need to be able to map the home key to ";$", the end key to "exit^M", the F-10 key to ";}" etc. Putty doesn't allow custom mapping. We've tried to edit the source code of putty to change its behaviour, but had no luck.
Does anyone know if there is a modified version of putty somewhere that allows key binding? Or another free terminal program that does? Or instructions for what to change in the putty source code? If we can't find a solution we're probably going to end up buying ZOC, but we'd rather not if we can find an open alternative.
Thanks a lot,
Alex
Never mind, in the end we were able to modify the Putty source code as required to add the custom keys.