Skip to content

Commit

Permalink
dev: add development tooling
Browse files Browse the repository at this point in the history
Signed-off-by: Patrizio Bekerle <patrizio@bekerle.com>
  • Loading branch information
pbek committed Feb 21, 2025
1 parent b942ba6 commit d4ee8e9
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 0 deletions.
1 change: 1 addition & 0 deletions .envrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
use nix
78 changes: 78 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
# Use `just <recipe>` to run a recipe
# https://just.systems/man/en/

# By default, run the `--list` command
default:
@just --list

# Variables

zellijSession := "esign-app"

# Open a terminal with the cabinet-app session
[group('dev')]
term-run:
zellij --layout term.kdl attach {{ zellijSession }} -c

# Kill the cabinet-app session
[group('dev')]
term-kill:
-zellij delete-session {{ zellijSession }} -f

# Kill and run a terminal with the cabinet-app session
[group('dev')]
term: term-kill term-run

# Open a browser with the application
[group('dev')]
open-browser:
xdg-open https://localhost:8001

# Interactive npm watch script selector
[group('dev')]
watch:
#!/usr/bin/env bash
set -euo pipefail
# Define the watch scripts with descriptions
watch_scripts=(
"watch: Whitelabel app"
"watch-custom: TU Graz app"
)

# Use fzf to select a script
selected_script=$(printf '%s\n' "${watch_scripts[@]}" | fzf \
--height 40% \
--layout=reverse \
--border \
--prompt='Select NPM watch script > ' \
--preview='echo "Will run: npm run $(echo {} | cut -d: -f1)"' \
--preview-window=up:1 \
| cut -d: -f1)

# Check if a script was selected
if [[ -n "$selected_script" ]]; then
# Get the full line for the selected script
full_text=$(printf '%s\n' "${watch_scripts[@]}" | grep "^$selected_script:")

# Set Zellij pane name
if command -v zellij &> /dev/null; then
zellij action rename-pane "$full_text"
fi

echo "Running: npm run $selected_script"
npm run "$selected_script"
else
echo "No script selected. Exiting."
exit 1
fi

# Format all justfiles
[group('linter')]
just-format:
#!/usr/bin/env bash
# Find all files named "justfile" recursively and run just --fmt --unstable on them
find . -type f -name "justfile" -print0 | while IFS= read -r -d '' file; do
echo "Formatting $file"
just --fmt --unstable -f "$file"
done
13 changes: 13 additions & 0 deletions shell.nix
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{ pkgs ? import <nixpkgs> {} }:
pkgs.mkShell {
# nativeBuildInputs is usually what you want -- tools you need to run
nativeBuildInputs = with pkgs; [
nodejs_20
curl
zellij # smart terminal workspace
lazygit # git terminal
just # task runner
fzf # fuzzy finder, for "just watch"
];
}

44 changes: 44 additions & 0 deletions term.kdl
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// https://zellij.dev/documentation/creating-a-layout
layout {
tab name="main" focus=true {
pane size=1 borderless=true {
plugin location="zellij:tab-bar"
}
pane size="60%" {
command "lazygit"
focus true
}
pane split_direction="vertical" size="40%" {
pane {
command "just"
args "watch"
}
pane {
command "npm"
args "install"
}
}
// pane split_direction="vertical" {
// pane {
// command "docker"
// args "compose" "up"
// cwd "./docker"
// }
// pane {
// cwd "./docker"
// }
// }
pane size=1 borderless=true {
plugin location="zellij:status-bar"
}
}
tab name="term" {
pane size=1 borderless=true {
plugin location="zellij:tab-bar"
}
pane
pane size=1 borderless=true {
plugin location="zellij:status-bar"
}
}
}

0 comments on commit d4ee8e9

Please sign in to comment.