Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion src/bash-aliases/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "bash-aliases",
"version": "1.0.3",
"version": "1.0.4",
"name": "Bash Aliases",
"description": "Loads custom bash aliases from your project's `.devcontainer/etc/bash-aliases` directory.",
"dependsOn": {
Expand Down
24 changes: 4 additions & 20 deletions src/bash-aliases/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ UPDATE_RC="${UPDATE_RC:-"true"}"
set -eux
export DEBIAN_FRONTEND=noninteractive

FEATURE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

if [ "$(id -u)" -ne 0 ]; then
echo -e 'Script must be run as root. Use sudo, su, or add "USER root" to your Dockerfile before running this script.'
exit 1
Expand All @@ -22,26 +24,8 @@ updaterc() {
fi
}

# Bash-aliases loader
SNIPPET_CONTENT=$(cat <<'EOF'
# Only runs on terminal from inside vscode editor, or in CI
if [[ ( -t 1 && "${TERM_PROGRAM}" = "vscode" ) || "${CI}" = "true" ]]; then
ALIASES_FOLDER="$PWD/.devcontainer/etc/bash-aliases"

# Dynamically load all *.sh files from ALIASES_FOLDER
if [ -d "$ALIASES_FOLDER" ]; then
for file in "$ALIASES_FOLDER/"*.sh; do
if [ -e "$file" ] && [ -r "$file" ]; then
source "$file"
fi
done
fi
fi
EOF
)

# Install loader
echo "Installing Loader..."
updaterc "${SNIPPET_CONTENT}"
rc_content="$(cat "${FEATURE_DIR}/scripts/rc_snippet.sh")"
updaterc "${rc_content}"

echo "Done!"
13 changes: 13 additions & 0 deletions src/bash-aliases/scripts/rc_snippet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# Only runs on terminal from inside vscode editor, or in CI
if [[ ( -t 1 && "${TERM_PROGRAM}" = "vscode" ) || "${CI}" = "true" ]]; then
ALIASES_FOLDER="$PWD/.devcontainer/etc/bash-aliases"

# Dynamically load all *.sh files from ALIASES_FOLDER
if [ -d "$ALIASES_FOLDER" ]; then
for file in "$ALIASES_FOLDER/"*.sh; do
if [ -e "$file" ] && [ -r "$file" ]; then
source "$file"
fi
done
fi
fi
2 changes: 1 addition & 1 deletion src/uv/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"id": "uv",
"version": "1.0.3",
"version": "1.0.4",
"name": "UV",
"description": "A fast Python package manager written in Rust. Replaces pip, poetry, virtualenv, and more.",
"options": {
Expand Down
14 changes: 5 additions & 9 deletions src/uv/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ USERNAME="${USERNAME:-"${_REMOTE_USER:-"automatic"}"}"
UPDATE_RC="${UPDATE_RC:-"true"}"
UV_INSTALL_DIR="${UV_INSTALL_DIR:-"~/.local/bin"}"

FEATURE_DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"

set -eux
export DEBIAN_FRONTEND=noninteractive

Expand Down Expand Up @@ -66,20 +68,14 @@ if ! uv --version &> /dev/null ; then
# Install dependencies
check_packages curl unzip tar ca-certificates

UV_CACHE_SCRIPT="$(cat << 'EOF'
if [[ ( -t 1 && "${TERM_PROGRAM}" = "vscode" ) || "${CI}" = "true" ]]; then
export UV_CACHE_DIR="$PWD/.uv_cache"
mkdir -p "$UV_CACHE_DIR"
fi
EOF
)"
updaterc "${UV_CACHE_SCRIPT}"
rc_content="$(cat "${FEATURE_DIR}/scripts/rc_snippet.sh")"
updaterc "${rc_content}"

mkdir -p $UV_INSTALL_DIR
chown -R "${USERNAME}:${USERNAME}" "${UV_INSTALL_DIR}"
chmod -R g+r+w "${UV_INSTALL_DIR}"

find "${UV_INSTALL_DIR}" -type d -print0 | xargs -n 1 -0 chmod g+s

echo "Installing UV..."

UV_VERSION=$VERSION
Expand Down
5 changes: 5 additions & 0 deletions src/uv/scripts/rc_snippet.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Only runs on terminal from inside vscode editor
if [ -t 1 ] && [ "${TERM_PROGRAM}" = "vscode" ]; then
export UV_CACHE_DIR="$PWD/.uv_cache"
mkdir -p "$UV_CACHE_DIR"
fi
2 changes: 1 addition & 1 deletion test/bash-aliases/cases/00-test-setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/bash

set -euo pipefail

Expand Down
2 changes: 1 addition & 1 deletion test/bash-aliases/cases/10-test-alias.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/bash

set -euo pipefail

Expand Down
14 changes: 7 additions & 7 deletions test/bash-aliases/cases/20-test-no-aliases-folder.sh
Original file line number Diff line number Diff line change
@@ -1,19 +1,19 @@
#!/bin/zsh
#!/bin/bash

set -euo pipefail

# Import test library bundled with the devcontainer CLI
source dev-container-features-test-lib

# Tests before removing aliases directory
check "directory exists" ls -lha "$ALIASES_DIR"
check "testalias exists" zsh -ic "command -v testalias"
check "testalias works" zsh -ic "testalias"
check "testalias result" zsh -ic "test \"\$(testalias)\" = 'Hello, World!'"
check "directory exists" bash -ic "test -d '$ALIASES_DIR'"
check "testalias exists" bash -ic 'command -v testalias'
check "testalias works" bash -ic 'testalias'
check "testalias result" bash -ic 'test "$(testalias)" = "Hello, World!"'

# Remove aliases directory
rm -rf "$ALIASES_DIR"

# Tests after removing aliases directory
check "directory should NOT exist" test ! -d "$ALIASES_DIR"
check "testalias should NOT exist" test ! -n "$(zsh -ic 'command -v testalias')"
check "directory should NOT exist" bash -ic "test ! -f '$ALIASES_DIR'"
check "testalias should NOT exist" bash -ic 'test ! "$(command -v testalias)"'
2 changes: 1 addition & 1 deletion test/bash-aliases/cases/__before.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/bash

##
# This file runs before each test case.
Expand Down
2 changes: 1 addition & 1 deletion test/bash-aliases/setup.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/bash

set -euo pipefail

Expand Down
7 changes: 3 additions & 4 deletions test/bash-aliases/test.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!/bin/zsh
#!/bin/bash

set -euo pipefail

Expand Down Expand Up @@ -30,11 +30,10 @@ for file in ./cases/*.sh; do
continue
fi

title="$(get_title "$file")"

source ./cases/__before.sh

check "[$title]" zsh -i "$file"
title="$(get_title "$file")"
check "[$title]" bash -i "$file"
done

# Report result
Expand Down
Loading