mirror of
https://github.com/m-housh/dotfiles.git
synced 2026-02-14 14:12:41 +00:00
feat: Adds swift-dev script
This commit is contained in:
107
env/.local/scripts/swift-dev
vendored
Executable file
107
env/.local/scripts/swift-dev
vendored
Executable file
@@ -0,0 +1,107 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
set -e
|
||||
set -o nounset
|
||||
set -o pipefail
|
||||
|
||||
SCRIPTS=${SCRIPTS:-$HOME/.local/scripts}
|
||||
THIS_FILE=${BASH_SOURCE[0]}
|
||||
LOG_LABEL=$(basename "$THIS_FILE")
|
||||
THIS=${THIS:-$LOG_LABEL}
|
||||
LOG_FILE=${LOG_FILE:-"$LOG_LABEL.log"}
|
||||
|
||||
XDG_CONFIG_HOME=${XDG_CONFIG_HOME:-$HOME/.config}
|
||||
XDG_DATA_HOME=${XDG_DATA_HOME:-$HOME/.local/share}
|
||||
IMAGE="git.housh.dev/michael/swift-dev-container"
|
||||
IMAGE_TAG="latest"
|
||||
|
||||
declare cmd dir pull_flag run_flag
|
||||
cmd=""
|
||||
dir=""
|
||||
pull_flag="0"
|
||||
run_flag="1"
|
||||
|
||||
usage() {
|
||||
cat <<EOF
|
||||
Runs neovim inside swift-dev-container docker container for working on swift projects.
|
||||
|
||||
Currently I'm unable to get swift to install on arch linux, so this gives me working lsp, etc.
|
||||
|
||||
USAGE:
|
||||
$ $THIS <flags> <command> -- <docker comand>
|
||||
|
||||
FLAGS:
|
||||
-h | --help: Show this help page.
|
||||
-p | --pull: Used with run command, to pull/update image before running.
|
||||
-t | --tag <tag>: Used with run command to specify the image tag to use.
|
||||
|
||||
COMMANDS:
|
||||
pull <tag>: Pull the dev container image, tag is optional (default; 'latest').
|
||||
run <dir> (default): Run the dev container in the directory, if directory not supplied it
|
||||
will default to PWD.
|
||||
|
||||
NOTES:
|
||||
Run command is implied / default, so it's not required to be passed if you just want to run the
|
||||
container. For example in your swift project directory you can run 'swift-dev' and a container
|
||||
will start.
|
||||
|
||||
This will properly mount '~/.config/nvim' and '~/.local/share/nvim' inside the container.
|
||||
|
||||
If you would like to run a custom command / not run neovim in the container then it MUST follow
|
||||
'--'. For example, 'swift-dev -- /bin/bash'.
|
||||
|
||||
EOF
|
||||
}
|
||||
|
||||
# Logging utility function, use in place of echo.
|
||||
log() {
|
||||
logging log --source "$THIS_FILE" "$@"
|
||||
}
|
||||
|
||||
pull() {
|
||||
log "Pulling image: '$IMAGE:$IMAGE_TAG'"
|
||||
podman pull "$IMAGE:$IMAGE_TAG"
|
||||
}
|
||||
|
||||
run() {
|
||||
[[ -z $dir ]] && dir="$PWD"
|
||||
[[ -z $cmd ]] && cmd="/root/.local/share/bob/nvim-bin/nvim"
|
||||
log "Running '$IMAGE:$IMAGE_TAG', in: '$dir'"
|
||||
podman run -it --rm \
|
||||
--volume "$XDG_CONFIG_HOME/nvim":/root/.config/nvim \
|
||||
--volume "$XDG_DATA_HOME/nvim":/root/.local/share/nvim \
|
||||
--volume "$dir":/root/dev \
|
||||
"$IMAGE:$IMAGE_TAG" "$cmd"
|
||||
}
|
||||
|
||||
################################################################################
|
||||
# MAIN
|
||||
################################################################################
|
||||
|
||||
# Setup logging file and label.
|
||||
source "$SCRIPTS/hypr/logging"
|
||||
setup-logging "$LOG_FILE" "$LOG_LABEL"
|
||||
|
||||
while [[ $# -gt 0 ]]; do
|
||||
if [[ $1 == "-h" ]] || [[ $1 == "--help" ]]; then
|
||||
usage && exit 0
|
||||
elif [[ $1 == "-p" ]] || [[ $1 == "--pull" ]]; then
|
||||
pull_flag="1"
|
||||
elif [[ $1 == "-t" ]] || [[ $1 == "--tag" ]]; then
|
||||
[[ -n ${2:-""} ]] || (log --error "Must supply a tag" && exit 1)
|
||||
IMAGE_TAG=$2
|
||||
shift
|
||||
elif [[ $1 == "pull" ]]; then
|
||||
run_flag="0"
|
||||
pull_flag="1"
|
||||
elif [[ $1 == "--" ]]; then
|
||||
shift
|
||||
cmd="$*"
|
||||
elif [[ ! $1 == "run" ]]; then
|
||||
dir="$1"
|
||||
fi
|
||||
shift
|
||||
done
|
||||
|
||||
[[ $pull_flag = "1" ]] && pull
|
||||
[[ $run_flag = "1" ]] && run
|
||||
Reference in New Issue
Block a user