Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
7cbb7de
[common-utils] - append shell history functionality - #1026
gauravsaini04 Oct 22, 2024
412d221
Merge branch 'devcontainers:main' into features_#1026_shellhistory_in…
gauravsaini04 Oct 24, 2024
3076345
[common-utils] - added working shell history preserving logic for onl…
gauravsaini04 Nov 3, 2024
76d048b
change to mounts formatting
gauravsaini04 Nov 3, 2024
192e4f0
changes as suggested
gauravsaini04 Nov 5, 2024
930050d
changed path of source for bind mount
gauravsaini04 Nov 5, 2024
6970923
changes to path yet again for source of bind mount
gauravsaini04 Nov 5, 2024
5c7b513
change
gauravsaini04 Nov 5, 2024
753ab15
point to correct source dir
gauravsaini04 Nov 5, 2024
d21cc08
small change to path of source file
gauravsaini04 Nov 5, 2024
e48c1c0
change
gauravsaini04 Nov 5, 2024
10747ff
check root folder
gauravsaini04 Nov 5, 2024
581e5eb
change
gauravsaini04 Nov 5, 2024
54119e3
misc
gauravsaini04 Nov 5, 2024
dd34103
path correction final
gauravsaini04 Nov 5, 2024
ba649cf
change
gauravsaini04 Nov 5, 2024
c1b37fa
try
gauravsaini04 Nov 5, 2024
c227dc8
c
gauravsaini04 Nov 5, 2024
1de5f38
s
gauravsaini04 Nov 5, 2024
50ff6d2
hi
gauravsaini04 Nov 5, 2024
129f6bf
fin
gauravsaini04 Nov 5, 2024
c7c5aa8
c
gauravsaini04 Nov 5, 2024
3f1e7c9
Update devcontainer-feature.json
gauravsaini04 Nov 6, 2024
be92e63
giving due permissions before mounts is called for file move
gauravsaini04 Nov 8, 2024
dec0296
few changes
gauravsaini04 Nov 14, 2024
261428f
change
gauravsaini04 Nov 14, 2024
d6ba404
Merge branch 'devcontainers:main' into features_#1026_shellhistory_in…
Kaniska244 Dec 6, 2024
8406068
Updated shell history changes for PR#1157
Kaniska244 Dec 6, 2024
f8a5099
Updated shell history test scenarios in allow_shell_history.sh file
Kaniska244 Dec 10, 2024
ddcf3ae
Correcting the devcontainer-feature.json file
Kaniska244 Dec 10, 2024
f95f1f6
Fixing allow_shell_history issue
Kaniska244 Dec 10, 2024
eaa03c2
few changes for check correction
gauravsaini04 Dec 12, 2024
6c12229
misc change
gauravsaini04 Dec 13, 2024
c081194
misc change
gauravsaini04 Dec 13, 2024
da0ae0e
misc change for docker commands to work in test case
gauravsaini04 Dec 13, 2024
abac4e4
misc changes
gauravsaini04 Dec 13, 2024
aac0274
Merge branch 'main' into features_#1026_shellhistory_in_common-utils_…
gauravsaini04 Jan 28, 2025
e2c56d1
Merge branch 'main' into features_#1026_shellhistory_in_common-utils_…
gauravsaini04 Jan 29, 2025
6297c84
Merge branch 'main' into features_#1026_shellhistory_in_common-utils_…
sireeshajonnalagadda Sep 8, 2025
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions src/common-utils/devcontainer-feature.json
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,18 @@
"type": "boolean",
"default": false,
"description": "Add packages from non-free Debian repository? (Debian only)"
},
"allowShellHistory": {
"type": "boolean",
"default": false,
"description": "Preserve shell history across dev container instances? (Currently supports bash, zsh, and fish)"
}
},
"mounts": [
{
"source": "${devcontainerId}-shellhistory",
"target": "/dc/shellhistory",
"type": "volume"
}
}
}
]
}
50 changes: 50 additions & 0 deletions src/common-utils/main.sh
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ USERNAME="${USERNAME:-"automatic"}"
USER_UID="${USERUID:-"automatic"}"
USER_GID="${USERGID:-"automatic"}"
ADD_NON_FREE_PACKAGES="${NONFREEPACKAGES:-"false"}"
ALLOW_SHELL_HISTORY="${ALLOWSHELLHISTORY:-"false"}"

MARKER_FILE="/usr/local/etc/vscode-dev-containers/common"

Expand Down Expand Up @@ -567,6 +568,55 @@ if [ "${INSTALL_ZSH}" = "true" ]; then
fi
fi

# *********************************
# ** Enable shell history **
# *********************************
#
# Generally, the installation favours configuring a shell to use the mounted volume
# for storing history rather than symlinking as any operation to recreate files
# could delete the symlink.
# On shells where this isn't possible, we symlink as a fallback.
#

if [ "${ALLOW_SHELL_HISTORY}" = "true" ]; then
# Set HISTFILE for bash
cat << EOF >> "${user_home}/.bashrc"
if [[ -z "\$HISTFILE_OLD" ]]; then
export HISTFILE_OLD=\$HISTFILE
fi
export HISTFILE=/dc/shellhistory/.bash_history
export PROMPT_COMMAND='history -a'
sudo chown -R $USERNAME /dc/shellhistory
EOF
chown -R $USERNAME ${user_home}/.bashrc

if [ "${INSTALL_ZSH}" = "true" ]; then
# Set HISTFILE for zsh
cat << EOF >> "${user_home}/.zshrc"
export HISTFILE=/dc/shellhistory/.zsh_history
export PROMPT_COMMAND='history -a'
sudo chown -R $USERNAME /dc/shellhistory
EOF
chown -R $USERNAME ${user_home}/.zshrc
fi

# Create symlink for fish
mkdir -p ${user_home}/.config/fish
cat << EOF >> "${user_home}/.config/fish/config.fish"
if test -z "\$XDG_DATA_HOME"
set history_location ~/.local/share/fish/fish_history
else
set history_location \$XDG_DATA_HOME/fish/fish_history
end
if test -f \$history_location
mv \$history_location "\$history_location-old"
end
ln -s /dc/shellhistory/fish_history \$history_location
sudo chown -R $USERNAME \$history_location
EOF
chown -R $USERNAME ${user_home}/.config/
fi

# *********************************
# ** Ensure config directory **
# *********************************
Expand Down
17 changes: 17 additions & 0 deletions test/common-utils/allow_shell_history.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
#!/bin/bash

set -e

# Optional: Import test library
source dev-container-features-test-lib

# Definition specific tests
check "default-shell-is-zsh" bash -c "getent passwd $(whoami) | awk -F: '{ print $7 }' | grep '/bin/zsh'"
# check it overrides the ~/.zshrc with default dev containers template
check "default-zshrc-is-dev-container-template" bash -c "cat ~/.zshrc | grep ZSH_THEME | grep devcontainers"
check "zsh-path-contains-local-bin" zsh -l -c "echo $PATH | grep '/home/devcontainer/.local/bin'"

check "Ensure .zprofile is owned by remoteUser" bash -c "stat -c '%U' /home/devcontainer/.zprofile | grep devcontainer"

# Report result
reportResults
10 changes: 10 additions & 0 deletions test/common-utils/scenarios.json
Original file line number Diff line number Diff line change
Expand Up @@ -292,5 +292,15 @@
"features": {
"common-utils": {}
}
},
"allow_shell_history": {
"image": "debian:bookworm",
"features": {
"common-utils": {
"installZsh": true,
"configureZshAsDefaultShell": true,
"allowShellHistory": true
}
}
}
}