dotfiles/justfile

70 lines
1.8 KiB
Makefile

#!/usr/bin/env -S just --justfile
set shell := ["bash", "-cu"]
set positional-arguments := true
[private]
default:
@just help
# show this help
help:
@just --list
# lint sh/bash files with ShellCheck
[group('dev')]
lint:
shfmt -f . | tee /dev/fd/2 | xargs -P$(nproc) -n1 -- shellcheck --external-sources --exclude=SC1091
# format sh/bash files
[group('dev')]
format-sh: lint
shfmt -f . | tee /dev/fd/2 | xargs shfmt --case-indent --binary-next-line --simplify --write
# format single sh file
[group('dev')]
format-sh-file file:
shfmt --case-indent --binary-next-line --simplify --write {{ file }}
# format lua files
[group('dev')]
format-lua:
git ls-files | grep -E '.*\.lua$' | xargs stylua --config-path .stylua.toml
# format all files
[group('dev')]
format: format-sh format-lua
# link shell scripts to ~/.local/bin
[group('install')]
link-bin:
scripts/link.sh
# stow core/*
[group('install')]
stow-core:
#!/usr/bin/env bash
if ! command -v stow &>/dev/null; then
echo "target requires GNU stow" >&2
exit 1
fi
# Since AstroNvim and nvim configurations are mutually exclusive, stow can fail and aborts.
exclude=('nvim')
printf -v pattern '%s\|' "${exclude[@]}"
pattern=${pattern%\\|}
core=($(command find core/ -mindepth 1 -maxdepth 1 -type d ! -regex ".*/\(${pattern}\)$" -printf '%f\n'))
echo "> If a stow fails, its configuration files probably already exist." >&2
for fragment in "${core[@]}"; do
printf "> Trying to stow %s: " "$fragment" >&2
if stow --restow --target="$HOME" --dir=core/ --stow "$fragment"; then
echo "OK" >&2
fi
done
# link all
[group('install')]
link: link-bin stow-core
alias install := link
# vi: set ft=just ts=4 sw=4 sts=-1 nosr et si tw=0 fdm=manual: