Using the "urxvt::term" Class - linux

I wanted to know if there are any resources
available for understanding and using
the 'term' class in urxvt.
The documentation makes a very general
set of references to it, but doesn't really
define the terms.
The uxrvt perl extensions also make very limited use
of the 'term' object, so there isn't much code
to study for reference.
My goals are simple:
To open a new terminal window.
To pass a command to the new terminal window,
then leave the window open for further input.
(example: "ls" or "echo 'Hello World'", then
leave the cursor awaiting further input)
To be able to specify which desktop the
new terminal will appear on.
Questions:
1. How exactly is $term defined?
The documentation says:
$term = new urxvt::term $envhashref, $rxvtname, [arg...]
I've used "my $env = $self->env;" to define the
$envhashref. So I suppose that the existing terminal's
environment variables are used for the new terminal.
I suppose this corresponds directly to the environment
variables themselves, since the following reproduces
those variables...
my #envv = $self->envv;
foreach (#envv) {
print "$_\n";
}
...and the following creates a reference to the 'env' hash:
my $env = $self->env;
Is this correct? It seems odd to have to explicitly declare
the environment if that setting will remain unchanged in the
vast majority of cases.
2. How should $rxvtname be set? Setting it to a name of my
choice results in two windows opening rather than one.
That behavior is odd... what is the correct way to define
the $rxvtname variable?
What exactly does ", [arg...]" refer to?
3. How is $term itself used? It apparently isn't
a reference to the new terminal window. What is its
purpose and how do you use it? An example would
probably be extremely useful here.
4. How can $term->exec_async ($cmd) send a command
to the new terminal window? Is there a better way
to send commands to a new window? Examples?
5. Is there a way to specify which desktop a terminal
window should appear in?
Hopefully this thread can serve as 'documentation' for anyone else
who has already scoured the man pages for urxvt, urxvtperl (as well as
urxvt.pm) and is left without a clear understanding. And if there's
a comprehensive reference on the web somewhere that contains full
explanations and examples, that would be great to know about, too.
Thanks in advance for your help.

Related

Can GNOME Shell extensions move the pointer? If so, how?

I want to write an extension that does the opposite of the "focus-follows mouse" setting in GNOME Shell: I want to make my pointer move to the center of the currently focused window.
Can this be done in a GNOME Shell extension? I see some GNOME code that wraps xfixes cursor, but I can't find any references to programmatic pointer updates in either the core Javascript or any existing extensions. (Am I just bad at Google?)
Valid answers include (1) example code that does it or (2) citation of a canonical source that says it can't be done.
Found this code in overview.js
Gdk = imports.gi.Gdk
let display = Gdk.Display.get_default();
let deviceManager = display.get_device_manager();
let pointer = deviceManager.get_client_pointer();
let [screen, pointerX, pointerY] = pointer.get_position();
pointer.warp(screen, 10, 10);
Are you willing to write your own script? If you are, I have found three tools, which, if used together, can get the job done for you.
First, use xprop to get the PID of the window you have clicked on.
Next, use xwininfo to get the dimensions and position information of the window based on its process ID.
Finally, use xdotool to calculate the center position of said window and move the cursor to that exact position.
Hope this helps. I don't have enough time write now to write the script (sorry), but this should be enough to get you started.
EDIT: Based on your comment, you want to stay in GNOME js. Totally understandable. You can call xdotool (which is the most efficient way of changing the position of the cursor on screen) from within GNOME js by use of something like:
const Util = imports.misc.util;
Util.spawn(['/bin/bash', '-c', "xrandr --query | awk 'something'"]) # replace the code here wih your own
This code was found at this thread.

Is it possible to keep a variable active with Revit Python Shell, using canned commands?

I'm currently using Revit Python Shell 2017 and I'd like let's say to make "communicate" different canned commands.
For instance, let's say I load a house model, and I create some additional walls on it, via a canned command that I would have previously created. While creating these walls, I could store all these new walls IDs in a variable, as a list.
Now, if I want to delete exactly these walls afterwards, I'd like to identify them using their IDs that I stored in the list, then delete them.
If I was in an interactive Python Shell session, well the "IDs list" variable would still be accessible (as long as I don't close the shell), and I could just retrieve the IDs from it, then delete the walls.
But what if I'm using canned commands? The first command would be "create the walls", and the 2nd would be "erase these walls". But that "IDs list" variable doesn't exists in the second canned command environment, so that I can't use it to erase the walls.
So, what would be the approach? Of course in this example I could identify the walls in the second command using a different methodology, such as asking the user to select them etc etc.. But the idea I'm going for would be the store that list from the first command "somewhere in Revit", and retrieve it when calling the second command.
I could write the list to an external text file, and read the file in the second command... but is there a cleaner way?
I'm sorry for the beginner's language used here, and hope that my question is clear enough! And that somebody can help ;)
Best,
Arnaud.
This is a great question Arnaud, in the past Ive done the following:
Create a text project parameter, and populate it with XML (yes you can have line breaks in a text parameter). This is similar to what Ideate BIM Link does (check the project parameters of any project that has used BIM Link). This is a long-winded method for keeping data persistent between commands.
The second part (saving a walls IDs) is more difficult I think, as I understand it every time you open a project the IDs are reassigned. You could test this to see if its the case?
Another method could involve using an External command that lingers after you have finished selecting walls. Could you go into a little more info about what youre wanting to achieve?
So,
Just for leaving a trace, I solved this using pyRevit and its ability to store data in temporary files (here, look for "Using Temporary Files").

Is there a way to detect the terminal program that someone is using in bash

I'm trying to make a bash script that behaves differently based on the terminal program that someone is using (Putty, mobaxterm, etc). Is there any way to retrieve this kind of information from a bash script?
I was searching around online but I was not able to find anything (or I'm just wording it incorrectly, which could be a distinct possibility).
thank you
You need to understand that these are terminal emulators. There is a simple, crude identification function for (most?) modern line terminals (now that's an oxymoron!) but it will return something like vt102 or xterm i.e. whatever the emulator is emulating; not the identity of the program performing this emulation. Incidentally, this is usually used when the session is initiated, and reflected in the value of the $TERM environment variable.
The common way to do this is the environment variable TERM. Try
echo $TERM
That should output the terminal emulator's type, indicating its capabilities. Often, though not always, the value of TERM will be the name of the terminal emulator. For example, xterm may set TERM to xterm, or to xterm-color, depending on configuration.
Note that the user can change this variable, so it may contain something completely different.
That said, if you want to do fancy things with the terminal from a script, you don't need to build support for different terminals by hand. There are various libraries that offer all the usual functions (clear terminal, resize window, change font etc.). The most popular one is terminfo; there are various packages that build on terminfo.

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

what is the meaning of shell title?

I'm new to linux. And I'm confused with the different shell titles in linux.
for example, when I called "/bin/sh", I saw
sh-3.1#
but when I used "su root", I saw
my-environment:~#
and when I logged in as normal user, I saw
user#my-environment:$
I kind of notice # means root and $ means non-root, but could some explain how I got the above titles?
Thanks a lot!
The text at the shell prompt is controlled by the variable $PS1 (and sometimes $PS2 $PS3 $PS4). This blogpost explains how you can customize the prompt in many ways.
Do echo $PS1 in the different terminals to see the current value.
This depends on your variable environment $PS1.
To see what I mean, try doing PS1=something, and see what happens.
To reset it you could do source ~/.bashrc.
So, why do you have different prompt according? Because you don't load the same files according to the command you type to open your sessions, so you end up with different configs, hence a different $PS1

Resources