Hello,

I did some work on this a few years ago and made it work, kind of...
There is no easy solution, but the trick is to use the window id
($WINDOWID in bash and also available in Awesome). I guess using some
dark magic using /proc or ps you could get the PWD. But again, it wont
be perfect and wont handle ssh sessions ans such.

There is more. URXVT have a mode called "urxvtd". This will create a
single PID for all terminals. This has some advantages. First of all,
they can communicate to each other using the Perl API. Then, even
better, I wrote a plugin that create a DBus interface (
https://github.com/Elv13/urxvt-dbus ) to interact from Awesome. This
way, Awesome can create tabs and instances with much more control.
Unfortunately, there is a bug in LGI that prevent GDBus_async from
working correctly, but you can still wrap the shell command
asynchronously as a work around. As is, the plugin is useless to you
as it is very incomplete and I know nothing about Perl, I just hacked
my way using some Tutorials and existing code. If you want a _real_
Awesome<->URXVT bridge and know Perl, then please for the thing and
complete it.

If you don't, then the WINDOWID trick will get you there. In ZSH, it
was easy enough to create a function that could send the PWD and
current command into awesome-client by using the pre and post command
hooks. I don't think these are available to bash (pre command is, I
guess it could also be used as a post command)

On 7 September 2014 07:46, Ian Thompson <[email protected]> wrote:
> On Sun, Sep 7, 2014 at 5:10 AM, lilydjwg <[email protected]> wrote:
>>
>> On Sun, Sep 07, 2014 at 08:55:37AM +0100, Paul Jolly wrote:
>> > [...]
>> >
>> > But for now I would be happy for the cwd of the bash instance in the
>> > current window. My problem is I don't know how to get the PID of the
>> > current window (indeed if someone can suggest a better approach I'm all
>> > ears!)
>>
>> IIUC, that is client.focus.pid if available.
>
>
> Unfortunately, that only gets the PID of the terminal emulator, which
> doesn't change directory with bash. You need something that digs through the
> process tree to find the current interactive shell process and grabs its
> PID. Here's the script I use:
>
> https://gist.github.com/Dalrik/20b41ca274a9da47138a
>
> Call that script with client.focus.pid as the argument, and it will spawn a
> new shell in the same cwd in most cases. YMMV. Some notes:
> - This script will find the "deepest" zsh process under a given PID, which
> in my case is almost always the currently interactive shell. I have a bunch
> of alternate environments that I can run as necessary, so it's fairly common
> for me to have 2 or 3 zsh processes running under a given instance of urxvt.
> - You'll need to change zsh and urxvt in the script to whatever you use.
> - This version of the script breaks down if it hits a su'd terminal. I use
> another one which replaces the pwdx call with a small setuid program which
> prints the pwd of any process, which allows me to use it on terminals that
> I've, for example, used `sudo -s` on. I wouldn't recommend doing this unless
> you understand exactly what the security implications are.
>
> If you don't care about tracking down which instance of bash is the one
> you're interacting with, you could change the checkchildren function to
> return on the first shell process it finds. In most cases, it's also
> sufficient to simply increment the PID of the terminal emulator by 1, but
> there are many cases where that assumption could break down.
>
> Hope this helps,
> Ian

-- 
To unsubscribe, send mail to [email protected].

Reply via email to