Skip to content

Commit eb2d04f

Browse files
authored
Merge pull request #2 from gilesknap/ci2
Full fat CI
2 parents 0ed28a3 + 9034708 commit eb2d04f

File tree

16 files changed

+184
-54
lines changed

16 files changed

+184
-54
lines changed

.devcontainer/devcontainer.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@
3434
],
3535
// Mount the parent as /workspaces so we can pip install peers as editable
3636
"workspaceMount": "source=${localWorkspaceFolder}/..,target=/workspaces,type=bind",
37-
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/devcontainer_rc",
37+
// Create the config folder for the bash-config feature
38+
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/bash-config",
3839
"remoteUser": "root"
3940
}

.devcontainer/features/bash-config/README.md

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,30 @@
1-
# Lightweight, Configurable BASH Eternal History
1+
# Lightweight, Configurable BASH Config with Eternal History
22

3-
## Defaults
3+
Intended as a lightweight alternative to common-utils.
44

5-
The default, opinionated configuration is defined in
6-
`$HOME/.config/bash-config/bash-config-rc` and includes the following:
5+
## Installation
6+
7+
To use this feature in an individual devcontainer, add the following to your `.devcontainer/devcontainer.json`:
8+
9+
```json
10+
"features": {
11+
"ghcr.io/diamondlightsource/devcontainer-features/bash-config:1": {}
12+
},
13+
"initializeCommand": "mkdir -p ${localEnv:HOME}/.config/bash-config",
14+
```
15+
16+
The initializeCommand is required to create the directory for the bash-config folder in your home folder on the host, the very first time this is executed. Features do not have an InitializeCommand, so the devcontainer.json must do this.
17+
18+
19+
## features
20+
21+
The default, opinionated configuration can be found in `$HOME/.config/bash-config/bash-config-rc` and includes the following:
722

823
- Persistent history across all devcontainers that use this feature
924
- The MS devcontainer bash prompt with git branch and status
1025
- history search with up/down arrows (.inputrc)
1126
- ctrl-left or right arrow for word navigation (.inputrc)
27+
- git autocomplete
1228

