How to access a linux terminal's scrolled text file/buffer directly? - linux

linux terminals display output on a (configurable) scrolling window. User configuration allows control of both the scrolling and the size of the window (in number of rows and columns).
The fact that we can scroll back to areas that went off screen, then select that text for cut+paste, means that there is an accessible buffer where that content can be reached directly and specifically.
Is there a process, using linux/bash built-ins or utilites, which would permit the user to access specific segments of that content buffer (which are otherwise accessible via mouse selection) from within a bash script (preferrably directly ... and, if not, possibly via prompted mouse interraction) ?
If unable to do that selectively, is there a way, again from within a bash script, to get a snapshot of that full 2000-line buffer and save it to a script-defined file, where it could then be manipulated ?

Related

Script to paste a specific string into a text field with a hotkey

I am trying to find a way to paste a predefined string upon entering a specific keyboard sequence, on any app.
For example if I have to paste an url or a password into a field, I can have said password in a hidden script and when I press, say, [ctrl] + [5], it would write "example123" on the text field where my cursor is.
Ideally without copying to the clipboard (I'd prefer keeping what I have on my clipboard and also avoiding to paste a password or such by mistake elsewhere).
I have tried every solution I've found so far that include xclip, xdotool and xvkdb. All of them either do not work or are really inconsistent: They only paste the string sometimes, and when they do, it's usually only part of the string ("ample123" instead of "example123").
I thought of using compose key, which I heavily use anyway to write in french on an us keyboard, but it seems it only supports 1 character sequences, as nothing is printed when I modify my .XCompose to include custom output sequences of len > 1.
I am using Ubuntu 18.04 with Gnome as a DE. Ideally something that also works when logging back (like compose keys).
You need to walk the Document Object Model for either Gnome or your web-page. My concern is that with a desktop script you wont be able to access the web page because you will need to be able to establish a target to send string to. I see in your question that you tried using using "x{tool-name}" to grab the text field element. Delivering the sting really isn't the problem. The problem is getting the GUI element of text box pragmatically. The easiest way to get access to this in a user loaded web-page is with WebExtensions API which is how to make extensions for most modern browsers. Otherwise, if you can get away with only having access to Gnome's GUI I would try LDTP, it's a library used for testing, but it looks like it can be used for automation too.
For keyboard shortcuts:
It really shouldn't matter what the script is doing to how you want to activate it. I would just go to Gnome/Settings/Keyboard and set the path to where I saved the script to be the Command. If you go the WebExtension route, you will want to build the shortcut into your extension.

persist fields order for linux `top`

In linux, top can be used to monitor system status. When it is running, using f allows us to choose the columns to be displayed.
However, when you quit it and reenter top, all the settings go back to the default.
How can I make the changes persistent? Is there a config file for top?
Use W (capital w) to save the top configuration after you made your changes.
By issuing this command just before quitting top, you will be able restart later in exactly that same state (from man page)

xterm dump of full scrollable window content

I want to know if anyone does know a way to dump or copy the whole lot of viewable messages in a xterm window on linux. The very important thing is I don't want to know how to send a command out and kapture its output for stream 1 and 2 as well as the input, as this is well known to me.
I may explain for what this is needed. You do something and expect not any complications but than you got pages of msg's als err msg or normal output. To be able to see later after it you should be able to get them in a file and as long as you are able to scroll that all back and forther with your mouse it is sure the data is there some where. But the time may be not to scroll and screenshot and scroll ....
I would be glad to help me out in such cases and it would be fine to have the full view including all your own typing and all the msg's in same order as you watch it when you scroll it back.
I don't really know where this is stored and how you could get that saved. I know that I could dump the whole lot of Memory and search it for a part of the xterm window, but that is a bit over the top I think.
There is a control sequence, which I had forgotten. This question reminded me. In XTerm Control Sequences, it is noted "print all pages":
CSI ? Pm i
Media Copy (MC, DEC-specific).
Ps = 1 -> Print line containing cursor.
Ps = 4 -> Turn off autoprint mode.
Ps = 5 -> Turn on autoprint mode.
Ps = 1 0 -> Print composed display, ignores DECPEX.
Ps = 1 1 -> Print all pages.
That dates from 1999 (patch #119), so you likely have it in your xterm. You could do this in a shell command like this:
printf '\033[?11i'
A comment mentions the page Hidden gems of xterm, which uses the corresponding action print-everything (something that can be executed via the translations resource). It is in the manual page, of course. The same comment points to Extra characters in XTerm printerCommand output, which mentions the resource printAttributes. By default, the control sequences for the printer tell xterm to send extra control characters (to reconstruct video attributes). The resource can be modified (set to 0) to suppress that. That is even older (patch #74).
Without that — Conceivably one could construct an application which used the X SendEvent protocol to construct a series of events which would be interpreted as xterm actions to scroll back, select text and copy it chunk-by-chunk via the clipboard. You could even write it in Perl (there is a module for X protocol). But seriously, no.
If you want to capture text which was written to xterm, you can do this by preparing before the text is needed by different methods (see manual):
turn on the xterm logging feature (not that user-friendly because it generates the filename). This can be enabled using the "Log to File (logging)" menu entry.
use the printer control sequences to write lines as they are written (again, not that friendly, though there is a menu entry to turn it on and off, "Redirect to Printer (print-redir)")
use script to capture all output to the terminal. I use this, because it works with any terminal on any POSIX-like system (even Cygwin).
Each of these methods produces a file containing escape/control sequences, which requires filtering out. The hypothetical program using SendEvent could in principle eliminate that.

Clean any output of a linux console

I have a linux installation without X. When I launch a third-part application (i.e. gstreamer) it draws on a portion of the screen, let the users see through the external areas.
I want to "clear" the console so it appears black. Of course the clear command won't work because you still see the prompt.
Might you recommend any way to achieve this?
The environment variable which contains the output displayed by the prompt is named PS1. You can empty this variable when needed.
Don't forget to keep a 'backup' of the value in order to be able to set it back to its old value

Kindle: Change screen boundaries/resolution

Is there any way to change the resolution or set different boundaries for the screen on Amazon Kindle Keyboard? My screen has a crack in a portion of the screen, and I would like to work around it.
I've tried messing around in the filesystem (connected over WiFi), but none of my property changes have had any effect. I assume it would be possible, as it is a Linux OS.
AFAIK you can't change ther resoluiton, but for the margins:
For simple adjustment of the left and right margins to one of the
three preset values, use the "Words per Line" option on the font size
page (press Aa key to the right of the spacebar on the keyboard). The
option may be named "Words per Line" but what it really does is to
alter the left and right margins.
For finer control of the margins,
the following steps require the user to access the the Amazon Kindle's
internal storage memory through a USB cable attached to a computer.
On
your Kindle, go to the home page. NOTE: if the next steps are
completed while an ebook is open, the change will not take effect.
Connect your Kindle to your computer with a USB cable.
Open the folder
"system" in the root of the Kindle's internal storage memory. If
you're on a Windows machine, this might be hidden from you. Be sure to
set Folder Options to ‘Show hidden files, folders, and drives’ and
uncheck the ‘Hide unprotected system files’ option. Alternatively, try
typing in the system folder's address explicity, e.g. if the Kindle's
drive letter is H, the address would be H:\system\ Open the
"com.amazon.ebook.booklet.reader" folder.
Open the "reader.pref" file
in a text editor. This is a plain text file with Unix line endings.
There is a line in reader.pref that starts "HORIZONTAL_MARGIN=".
Change the number (Default=40) that follows to the desired number.
Margin-widths of 20, 15, and 10 are good starting points for
determining what you're most comfortable with. I find that 0 (zero)
puts the text too close to the bezel surrounding the display
(particularly difficult on the eyes with graphite colored bezel).
Save
and close the file.
Eject and disconnect the Kindle.
Restart your
Kindle (Menu/Settings/Menu/Restart)
Your default margins when reading
books have now been changed. If you change the 'Words per Line'
preference in the Font Size dialog, you will undo the change to the
margins that you have just made.
Source: http://wiki.mobileread.com/wiki/Kindle_HowTo:_Change_Margin

Resources