Skip to content

Commit

Permalink
New Feature: R history
Browse files Browse the repository at this point in the history
  • Loading branch information
eitsupi committed Sep 4, 2023
1 parent eb86653 commit 06841eb
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .github/workflows/test.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ jobs:
pandoc: ./**/pandoc/**
quarto-cli: ./**/quarto-cli/**
r-apt: ./**/r-apt/**
r-history: ./**/r-history/**
r-packages: ./**/r-packages/**
r-rig: ./**/r-rig/**
renv-cache: ./**/renv-cache/**
Expand Down Expand Up @@ -89,6 +90,7 @@ jobs:
- pandoc
- quarto-cli
- r-apt
- r-history
- r-packages
- r-rig
- renv-cache
Expand Down Expand Up @@ -119,6 +121,7 @@ jobs:
- pandoc
- quarto-cli
- r-apt
- r-history
- r-packages
- r-rig
- renv-cache
Expand Down
24 changes: 24 additions & 0 deletions src/r-history/devcontainer-feature.json
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.",
"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": {
"radian-history-setup": "/usr/local/share/rocker-devcontainer-features/r-history/scripts/oncreate.sh"
},
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
}
35 changes: 35 additions & 0 deletions src/r-history/install.sh
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!"
21 changes: 21 additions & 0 deletions src/r-history/oncreate.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
#!/usr/bin/env bash

set -e

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!"
}

set_radian_history
12 changes: 12 additions & 0 deletions test/r-history/test.sh
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" bash -c 'find /dc/r-history/*'

# Report result
reportResults

0 comments on commit 06841eb

Please sign in to comment.