pgid-cd.pl - change directory to that of given process and run command
pgid-cd.pl [ -v ] ( pgid | -1 ) command [ args ... ]
Tries to detect current working directory (or CWD) of specified process group and runs specified command in that directory.
CWD detection is brittle and can lead to unexpected results. It is likely to fail if all processes in given process group run as a user other than current user (current user will simply lack permission to read CWD information). Furthermore, if different processes in process group have different CWDs the script will pick arbitrary one (it can access). And of course there's no hope of it working via remote connection (e.g. SSH).
If changing directory fails, print all encountered errors. Otherwise silently start the command. Note: if present, this *must* be the first argument.
ID of the process group to detect CWD of. -1 disables CWD detection and the script then simply executes the command.
Command to execute.
The script was designed to work with tabbedex urxvt plugin and in particular its tab-arguments configuration resource. For example, if this script is located in ~/.urxvt/tabbedex-pgid-cd one can use the following configuration:
URxvt.tabbedex.tab-arguments: \
-e %~/.urxvt/tabbedex-pgid-cd %p %E
or if it's in /usr/lib/urxvt/tabbadex-pgid-cd then:
URxvt.tabbedex.tab-arguments: \
-e /usr/lib/urxvt/tabbadex-pgid-cd %p %E
Tabbedex will replace %p sequence with an ID of a process in foreground of current tab such that command in the new tab will inherit current working directory from existing tab.