Skip to content

Commit

Permalink
Merge pull request #7 from braun-daniel/feature/fzf
Browse files Browse the repository at this point in the history
Feature/fzf
  • Loading branch information
braun-daniel authored Oct 10, 2024
2 parents 35593f7 + 2df96ca commit 20ff8b7
Show file tree
Hide file tree
Showing 7 changed files with 54 additions and 137 deletions.
33 changes: 2 additions & 31 deletions src/asciidoc/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,37 +1,8 @@
{
"name": "AsciiDoc",
"id": "asciidoc",
"version": "1.1.0",
"description": "Installs AsciiDoctor, Asciidoctor PDF and AsciiDoctor Diagram.",
"options": {
"asciidoctorVersion": {
"type": "string",
"default": "latest",
"proposals": [
"latest",
"2.0.23"
],
"description": "Version of AsciiDoctor to install. Use 'latest' for the most recent version."
},
"asciidoctorPdfVersion": {
"type": "string",
"default": "latest",
"proposals": [
"latest",
"2.3"
],
"description": "Version of Asciidoctor PDF to install. Use 'latest' for the most recent version."
},
"asciidoctorDiagramVersion": {
"type": "string",
"default": "latest",
"proposals": [
"latest",
"2.3.1"
],
"description": "Version of Asciidoctor Diagram to install. Use 'latest' for the most recent version."
}
},
"version": "1.3.0",
"description": "Installs asciidoctor, asciidoctor-pdf, asciidoctor-diagram and asciidoctor-kroki via. gem.",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
]
Expand Down
91 changes: 10 additions & 81 deletions src/asciidoc/install.sh
Original file line number Diff line number Diff line change
@@ -1,88 +1,17 @@
#!/usr/bin/env bash
# This script installs AsciiDoc and all necessary tools for a DevContainer feature.
# This script installs AsciiDoctor and related tools for a DevContainer feature.

# Exit script on any error
set -e

# Default version for AsciiDoctor (if not specified)
ASCIIDOCTOR_VERSION="${ASCIIDOCTOR_VERSION:-latest}"
# Update package lists and install Ruby
echo "Updating package lists and installing Ruby..."
apt-get update -y && apt-get install -y ruby

# Default version for AsciiDoctor PDF (if not specified)
ASCIIDOCTOR_PDF_VERSION="${ASCIIDOCTOR_PDF_VERSION:-latest}"
# Install RubyGems
echo "Installing AsciiDoctor and related gems..."
gem install asciidoctor asciidoctor-pdf asciidoctor-diagram asciidoctor-kroki

# Default version for AsciiDoctor Diagram (if not specified)
ASCIIDOCTOR_DIAGRAM_VERSION="${ASCIIDOCTOR_DIAGRAM_VERSION:-latest}"

# Function to install system dependencies
install_dependencies() {
echo "Updating package lists..."
apt-get update -y

echo "Installing essential dependencies..."
apt-get install -y \
ruby
}

# Function to install AsciiDoctor (optional faster alternative)
install_asciidoctor() {
if [ "$ASCIIDOCTOR_VERSION" = "latest" ]; then
echo "Installing the latest version of AsciiDoctor via RubyGems..."
gem install asciidoctor
else
echo "Installing AsciiDoctor (version $ASCIIDOCTOR_VERSION) via RubyGems..."
gem install asciidoctor -v "$ASCIIDOCTOR_VERSION"
fi
}

# Function to install AsciiDoctor PDF (optional faster alternative)
install_asciidoctor_pdf() {
if [ "$ASCIIDOCTOR_PDF_VERSION" = "latest" ]; then
echo "Installing the latest version of AsciiDoctor PDF via RubyGems..."
gem install asciidoctor-pdf
else
echo "Installing AsciiDoctor PDF (version $ASCIIDOCTOR_PDF_VERSION) via RubyGems..."
gem install asciidoctor-pdf -v "$ASCIIDOCTOR_PDF_VERSION"
fi
}

# Function to install AsciiDoctor Diagram (optional faster alternative)
install_asciidoctor_diagram() {
if [ "$ASCIIDOCTOR_DIAGRAM_VERSION" = "latest" ]; then
echo "Installing the latest version of AsciiDoctor Diagram via RubyGems..."
gem install asciidoctor-diagram
else
echo "Installing AsciiDoctor Diagram (version $ASCIIDOCTOR_DIAGRAM_VERSION) via RubyGems..."
gem install asciidoctor-diagram -v "$ASCIIDOCTOR_DIAGRAM_VERSION"
fi
}

# Function to clean up after installation
cleanup() {
echo "Cleaning up unnecessary packages and cache..."
apt-get autoremove -y
apt-get clean
rm -rf /var/lib/apt/lists/*
}

# Main installation process
install_dependencies
install_asciidoctor
install_asciidoctor_pdf
install_asciidoctor_diagram
cleanup

# Verification of the installations
echo "Verifying installation..."
if command -v asciidoctor >/dev/null 2>&1; then
echo "AsciiDoctor installed successfully."
else
echo "Error: AsciiDoctor installation failed." >&2
exit 1
fi

if command -v asciidoctor-pdf >/dev/null 2>&1; then
echo "AsciiDoctor PDF installed successfully."
else
echo "Error: AsciiDoctor PDF installation failed." >&2
exit 1
fi
# Clean up unnecessary packages and cache
echo "Cleaning up unnecessary packages and cache..."
apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*
2 changes: 1 addition & 1 deletion src/fzf/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "fzf",
"id": "fzf",
"version": "0.0.1",
"version": "0.0.2",
"description": "Installs fzf - a command line fuzzy search.",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
Expand Down
42 changes: 20 additions & 22 deletions src/fzf/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,40 +4,38 @@
# Exit script on any error
set -e

# Update package lists and install fzf
echo "Updating package lists and installing fzf..."
apt-get update -y && apt-get install -y fzf

# Clean up unnecessary packages and cache
echo "Cleaning up unnecessary packages and cache..."
apt-get autoremove -y && apt-get clean && rm -rf /var/lib/apt/lists/*

# Verify the installation
echo "Verifying installation..."
if command -v fzf --version >/dev/null 2>&1; then
echo "fzf installed successfully."
else
echo "Error: fzf installation failed." >&2
exit 1
fi
# Determine the remote user (typically non-root, like vscode or devuser)
REMOTE_USER="${_REMOTE_USER:-root}"

# Clone the fzf repository into the remote user's home directory
echo "Cloning fzf repository..."
git clone --depth 1 https://github.com/junegunn/fzf.git "$REMOTE_USER_HOME/.fzf"

# Run the fzf install script
echo "Running fzf install script..."
"$REMOTE_USER_HOME/.fzf/install"

# Home directory of the remote user
USER_HOME="/home/${REMOTE_USER}"

# Set up fzf key bindings and fuzzy completion for bash
if [ -n "$BASH_VERSION" ]; then
echo "Setting up fzf key bindings and fuzzy completion for bash..."
echo 'eval "$(fzf --bash)"' >> ~/.bashrc
source ~/.bashrc
echo 'eval "$(fzf --bash)"' >> "${USER_HOME}/.bashrc"
chown "${REMOTE_USER}:${REMOTE_USER}" "${USER_HOME}/.bashrc"
fi

# Set up fzf key bindings and fuzzy completion for zsh
if [ -n "$ZSH_VERSION" ]; then
echo "Setting up fzf key bindings and fuzzy completion for zsh..."
echo 'source <(fzf --zsh)' >> ~/.zshrc
source ~/.zshrc
echo 'source <(fzf --zsh)' >> "${USER_HOME}/.zshrc"
chown "${REMOTE_USER}:${REMOTE_USER}" "${USER_HOME}/.zshrc"
fi

# Set up fzf key bindings for fish
if [ -n "$FISH_VERSION" ]; then
echo "Setting up fzf key bindings for fish..."
echo 'fzf --fish | source' >> ~/.config/fish/config.fish
source ~/.config/fish/config.fish
mkdir -p "${USER_HOME}/.config/fish"
echo 'fzf --fish | source' >> "${USER_HOME}/.config/fish/config.fish"
chown -R "${REMOTE_USER}:${REMOTE_USER}" "${USER_HOME}/.config/fish"
fi
2 changes: 1 addition & 1 deletion src/spaceship/devcontainer-feature.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "Spaceship",
"id": "spaceship",
"version": "0.0.1",
"version": "0.0.2",
"description": "Installs spaceship-prompt.",
"installsAfter": [
"ghcr.io/devcontainers/features/common-utils"
Expand Down
8 changes: 7 additions & 1 deletion src/spaceship/install.sh
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,12 @@
# Exit script on any error
set -e

# Check if zsh is installed
if ! command -v zsh > /dev/null; then
echo "Zsh is not installed. Please install zsh before running this script."
exit 1
fi

# Ensure the DevContainer user's home directory is used
DEVCONTAINER_HOME="${HOME}"

Expand All @@ -14,4 +20,4 @@ mkdir -p "$DEVCONTAINER_HOME/.zsh"
git clone --depth=1 https://github.com/spaceship-prompt/spaceship-prompt.git "$DEVCONTAINER_HOME/.zsh/spaceship"

# Make sure the spaceship-prompt is permanently sourced in the .zshrc file
echo 'source "$HOME/.zsh/spaceship/spaceship.zsh"' >> "$DEVCONTAINER_HOME/.zshrc"
echo 'source "$DEVCONTAINER_HOME/.zsh/spaceship/spaceship.zsh"' >> "$DEVCONTAINER_HOME/.zshrc"
13 changes: 13 additions & 0 deletions test/fzf/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,18 @@ source dev-container-features-test-lib
# Definition specific tests
check "check for fzf" fzf --version

# Depending on the shell (bash, zsh, fish), check if the config was added to the profiles
if [ -n "$BASH_VERSION" ]; then
check "check for fzf key bindings and fuzzy completion for bash" grep -q 'eval "$(fzf --bash)"' "${USER_HOME}/.bashrc"
fi

if [ -n "$ZSH_VERSION" ]; then
check "check for fzf key bindings and fuzzy completion for zsh" grep -q 'source <(fzf --zsh)' "${USER_HOME}/.zshrc"
fi

if [ -n "$FISH_VERSION" ]; then
check "check for fzf key bindings for fish" grep -q 'fzf --fish | source' "${USER_HOME}/.config/fish/config.fish"
fi

# Report result
reportResults

0 comments on commit 20ff8b7

Please sign in to comment.