From c3872475b53e530a2be98faa8f847b6bd2c773d1 Mon Sep 17 00:00:00 2001 From: Yan Lin Date: Sun, 27 Jul 2025 17:17:03 +0200 Subject: [PATCH] Add database tools and improve tmux copy mode MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Database Tools: - Add lazysql: LazyGit-style TUI database management tool - Add sqlite3: Official SQLite CLI for scripting and automation - Comprehensive usage documentation for both tools - Support for MySQL, PostgreSQL, and SQLite databases Tmux Improvements: - Fix copy mode to not exit after copying (copy-pipe vs copy-pipe-and-cancel) - Allows multiple text selections without re-entering copy mode - Manual exit control with q/Escape/Ctrl+c System Optimizations: - Add trusted binary caches for faster Nix builds - Include nix-community and devenv cachix for improved performance 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- README.md | 72 ++++++++++++++++++++++++++++++++++++++++++++++++ flake.nix | 12 ++++++++ modules/tmux.nix | 2 +- 3 files changed, 85 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 15d66d2..d10d90b 100644 --- a/README.md +++ b/README.md @@ -212,6 +212,8 @@ Launch with `gitui` in any git repository for: - **bat**: Syntax-highlighted cat replacement - **btop**: Modern system monitor - **httpie**: Modern HTTP client for API testing +- **lazysql**: LazyGit-style TUI database management tool +- **sqlite3**: Official SQLite command-line interface - **lftp**: Scriptable FTP client for automation - **termscp**: Comprehensive TUI file transfer client (FTP/SFTP/SCP/S3) - **zoxide**: Smart cd with frecency algorithm @@ -258,6 +260,76 @@ http GET api.example.com/protected Authorization:"Bearer your-token" http GET api.example.com/api X-API-Key:"your-api-key" ``` +#### lazysql Usage Examples +```bash +# Launch TUI database management (LazyGit-style interface) +lazysql + +# Connect to different databases +lazysql -h localhost -u username -p password -d database_name # MySQL +lazysql --url postgres://user:pass@localhost/dbname # PostgreSQL +lazysql --url sqlite://./database.db # SQLite +lazysql --url "mysql://user:pass@localhost/db" # MySQL URL format + +# With config file (recommended for credentials) +lazysql --config ~/.config/lazysql/config.yml + +# Interactive TUI operations: +# - Navigate tables with j/k (vim-style) +# - View table structure and data +# - Execute SQL queries in editor mode +# - Export query results +# - Browse database schema +``` + +**Key lazysql features:** +- **LazyGit-inspired interface**: Familiar navigation for developers +- **Multi-database support**: MySQL, PostgreSQL, SQLite +- **SQL editor**: Syntax highlighting and query execution +- **Export capabilities**: Save query results to files +- **Connection management**: Save and reuse database connections + +#### sqlite3 Usage Examples +```bash +# Connect to SQLite database +sqlite3 ai.db + +# One-liner queries (no interactive session) +sqlite3 ai.db "SELECT COUNT(*) FROM users;" +sqlite3 ai.db "SELECT * FROM users WHERE active = 1;" + +# Common SQLite dot commands (inside sqlite3 shell) +.tables # List all tables +.schema # Show all table schemas +.schema users # Show specific table schema +.mode csv # Set output format (csv, json, html, etc.) +.headers on # Show column headers +.output results.csv # Redirect output to file +.output stdout # Reset output to terminal + +# Import/Export operations +.backup backup.db # Create database backup +.restore backup.db # Restore from backup +.dump # Export entire database as SQL +.dump users # Export specific table as SQL + +# Execute SQL script file +.read script.sql # Run SQL commands from file +sqlite3 ai.db < script.sql # Alternative: pipe script to sqlite3 + +# Database inspection +.dbinfo # Show database information +.indices table_name # Show indexes for table +.exit # Exit sqlite3 shell +``` + +**Key sqlite3 features:** +- **Universal compatibility**: Works with any SQLite database +- **Scriptable**: Perfect for automation and batch operations +- **Lightweight**: Minimal overhead for quick queries +- **Import/Export**: Built-in CSV, JSON, and SQL dump capabilities +- **Backup tools**: Simple database backup and restore operations + #### termscp Usage Examples ```bash # Launch TUI file transfer client diff --git a/flake.nix b/flake.nix index 5e26718..130c413 100644 --- a/flake.nix +++ b/flake.nix @@ -21,6 +21,16 @@ ]; nix.settings.experimental-features = "nix-command flakes"; + nix.settings.substituters = [ + "https://cache.nixos.org/" + "https://nix-community.cachix.org" + "https://devenv.cachix.org" + ]; + nix.settings.trusted-public-keys = [ + "cache.nixos.org-1:6NCHdD59X431o0gWypbMrAURkbJ16ZPMQFGspcDShjY=" + "nix-community.cachix.org-1:mB9FSh9qf2dCimDSUo8Zy7bkq5CX+/rkCWyvRCYg3Fs=" + "devenv.cachix.org-1:w1cLUi8dv3hnoSPGAuibQv+f9TZLr6cv/Hm9XgU50cw=" + ]; system.stateVersion = 6; nixpkgs.hostPlatform = "aarch64-darwin"; @@ -48,6 +58,8 @@ lftp termscp httpie + lazysql + sqlite claude-code.packages.aarch64-darwin.claude-code nerd-fonts.fira-code nerd-fonts.jetbrains-mono diff --git a/modules/tmux.nix b/modules/tmux.nix index fb20494..0d3c9b1 100644 --- a/modules/tmux.nix +++ b/modules/tmux.nix @@ -70,7 +70,7 @@ # Better copy mode bind-key -T copy-mode-vi v send-keys -X begin-selection - bind-key -T copy-mode-vi y send-keys -X copy-pipe-and-cancel "pbcopy" + bind-key -T copy-mode-vi y send-keys -X copy-pipe "pbcopy" bind-key -T copy-mode-vi r send-keys -X rectangle-toggle # New window with current path