generated from devcontainers/feature-starter
-
Notifications
You must be signed in to change notification settings - Fork 15
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Close #190
- Loading branch information
Showing
6 changed files
with
130 additions
and
0 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
<!-- markdownlint-disable MD041 --> | ||
|
||
## Acknowledgements | ||
|
||
This Feature is inspired by | ||
[`ghcr.io/stuartleeks/dev-container-features/shell-history`](https://github.com/stuartleeks/dev-container-features/tree/main/src/shell-history). |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
{ | ||
"name": "R history", | ||
"id": "r-history", | ||
"version": "0.1.0", | ||
"description": "Preserve R terminal history across Dev Container instances. Supports Radian and RStudio Server integrated terminal.", | ||
"documentationURL": "https://github.com/rocker-org/devcontainer-features/tree/main/src/r-history", | ||
"options": {}, | ||
"containerEnv": { | ||
"R_HISTFILE": "/dc/r-history/.Rhistory" | ||
}, | ||
"mounts": [ | ||
{ | ||
"source": "${devcontainerId}-r-history", | ||
"target": "/dc/r-history", | ||
"type": "volume" | ||
} | ||
], | ||
"onCreateCommand": { | ||
"r-history-setup": "/usr/local/share/rocker-devcontainer-features/r-history/scripts/oncreate.sh" | ||
}, | ||
"installsAfter": [ | ||
"ghcr.io/devcontainers/features/common-utils" | ||
] | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
#!/bin/sh | ||
|
||
USERNAME=${USERNAME:-${_REMOTE_USER}} | ||
|
||
LIFECYCLE_SCRIPTS_DIR="/usr/local/share/rocker-devcontainer-features/r-history/scripts" | ||
|
||
set -e | ||
|
||
create_cache_dir() { | ||
if [ -d "$1" ]; then | ||
echo "Cache directory $1 already exists. Skip creation..." | ||
else | ||
echo "Create cache directory $1..." | ||
mkdir -p "$1" | ||
fi | ||
|
||
if [ -z "$2" ]; then | ||
echo "No username provided. Skip chown..." | ||
else | ||
echo "Change owner of $1 to $2..." | ||
chown -R "$2:$2" "$1" | ||
fi | ||
} | ||
|
||
export DEBIAN_FRONTEND=noninteractive | ||
|
||
create_cache_dir "/dc/r-history" "${USERNAME}" | ||
|
||
# Set Lifecycle scripts | ||
if [ -f oncreate.sh ]; then | ||
mkdir -p "${LIFECYCLE_SCRIPTS_DIR}" | ||
cp oncreate.sh "${LIFECYCLE_SCRIPTS_DIR}/oncreate.sh" | ||
fi | ||
|
||
echo "Done!" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
fix_permissions() { | ||
local dir | ||
dir="${1}" | ||
|
||
if [ ! -w "${dir}" ]; then | ||
echo "Fixing permissions of '${dir}'..." | ||
sudo chown -R "$(id -u):$(id -g)" "${dir}" | ||
echo "Done!" | ||
else | ||
echo "Permissions of '${dir}' are OK!" | ||
fi | ||
} | ||
|
||
set_renviron() { | ||
local renviron_file | ||
|
||
if [ -n "${R_ENVIRON}" ]; then | ||
renviron_file="${R_ENVIRON}" | ||
else | ||
renviron_file="${HOME}/.Renviron" | ||
fi | ||
|
||
echo "Updating '${renviron_file}'..." | ||
echo "R_HISTFILE=${R_HISTFILE}" >>"${renviron_file}" | ||
echo "Done!" | ||
} | ||
|
||
set_radian_history() { | ||
local radian_profile_dir | ||
|
||
if [ -n "${XDG_CONFIG_HOME}" ]; then | ||
radian_profile_dir="${XDG_CONFIG_HOME}/radian" | ||
else | ||
radian_profile_dir="${HOME}/.config/radian" | ||
fi | ||
|
||
mkdir -p "${radian_profile_dir}" | ||
|
||
echo "Updating '${radian_profile_dir}/profile'..." | ||
echo 'options(radian.global_history_file = "/dc/r-history/.radian_history")' >>"${radian_profile_dir}/profile" | ||
echo "Done!" | ||
} | ||
|
||
fix_permissions "/dc/r-history" | ||
set_renviron | ||
set_radian_history |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
#!/usr/bin/env bash | ||
|
||
set -e | ||
|
||
# Optional: Import test library bundled with the devcontainer CLI | ||
source dev-container-features-test-lib | ||
|
||
# Feature-specific tests | ||
check "cache dir permission" bash -c "test -w /dc/r-history/" | ||
|
||
# Report result | ||
reportResults |