1329
## Customisation
1430

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
# bash-config configuration files
2+
3+
## introduction
4+
5+
The files in this folder are copied out of the bash-config feature and
6+
into the users config folder on the host at ~/.config/bash-config
7+
8+
## files
9+
10+
- bashrc: The entry point for the bash-config feature. User editable
11+
- inputrc: The readline configuration file. User editable
12+
- bash-config-rc: The configuration file for the bash-config feature. Not
13+
user editable. Replaced with the latest version on each rebuild of the
14+
developer container.
15+
16+
## Stages
17+
18+
1. At build time all the files in this folder are copied to a staging folder
19+
in the container filesystem.
20+
1. At container runtime the files are copied from the staging folder to the
21+
users config folder on the host.
22+
1. The file onCreateCommand.sh is executed at container creation time in order
23+
to facilitate the above copy.
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
#!/bin/bash
2+
3+
# default opinioned bash configuration
4+
5+
# set the prompt
6+
export PS1="\[\033[1;34m\]\W \[\033[0m\]# "
7+
8+
# enable enternal shared history
9+
export HISTCONTROL=ignoreboth:erasedups
10+
export HISTSIZE=-1
11+
export HISTFILESIZE=-1
12+
export SAVEHIST=-1
13+
export HISTFILE=$CONFIG_FOLDER/.bash_eternal_history
14+
15+
# bash theme - partly inspired by https://github.com/ohmyzsh/ohmyzsh/blob/master/themes/robbyrussell.zsh-theme
16+
# from https://github.com/devcontainers/features/blob/main/src/common-utils/scripts/bash_theme_snippet.sh
17+
__bash_prompt() {
18+
local userpart='`export XIT=$? \
19+
&& [ ! -z "${GITHUB_USER:-}" ] && echo -n "\[\033[0;32m\]@${GITHUB_USER:-} " || echo -n "\[\033[0;32m\]\u " \
20+
&& [ "$XIT" -ne "0" ] && echo -n "\[\033[1;31m\]➜" || echo -n "\[\033[0m\]➜"`'
21+
local gitbranch='`\
22+
if [ "$(git config --get devcontainers-theme.hide-status 2>/dev/null)" != 1 ] && [ "$(git config --get codespaces-theme.hide-status 2>/dev/null)" != 1 ]; then \
23+
export BRANCH="$(git --no-optional-locks symbolic-ref --short HEAD 2>/dev/null || git --no-optional-locks rev-parse --short HEAD 2>/dev/null)"; \
24+
if [ "${BRANCH:-}" != "" ]; then \
25+
echo -n "\[\033[0;36m\](\[\033[1;31m\]${BRANCH:-}" \
26+
&& if [ "$(git config --get devcontainers-theme.show-dirty 2>/dev/null)" = 1 ] && \
27+
git --no-optional-locks ls-files --error-unmatch -m --directory --no-empty-directory -o --exclude-standard ":/*" > /dev/null 2>&1; then \
28+
echo -n " \[\033[1;33m\]✗"; \
29+
fi \
30+
&& echo -n "\[\033[0;36m\]) "; \
31+
fi; \
32+
fi`'
33+
local lightblue='\[\033[1;34m\]'
34+
local removecolor='\[\033[0m\]'
35+
PS1="${userpart} ${lightblue}\w ${gitbranch}${removecolor}\$ "
36+
unset -f __bash_prompt
37+
}
38+
__bash_prompt
39+
export PROMPT_DIRTRIM=4
40+
41+
# enable bash completion for git
42+
if [[ -f /usr/share/bash-completion/completions/git ]]; then
43+
source /usr/share/bash-completion/completions/git
44+
elif [[ -f /etc/bash_completion.d/git ]]; then
45+
source /etc/bash_completion.d/git
46+
fi

.devcontainer/features/bash-config/bashrc renamed to .devcontainer/features/bash-config/config/bashrc

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
# This file is initialized by bash-config, but you are then free to edit it
88

99
# execute default, opinionated settings - delete this line to remove defaults
10-
source $CONFIG_FOLDER/feature_settings_rc
10+
source $CONFIG_FOLDER/bash-config-rc
1111

12-
# add your personal custom settings below
12+
if [ ! -f /one-time ]; then
13+
14+
# add your personal one time only (container creation) commands here
15+
16+
touch /one-time
17+
fi
18+
19+
# add your personal settings for every shell below
File renamed without changes.

.devcontainer/features/bash-config/onCreateCommand.sh renamed to .devcontainer/features/bash-config/config/onCreateCommand.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# this script is run once inside the developer container at creation time
44

55
# copy in the opinionated default settings from the feature
6-
cp $CONFIG_STAGING/feature_settings_rc $CONFIG_FOLDER/feature_settings_rc
6+
cp $CONFIG_STAGING/bash-config-rc $CONFIG_FOLDER
77

88
# copy in the user editable settings unless they already exist
99
if [[ ! -f $CONFIG_FOLDER/bashrc ]] ; then

.devcontainer/features/bash-config/devcontainer-feature.json

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@
77
"description": "Lightweight BASH setup with eternal history and PS1 tweaks. Fully configurable.",
88
"documentationURL": "https://raw.githubusercontent.com/DiamondRC/devcontainer-features/refs/heads/main/.devcontainer/features/bash-config/README.md",
99
"containerEnv": {
10-
"CONFIG_FOLDER": "/devcontainer_rc",
11-
"CONFIG_STAGING": "/devcontainer_staging"
10+
"CONFIG_FOLDER": "/bash-config",
11+
"CONFIG_STAGING": "/bash-config-staging"
1212
},
1313
"mounts": [
1414
{
15-
"source": "${localEnv:HOME}/.config/devcontainer_rc",
16-
"target": "/devcontainer_rc",
15+
"source": "${localEnv:HOME}/.config/bash-config",
16+
"target": "/bash-config",
1717
"type": "bind"
1818
}
1919
],
20-
"onCreateCommand": "bash /devcontainer_staging/onCreateCommand.sh"
20+
"onCreateCommand": "bash /bash-config-staging/onCreateCommand.sh"
2121
}

.devcontainer/features/bash-config/feature_settings_rc

Lines changed: 0 additions & 14 deletions
This file was deleted.

.devcontainer/features/bash-config/install.sh

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
# abort on error
44
set -e
55

6-
# discover where the install.sh and peers have been extracted to
6+
# discover where this install.sh and its peers have been extracted to
77
this_dir="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
88

99

10-
echo "Activating feature 'terminal-history'"
10+
echo "Activating feature 'bash-config'"
1111
echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}"
1212

1313
# This script is run at container build time.
@@ -17,9 +17,8 @@ echo "User: ${_REMOTE_USER} User home: ${_REMOTE_USER_HOME}"
1717
# Then at container runtime, when the hosts' config folder is mounted in, we
1818
# can copy from the staging area to the mounted host folder
1919
#
20-
# The runtime copy to host folder is performed once oby onCreateCommand.sh
20+
# The runtime copy to host folder is performed once only by onCreateCommand.sh
2121

2222
mkdir -p "$CONFIG_STAGING"
23-
cp -r "$this_dir"/* "$CONFIG_STAGING"
24-
echo $this_dir > "$CONFIG_STAGING/this_dir"
23+
cp -r "$this_dir"/config/* "$CONFIG_STAGING"
2524

0 commit comments

Comments
 (0)