From 26dd25be7764b1a9e7847fe5170da9f47c34fe15 Mon Sep 17 00:00:00 2001 From: Paul Trowbridge Date: Sat, 30 May 2026 23:40:55 -0400 Subject: [PATCH] add global CLAUDE.md: sql style, query tools, nvim awareness Co-Authored-By: Claude Sonnet 4.6 (1M context) --- _lib.sh | 3 +++ dotfiles/.claude/CLAUDE.md | 50 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 53 insertions(+) create mode 100644 dotfiles/.claude/CLAUDE.md diff --git a/_lib.sh b/_lib.sh index ef45e6e..93692f6 100755 --- a/_lib.sh +++ b/_lib.sh @@ -52,6 +52,9 @@ deploy_configs() { migrate_and_link "$config_dir/$config" ~/"$config" done + mkdir -p ~/.claude + create_symlink "$config_dir/.claude/CLAUDE.md" ~/.claude/CLAUDE.md + echo "Sourcing .bashrc..." source ~/.bashrc } diff --git a/dotfiles/.claude/CLAUDE.md b/dotfiles/.claude/CLAUDE.md new file mode 100644 index 0000000..16275e1 --- /dev/null +++ b/dotfiles/.claude/CLAUDE.md @@ -0,0 +1,50 @@ +# Global Claude Preferences + +## SQL Style + +Always write SQL in this style: + +- **Keywords UPPERCASE**: SELECT, FROM, WHERE, WITH, GROUP BY, LEFT JOIN, ON, CASE, WHEN, COALESCE, SUM, MAX, etc. +- **Leading commas**, one column per line, indented under SELECT/GROUP BY +- **FROM / WHERE / GROUP BY** on their own line, content indented below +- **LEFT JOIN ... ON** with condition indented on next line +- **WHERE TRUE** as base condition +- **CTEs** with `--` comment header; subsequent CTEs start with `,cte_name AS (` +- `::TYPE` casting over `CAST()` +- `~` for regex, not LIKE +- No trailing commas, no unnecessary parentheses +- Descriptive snake_case aliases + +Canonical example: `inventory/on_hand/onhand_with_last_mfg.pg.sql` in the SQL repo. + +## Shell Query Tools + +PostgreSQL (connection string in `$PG`, defined in `.bashrc_local`): +- `xnspa` — fzf-select open nvim buffer, run with `$PG`, output to VisiData +- `xnsp` — same, output to pspg +- `xns` — same, raw output + +DuckDB (`/opt/sync/osm_stack.duckdb` snapshot, CLI at `~/.local/bin/duckdb`): +- `xnd` — fzf-select open nvim buffer, run against DuckDB snapshot, output to VisiData +- Direct: `duckdb /opt/sync/osm_stack.duckdb < file.du.sql` + +SQL Server (connection strings `$MS`, `$MSC`, `$MSW` in `.bashrc_local`): +- `xmspa` — fzf-select open nvim buffer, run with `$MSC`, output to VisiData + +File extension conventions: +- `.pg.sql` — PostgreSQL +- `.ms.sql` — SQL Server +- `.db2.sql` — IBM DB2 +- `.du.sql` — DuckDB + +## Nvim Buffer Awareness + +At the start of every conversation, check for open nvim buffers in the current directory and read them proactively: + +```bash +lsof +D ~/.local/state/nvim/swap/ 2>/dev/null | grep -o "/swap/.*" | sed 's|^/swap/||' | tr "%" "/" | sed -E 's/\.sw[op]$//' | grep "$(pwd | sed 's|^//|/|')" +``` + +## Setup Environment + +Dotfiles are managed via symlinks from `~/setup_env/dotfiles/`. Editing `~/.` directly edits the repo. Always edit dotfiles at their source (`~/setup_env/dotfiles/`) rather than the symlink target. `_lib.sh` handles deployment; `.bashrc_local` and `.bashrc_paths` are gitignored and machine-specific.