Add devcontainer creation alias with nvim config mount. Also add devc-ssh command.

This commit is contained in:
Hans Goor 2024-11-23 16:58:26 +01:00
parent 53dfef6c9e
commit bde737b037
Signed by: eyedevelop
SSH key fingerprint: SHA256:Td89veptDEwCV8J3fjqnknNk7SbwzedYhauyC2nFBYg
4 changed files with 43 additions and 0 deletions

View file

@ -0,0 +1,27 @@
#!/bin/bash
CONTAINER="docker"
if ! command -v docker &>/dev/null; then
CONTAINER="podman"
fi
if [[ "$#" -lt 1 ]]; then
echo "Usage: $0 <container id>" >&2
exit 1
fi
container_id="$1"; shift
# We expect a devcontainer to run an SSH server on 2222/tcp
# and to have this port exposed. We find the host binding
# to SSH to that container.
if ! ssh_port="$(${CONTAINER} inspect --format '{{ (index (index .NetworkSettings.Ports "2222/tcp") 0).HostPort }}' "${container_id}" 2>/dev/null)"; then
echo "[!] Could not get SSH host port for container '${container_id}'" >&2
exit 1
fi
ssh -o UserKnownHostsFile=/dev/null \
-o StrictHostKeyChecking=false \
-p "${ssh_port}" \
dev@localhost "$@"

View file

@ -0,0 +1,9 @@
#!/bin/bash
_devc_ssh() {
if [[ "${#COMP_WORDS[@]}" -eq 2 ]]; then
COMPREPLY=( $(compgen -W "$(docker ps --format '{{ .Names }}' | tr '\n' ' ')" -- "${cur}" ) )
fi
}
complete -F _devc_ssh devc-ssh

View file

@ -112,3 +112,8 @@ if [[ -d "${HOME}/.zshrc.d" ]]; then
source "${ext}"
done
fi
# Custom command completions
if [[ -f "${HOME}/.bash_completion" ]]; then
source "${HOME}"/.bash_completion
fi

View file

@ -8,3 +8,5 @@ function cdp() {
cd -- "$(_cdp_path "$@")"
}
alias devcontainer-nvim="devcontainer up --mount 'type=bind,source=${HOME}/.config/nvim,target=/home/dev/.config/nvim' --workspace-folder ."