Compare commits

...

3 Commits

Author SHA1 Message Date
26dd25be77 add global CLAUDE.md: sql style, query tools, nvim awareness
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-05-30 23:40:55 -04:00
b3c7edb504 add xnd (duckdb→vd), visidatarc with comma formatting
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-05-30 23:27:06 -04:00
8b80993e78 fix xnspa: explicit csv format for visidata stdin
Co-Authored-By: Claude Sonnet 4.6 (1M context) <noreply@anthropic.com>
2026-05-14 16:00:19 -04:00
4 changed files with 75 additions and 2 deletions

View File

@ -44,7 +44,7 @@ deploy_configs() {
echo "Deploying configuration files as symlinks..."
local config_dir="$SCRIPT_DIR/dotfiles"
for config in .bashrc .vimrc .gitconfig .pspgconf .psqlrc .tmux.conf; do
for config in .bashrc .vimrc .gitconfig .pspgconf .psqlrc .tmux.conf .visidatarc; do
create_symlink "$config_dir/$config" ~/"$config"
done
@ -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
}

View File

@ -176,7 +176,25 @@ xnspa() {
--csv \
--pset footer=off \
$db_args \
-f "$file" | vd -
-f "$file" | vd -f csv -
}
xnd() {
local file
file=$(
lsof +D ~/.local/state/nvim/swap/ 2>/dev/null | grep -v 'lsof:' |
grep -o "/swap/.*" |
sed 's|^/swap/||' |
tr "%" "/" |
sed -E 's/\.sw[op]$//' |
grep "$(pwd | sed 's|^//|/|')" |
fzf
) || return
[[ -z "$file" ]] && return
duckdb -csv /opt/sync/osm_stack.duckdb < "$file" | vd -f csv -
}
xndb2() {

View File

@ -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 `~/.<file>` 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.

2
dotfiles/.visidatarc Normal file
View File

@ -0,0 +1,2 @@
options.disp_float_fmt = '{:,.2f}'
options.disp_int_fmt = '{:,}'