Skip to content

Instantly share code, notes, and snippets.

@noamross
Last active August 30, 2018 10:41
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save noamross/2e4805a320eafef44bb3dbf0d33e27ec to your computer and use it in GitHub Desktop.
Save noamross/2e4805a320eafef44bb3dbf0d33e27ec to your computer and use it in GitHub Desktop.
An experiment in trying to make RStudio GIT_EDITOR for terminal sessions
#!/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
@noamross
Copy link
Author

Hmm, maybe:

  • Run a loop pinging the RStudio session to see if the file has changed
  • Return from the bash script after the file has been saved.

@noamross
Copy link
Author

noamross commented Aug 21, 2018

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