With Textmate 1.5 I used the parent process ID from my bundle script (PHP posix_getppid) in order to store some per-session variables. With 2.0, the same function returns a different value for each script execution in the same session. I realize I could query the system and find the Textmate pid by name, but there could be more than one instance running. Is there a better way to get a stable identifier that only changes if the application is relaunched?
Thanks,
John DeSoi, Ph.D.
Not a very nice solution, but if your routine is now returning a pid of the shell rather than the parent textmate, you can query it from bash, then the PPID should be the TM pid
$ ps -lp62651 UID PID PPID F CPU PRI NI SZ RSS WCHAN S ADDR TTY TIME CMD 501 62651 250 4084 0 48 0 3708212 48356 - S 0 ?? 0:02.11 /Applications/TextMate.app/Contents/MacOS/TextMate
This would be stable *even* if it was possible to run more than one instance of TM.
But are you sure this is even possible? I could not get TM to use more than one instance, even trying various things from the commandline
On 14 November 2014 20:47, John DeSoi desoi@pgedit.com wrote:
With Textmate 1.5 I used the parent process ID from my bundle script (PHP posix_getppid) in order to store some per-session variables. With 2.0, the same function returns a different value for each script execution in the same session. I realize I could query the system and find the Textmate pid by name, but there could be more than one instance running. Is there a better way to get a stable identifier that only changes if the application is relaunched?
Thanks,
John DeSoi, Ph.D.
textmate mailing list textmate@lists.macromates.com http://lists.macromates.com/listinfo/textmate
On Nov 14, 2014, at 3:16 PM, Carpii UK carpii.uk@gmail.com wrote:
Not a very nice solution, but if your routine is now returning a pid of the shell rather than the parent textmate, you can query it from bash, then the PPID should be the TM pid
$ ps -lp62651 UID PID PPID F CPU PRI NI SZ RSS WCHAN S ADDR TTY TIME CMD 501 62651 250 4084 0 48 0 3708212 48356 - S 0 ?? 0:02.11 /Applications/TextMate.app/Contents/MacOS/TextMate
This would be stable *even* if it was possible to run more than one instance of TM.
But are you sure this is even possible? I could not get TM to use more than one instance, even trying various things from the commandline
Right, I was testing something like this:
pgrep "TextMate" 20567 15405
and had two IDs because I was running 1.5 and 2.0 at the same time.
Allan gave some good solutions, I should be good to go.
Thanks,
John DeSoi, Ph.D.
On 14 Nov 2014, at 21:47, John DeSoi wrote:
With Textmate 1.5 I used the parent process ID from my bundle script (PHP posix_getppid) in order to store some per-session variables. With 2.0, the same function returns a different value for each script execution in the same session.
I was unable to reproduce that using the following command:
#!/usr/bin/php <?php echo posix_getppid() . "\n";
I realize I could query the system and find the Textmate pid by name, but there could be more than one instance running. Is there a better way to get a stable identifier that only changes if the application is relaunched?
TextMate sets TM_PID so you can use $_ENV['TM_PID']. Granted, we did this only for the interactive input support which no longer exist, but I see a few other things now rely on it, so should probably not remove it.
There is also TM_PROJECT_UUID and TM_DOCUMENT_UUID, which are meant as “public API”, but those are per-project and per-document, so they’ll live shorter than the session (but figured the info might be useful in this context).
On Nov 14, 2014, at 3:29 PM, Allan Odgaard mailinglist@textmate.org wrote:
I was unable to reproduce that using the following command:
#!/usr/bin/php <?php echo posix_getppid() . "\n";
I was launching my command like this:
#!/usr/bin/env bash [[ -f "${TM_SUPPORT_PATH}/lib/bash_init.sh" ]] && . "${TM_SUPPORT_PATH}/lib/bash_init.sh"
require_cmd psql php -f "$TM_BUNDLE_SUPPORT/src/execute.php"
It was so long ago, I don't remember exactly why. I assume it was to setup PATH and take advantage of require_cmd. If I write my own require_cmd in PHP, is there a right way to set this up without requiring the PHP interpreter at /usr/bin/php? It may not be important now that Apple seems to be including Postgres support in their PHP version.
Thanks!
John DeSoi, Ph.D.
On 16 Nov 2014, at 16:55, John DeSoi wrote:
It was so long ago, I don't remember exactly why. I assume it was to setup PATH and take advantage of require_cmd. If I write my own require_cmd in PHP, is there a right way to set this up without requiring the PHP interpreter at /usr/bin/php?
TextMate 2 has a better system for declaring requirements.
You’ll have to manually edit the XML of the tmCommand as it’s currently not exposed in the bundle editor. If you insert the XML below in your tmCommand then TextMate will find `psql` by checking if the value of `TM_PSQL` is valid, searching `PATH`, and finally trying the locations listed in the `locations` array.
If it finds `psql` then it sets `TM_PSQL` to where it is located and runs the command. So your command should use the `TM_PSQL` variable (rather than rely on finding it via `PATH`).
If `psql` is not found, TextMate shows a dialog explaining the issue (and does not run your command).
If you leave out the variable from the XML below, TextMate will instead update `PATH` if `psql` is not already in the `PATH` (e.g. if found via `locations`) — but we recommend keeping the variable, as it’s more flexible (for the user).
<key>requiredCommands</key> <array> <dict> <key>command</key> <string>psql</string> <key>variable</key> <string>TM_PSQL</string> <key>locations</key> <array> <string>/usr/local/bin/psql</string> <string>/opt/local/bin/psql</string> </array> <key>moreInfoURL</key> <string>http://www.postgresql.org/docs/9.2/static/app-psql.html</string> </dict> </array>