nixos: gen 45 @ lilac — 2026-09-18 08:18 26.05.20260814.02e0898 (Yarara) ----- refactoring nvim.nix and adding better java integration

This commit is contained in:
2026-09-18 08:18:18 -06:00
parent b85e10aa25
commit 77178d0b6e
3 changed files with 179 additions and 37 deletions
+102 -11
View File
@@ -65,34 +65,126 @@ in
custom_wvkbd
(pkgs.writeShellScriptBin "jroot" ''
d="$PWD"
while [ "$d" != "/" ]; do
if [ -f "$d/.classpath" ]; then printf '%s\n' "$d"; exit 0; fi
d="$(dirname "$d")"
done
echo "jroot: no .classpath found at or above $PWD" >&2
exit 1
'')
(pkgs.writeShellScriptBin "jbuild" ''
set -euo pipefail
# Assign first: `cd "$(jroot)"` would swallow a jroot failure, because
# `cd ""` is a successful no-op and set -e never sees the error.
ROOT="$(jroot)"
cd "$ROOT"
mkdir -p bin
SOURCES="$(mktemp)"
trap 'rm -f "$SOURCES"' EXIT
find . -path ./bin -prune -o -name '.*' -prune -o -name '*.java' -print > "$SOURCES"
if [ ! -s "$SOURCES" ]; then
echo "jbuild: no .java files found under $ROOT" >&2
exit 1
fi
# bin is deliberately NOT on the compile classpath: every source is passed
# explicitly, so a stale .class from a deleted file would silently satisfy
# references that ought to fail.
javac -g --release 21 -encoding UTF-8 -d bin -cp "lib/*" @"$SOURCES"
'')
(pkgs.writeShellScriptBin "jclean" ''
set -euo pipefail
ROOT="$(jroot)"
rm -rf "$ROOT/bin"
echo "cleaned $ROOT/bin"
'')
(pkgs.writeShellScriptBin "jrun" ''
set -euo pipefail
if [ $# -lt 1 ]; then
echo "usage: jrun <package.MainClass> [args...]" >&2
exit 1
fi
ROOT="$(jroot)"
jbuild
cd "$ROOT"
MAIN="$1"; shift
exec java -cp "bin:lib/*" "$MAIN" "$@"
'')
(pkgs.writeShellScriptBin "jtest" ''
set -euo pipefail
# sort -V so 1.10.2 beats 1.9.0; plain tail -n1 sorts those the wrong way.
JUNIT="$(ls -1 "$HOME"/dev/jars/junit-platform-console-standalone-*.jar 2>/dev/null | sort -V | tail -n1 || true)"
if [ -z "$JUNIT" ]; then
echo "jtest: no junit-platform-console-standalone jar in ~/dev/jars" >&2
exit 1
fi
ROOT="$(jroot)"
jbuild
cd "$ROOT"
if [ $# -eq 0 ]; then
exec java -jar "$JUNIT" execute --class-path "bin:lib/*" --scan-class-path --details=tree
fi
ARGS=""
for pkg in "$@"; do
ARGS="$ARGS --select-package $pkg"
done
exec java -jar "$JUNIT" execute --class-path "bin:lib/*" $ARGS --details=tree
'')
(pkgs.writeShellScriptBin "fkill" ''
if [ -z "$1" ]; then
echo "Need the name of one application"
echo "eg. fkill google-chrome"
set -eu
if [ $# -lt 1 ]; then
echo "usage: fkill <process-name>" >&2
echo "eg. fkill firefox" >&2
exit 1
fi
PROGRAM=$1
PROGRAM="$1"
ps aux | grep $PROGRAM | awk '{print $2}' | xargs kill
if ! pgrep -x -- "$PROGRAM" >/dev/null 2>&1; then
echo "fkill: no process named '$PROGRAM'" >&2
exit 1
fi
pgrep -a -x -- "$PROGRAM"
printf 'Kill these? [y/N] '
read -r reply
case "$reply" in
[yY]*) pkill -x -- "$PROGRAM" ;;
*) echo "aborted" ;;
esac
'')
(pkgs.writeShellScriptBin "find-open-port" ''
if [ -z "$1" ]; then
set -u
if [ $# -lt 1 ]; then
echo "Please provide an application name, project directory, or other identifier."
echo " Usage: find-open-port $HOME/dev/some-project"
echo ' Usage: find-open-port $HOME/dev/some-project'
echo " Usage: find-open-port some-app"
exit 1
fi
APP_NAME=$1
REGISTRY_FILE=$HOME/.dotfiles/ports.registry
APP_NAME="$1"
REGISTRY_FILE="$HOME/.dotfiles/ports.registry"
MIN_PORT=8000
MAX_PORT=8999
MAX_RETRIES=50
mkdir -p "$(dirname "$REGISTRY_FILE")"
if [ -f "$REGISTRY_FILE" ] && grep -q "^$APP_NAME : " "$REGISTRY_FILE"; then
echo "Already registered:"
grep "^$APP_NAME : " "$REGISTRY_FILE"
exit 0
fi
echo "Searching for available port between $MIN_PORT and $MAX_PORT for $APP_NAME..."
for ((i=1; i<=MAX_RETRIES; i++)); do
@@ -163,4 +255,3 @@ in
home.stateVersion = "26.05"; # DO NOT CHANGE
}