Created
September 28, 2025 10:46
-
-
Save geotheory/990b6503989753d26eb29fbecfc39cb4 to your computer and use it in GitHub Desktop.
Rstudio - open help in browser (Ubuntu)
This file contains hidden or 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 | |
set -e | |
FILE="/usr/lib/rstudio/resources/app/R/Options.R" | |
TMP_FILE="$(mktemp)" | |
if [ ! -f "$FILE" ]; then | |
echo "Options.R not found at $FILE" | |
exit 1 | |
fi | |
# Idempotent patch: only if block not yet commented | |
if grep -qE '^\s*#\.rs\.setOption\("browser",' "$FILE"; then | |
echo "Block already commented. Nothing to do." | |
exit 0 | |
fi | |
# Comment the specific browseURL block into temporary file | |
awk ' | |
BEGIN {in_block=0} | |
/^\s*\.rs\.setOption\("browser",/ { | |
print "#"$0 | |
in_block=1 | |
next | |
} | |
in_block && /^\s*\{/ { | |
print "#"$0 | |
next | |
} | |
in_block && /^\s*\.Call\("rs_browseURL",/ { | |
print "#"$0 | |
next | |
} | |
in_block && /^\s*\}\)/ { | |
print "#"$0 | |
in_block=0 | |
next | |
} | |
{ print } | |
' "$FILE" > "$TMP_FILE" | |
# Add top comment if not present | |
if ! grep -q "^# custom browseURL implementation." "$TMP_FILE"; then | |
sed -i '1i# custom browseURL implementation.' "$TMP_FILE" | |
fi | |
# Move temp file to original with sudo | |
sudo mv "$TMP_FILE" "$FILE" | |
sudo chmod 644 "$FILE" | |
echo "Patched $FILE successfully." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment