Skip to content

Instantly share code, notes, and snippets.

@noamross
Last active Aug 30, 2018
Embed
What would you like to do?
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

This comment has been minimized.

Copy link
Owner Author

@noamross noamross commented Aug 21, 2018

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

This comment has been minimized.

Copy link
Owner Author

@noamross 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