Last active
August 30, 2018 10:41
-
-
Save noamross/2e4805a320eafef44bb3dbf0d33e27ec to your computer and use it in GitHub Desktop.
An experiment in trying to make RStudio GIT_EDITOR for terminal sessions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
# Put this file somewhere and run | |
# export EDITOR=/path/to/rs_term_editor.sh | |
# export GIT_EDITOR=/path/to/rs_term_editor.sh | |
# There's probably some way to set thes e in my profile to only run | |
# when RSTUDIO=1 | |
### Set initial time of file | |
LTIME=`stat -f "%m" $1` | |
ATIME=`stat -f "%m" $1` | |
## Open file in rstudio | |
curl "http://127.0.0.1:$RSTUDIO_SESSION_PORT/rpc/console_input" \ | |
--header "X-Shared-Secret: $RS_SHARED_SECRET" \ | |
--data-binary "{\"method\":\"console_input\", \"params\":[\"rstudioapi::navigateToFile(\\\"$1\\\")\",\"\"], \"clientId\":\"33e600bb-c1b1-46bf-b562-ab5cba070b0e\"}" | |
#Wait until file changes, then exit | |
while [ $ATIME == $LTIME ] | |
do | |
sleep 0.25 | |
ATIME=`stat -f "%m" $1` | |
done | |
# Close the document? Then I'd have to open it in a way that I get its ID |
That worked! Didn't need to ping, just waited for file to change. Now, should I close it after it is saved? To do so I should open the file with a less hacky method so as to be able to get its ID and close it.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Hmm, maybe: