fish dev function 3 with exports working
This commit is contained in:
@@ -0,0 +1,3 @@
|
|||||||
|
function dev-remove
|
||||||
|
distrobox rm --force dev
|
||||||
|
end
|
||||||
@@ -36,48 +36,16 @@ function dev
|
|||||||
|
|
||||||
echo "Creating Distrobox container '$name'..."
|
echo "Creating Distrobox container '$name'..."
|
||||||
|
|
||||||
set -l init_hook '
|
|
||||||
set -e
|
|
||||||
|
|
||||||
echo "Initializing development environment..."
|
|
||||||
|
|
||||||
sudo mkdir -p /opt/rustup /opt/cargo
|
|
||||||
sudo chown -R $USER:$USER /opt/rustup /opt/cargo
|
|
||||||
|
|
||||||
sudo mkdir -p /etc/fish/conf.d /etc/fish/completions
|
|
||||||
|
|
||||||
printf "%s\n" \
|
|
||||||
"set -gx RUSTUP_HOME /opt/rustup" \
|
|
||||||
"set -gx CARGO_HOME /opt/cargo" \
|
|
||||||
"fish_add_path \$CARGO_HOME/bin /home/user/.local/bin" \
|
|
||||||
| sudo tee /etc/fish/conf.d/rust.fish >/dev/null
|
|
||||||
|
|
||||||
export RUSTUP_HOME=/opt/rustup
|
|
||||||
export CARGO_HOME=/opt/cargo
|
|
||||||
|
|
||||||
curl --proto "=https" \
|
|
||||||
--tlsv1.2 \
|
|
||||||
-sSf https://sh.rustup.rs \
|
|
||||||
| sh -s -- -y --no-modify-path
|
|
||||||
|
|
||||||
/opt/cargo/bin/rustup default stable
|
|
||||||
|
|
||||||
/opt/cargo/bin/rustup completions fish \
|
|
||||||
| sudo tee /etc/fish/completions/rustup.fish >/dev/null
|
|
||||||
|
|
||||||
echo "Development environment initialized successfully."
|
|
||||||
'
|
|
||||||
|
|
||||||
distrobox create \
|
distrobox create \
|
||||||
--name $name \
|
--name $name \
|
||||||
--image $image --yes \
|
--image $image --yes \
|
||||||
--additional-packages (string join ' ' $packages) \
|
--additional-packages (string join ' ' $packages) \
|
||||||
--init-hooks "$init_hook"
|
--init-hooks 'bash "$HOME/.scripts/distrobox-dev-init.sh"'
|
||||||
|
|
||||||
if test $status -ne 0
|
if test $status -ne 0
|
||||||
echo "Failed to create container '$name'." >&2
|
echo "Failed to create container '$name'." >&2
|
||||||
return 1
|
return 1
|
||||||
end
|
end
|
||||||
|
|
||||||
distrobox enter $name
|
distrobox enter $name --verbose
|
||||||
end
|
end
|
||||||
|
|||||||
@@ -0,0 +1,123 @@
|
|||||||
|
#!/usr/bin/env bash
|
||||||
|
|
||||||
|
set -euo pipefail
|
||||||
|
|
||||||
|
echo "Initializing development environment..."
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Rust directories
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
mkdir -p /opt/rustup /opt/cargo
|
||||||
|
chown "$(id -u):$(id -g)" /opt/rustup /opt/cargo
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Fish configuration
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
mkdir -p /etc/fish/conf.d
|
||||||
|
mkdir -p /etc/fish/completions
|
||||||
|
|
||||||
|
tee /etc/fish/conf.d/rust.fish >/dev/null <<'EOF'
|
||||||
|
set -gx RUSTUP_HOME /opt/rustup
|
||||||
|
set -gx CARGO_HOME /opt/cargo
|
||||||
|
fish_add_path $CARGO_HOME/bin
|
||||||
|
EOF
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Rustup
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
export RUSTUP_HOME=/opt/rustup
|
||||||
|
export CARGO_HOME=/opt/cargo
|
||||||
|
|
||||||
|
echo "Installing rustup..."
|
||||||
|
|
||||||
|
curl \
|
||||||
|
--proto '=https' \
|
||||||
|
--tlsv1.2 \
|
||||||
|
-sSf \
|
||||||
|
https://sh.rustup.rs \
|
||||||
|
| sh -s -- -y --no-modify-path
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Rust toolchain
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
echo "Installing stable Rust toolchain..."
|
||||||
|
|
||||||
|
/opt/cargo/bin/rustup default stable
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Fish completions
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
echo "Installing rustup Fish completion..."
|
||||||
|
|
||||||
|
/opt/cargo/bin/rustup completions fish \
|
||||||
|
| tee /etc/fish/completions/rustup.fish >/dev/null
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Export Rust development tools to the host
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
export PATH="/opt/cargo/bin:$PATH"
|
||||||
|
echo "Exporting development tools..."
|
||||||
|
|
||||||
|
DEV_HOME="$HOME"
|
||||||
|
DEV_USER="$(basename "$DEV_HOME")"
|
||||||
|
|
||||||
|
export_bin() {
|
||||||
|
local binary="$1"
|
||||||
|
|
||||||
|
if command -v "$binary" >/dev/null 2>&1; then
|
||||||
|
echo " exporting $binary"
|
||||||
|
sudo -u "$DEV_USER" \
|
||||||
|
env HOME="$DEV_HOME" \
|
||||||
|
distrobox-export \
|
||||||
|
--bin "$(command -v "$binary")" \
|
||||||
|
--export-path "$DEV_HOME/.local/bin"
|
||||||
|
else
|
||||||
|
echo " warning: $binary not found"
|
||||||
|
fi
|
||||||
|
}
|
||||||
|
|
||||||
|
# Rust
|
||||||
|
for binary in \
|
||||||
|
cargo \
|
||||||
|
cargo-clippy \
|
||||||
|
cargo-fmt \
|
||||||
|
cargo-miri \
|
||||||
|
clippy-driver \
|
||||||
|
rls \
|
||||||
|
rust-analyzer \
|
||||||
|
rustc \
|
||||||
|
rustdoc \
|
||||||
|
rustfmt \
|
||||||
|
rust-gdb \
|
||||||
|
rust-gdbgui \
|
||||||
|
rust-lldb \
|
||||||
|
rustup
|
||||||
|
do
|
||||||
|
export_bin "$binary"
|
||||||
|
done
|
||||||
|
|
||||||
|
# Native toolchain
|
||||||
|
export_bin clang
|
||||||
|
export_bin clang++
|
||||||
|
export_bin cmake
|
||||||
|
export_bin lld
|
||||||
|
export_bin ld.lld
|
||||||
|
export_bin gdb
|
||||||
|
export_bin strace
|
||||||
|
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
# Done
|
||||||
|
# -----------------------------------------------------------------------------
|
||||||
|
|
||||||
|
echo
|
||||||
|
echo "Development environment initialized successfully."
|
||||||
|
echo
|
||||||
|
echo "Rust:"
|
||||||
|
/opt/cargo/bin/rustc --version
|
||||||
|
/opt/cargo/bin/cargo --version
|
||||||
|
/opt/cargo/bin/rustup --version
|
||||||
Reference in New Issue
Block a user