Discussion:
Open new window from running instance
Adesh Kumar
2017-09-14 16:38:14 UTC
Permalink
Hello Folks,


I recently tried urxvt to see what all the fuss was about and I'm very much liking it. I think I'll soon ditch my Xfce Terminal.


However, there is something I'm missing. Most of the terminal emulators provide a keybinding to open a new terminal window from an already running instance. For example, in GNOME Terminal and Xfce terminal, you can press Ctrl+Shift+N to open a new terminal. The new window opened this way inherits its current working directory from the parent window, which is highly useful. Searching internet on this topic did not return anything useful. Documentaion if urxvt also does not talk about this topic. So, is this sort of functionality available in urxvt? If yes, how can this be enabled?


Regards,

Adesh
Marc Lehmann
2017-09-16 18:25:09 UTC
Permalink
Post by Adesh Kumar
can press Ctrl+Shift+N to open a new terminal. The new window opened
this way inherits its current working directory from the parent window,
which is highly useful.
First of all, this simply cannot be done without support from the program
running inside the terminal - while some operating systems allow
you to query the current working directory of other processes, this cannot be
done portably, and, whats more, there can be multiple programs running inside
a terminal all with their own cwd.

For example, try this in gnome terminal:

$ cd /tmp
$ bash
$ cd /
[ctrl-shift-n]

The new terminal will not open with the CWD set to /, but probably to
/tmp.

This is the reason why urxvt does not support this out of the box - opening
a new terminal would be as good as simply starting it again, so this option
isn't really needed.

Now, what gnome-terminal and others do on e.g. Linux could be done with
a linux-specific extension that, of course, would have to be written
first (it could also be done in other ways, but doing an extension would
probably be most painless).

So yes, there is no such functionality in urxvt out of the box, and none
planned, as urxvt tries to be portable.
--
The choice of a Deliantra, the free code+content MORPG
-----==- _GNU_ http://www.deliantra.net
----==-- _ generation
---==---(_)__ __ ____ __ Marc Lehmann
--==---/ / _ \/ // /\ \/ / ***@schmorp.de
-=====/_/_//_/\_,_/ /_/\_\
Martin Pohlack
2017-09-16 20:26:04 UTC
Permalink
We discussed a non-portable way to do that in 2012 here:

http://lists.schmorp.de/pipermail/rxvt-unicode/2012q3/001607.html

I am using something something similar in a custom selection-popup
plugin to open files that are highlighted. It breaks down as soon as
you have nested sessions of any forms (nested shells, midnight commander
etc.) with different CWDs, but is sensibly useful otherwise.

HTH,
Martin
Post by Marc Lehmann
Post by Adesh Kumar
can press Ctrl+Shift+N to open a new terminal. The new window opened
this way inherits its current working directory from the parent window,
which is highly useful.
First of all, this simply cannot be done without support from the program
running inside the terminal - while some operating systems allow
you to query the current working directory of other processes, this cannot be
done portably, and, whats more, there can be multiple programs running inside
a terminal all with their own cwd.
$ cd /tmp
$ bash
$ cd /
[ctrl-shift-n]
The new terminal will not open with the CWD set to /, but probably to
/tmp.
This is the reason why urxvt does not support this out of the box - opening
a new terminal would be as good as simply starting it again, so this option
isn't really needed.
Now, what gnome-terminal and others do on e.g. Linux could be done with
a linux-specific extension that, of course, would have to be written
first (it could also be done in other ways, but doing an extension would
probably be most painless).
So yes, there is no such functionality in urxvt out of the box, and none
planned, as urxvt tries to be portable.
Rastislav Barlik
2017-11-05 14:14:53 UTC
Permalink
Or just add this to your bashrc:

bind -x '"\e\r": "setsid urxvt"'

This creates a new shortcut for bash: Alt-Return and spawns a new
terminal in your current directory.

On Sat, 16 Sep 2017 22:26:04 +0200
Post by Martin Pohlack
http://lists.schmorp.de/pipermail/rxvt-unicode/2012q3/001607.html
I am using something something similar in a custom selection-popup
plugin to open files that are highlighted. It breaks down as soon as
you have nested sessions of any forms (nested shells, midnight
commander etc.) with different CWDs, but is sensibly useful otherwise.
HTH,
Martin
On Thu, Sep 14, 2017 at 04:38:14PM +0000, Adesh Kumar
Post by Adesh Kumar
can press Ctrl+Shift+N to open a new terminal. The new window
opened this way inherits its current working directory from the
parent window, which is highly useful.
First of all, this simply cannot
No…Dec 16Jan 17Feb 17Mar 17Apr 17May 17Jun 17Jul 17Aug 17Sep 17Oct
17Nov 17$50$75$100$125$150 03/16/2017US:RHT$84.1000
Advanced Charting

$ % Vol

be done without support from the
Post by Martin Pohlack
program running inside the terminal - while some operating systems
allow you to query the current working directory of other
processes, this cannot be done portably, and, whats more, there can
be multiple programs running inside a terminal all with their own
cwd.
$ cd /tmp
$ bash
$ cd /
[ctrl-shift-n]
The new terminal will not open with the CWD set to /, but probably
to /tmp.
This is the reason why urxvt does not support this out of the box -
opening a new terminal would be as good as simply starting it
again, so this option isn't really needed.
Now, what gnome-terminal and others do on e.g. Linux could be done
with a linux-specific extension that, of course, would have to be
written first (it could also be done in other ways, but doing an
extension would probably be most painless).
So yes, there is no such functionality in urxvt out of the box, and
none planned, as urxvt tries to be portable.
_______________________________________________
rxvt-unicode mailing list
http://lists.schmorp.de/mailman/listinfo/rxvt-unicode
Raphaël
2017-09-17 15:16:29 UTC
Permalink
I couldn't set the CWD of $SHELL from extension on_start(). Hints welcomed.
If this could be addressed, that would make it window-manager
independent (but bash & linux-specific).


#### ~/.urxvt/last-directory
#! perl -w
sub on_start {
if (open(FH, "/dev/shm/bash-cwd-" . $ENV{"USER"})) {
my $last_cwd = readline(FH);
chomp($last_cwd);
if (-e $last_cwd and -d $last_cwd) {
print("chdir=" . $last_cwd . "\n");
##### Error: this does not work. maybe $self->env ?
$self->option("chdir", $last_cwd);
}
}
()
}
#### ~/.bashrc
bash_prompt_command() {
# last path is recorded after every command bash runs
echo $PWD >| /dev/shm/bash-cwd-$USER
# [...]
}
export -f bash_prompt_command
export PROMPT_COMMAND=bash_prompt_command
Loading...