npm-run-scripts 1.0.0

Fast interactive TUI for running npm scripts
Documentation
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
# Rust Development Environment Setup

## Complete Guide for macOS and Linux

This guide will help you set up a complete Rust development environment for the `nrs` project.

---

## Table of Contents

1. [Install Rust]#1-install-rust
2. [Configure Your Shell]#2-configure-your-shell
3. [Essential Tools]#3-essential-tools
4. [IDE Setup]#4-ide-setup
5. [Project Setup]#5-project-setup
6. [Common Commands]#6-common-commands
7. [Troubleshooting]#7-troubleshooting

---

## 1. Install Rust

### 1.1 macOS with Homebrew (Recommended for macOS users)

The cleanest way to install Rust on macOS is via Homebrew + rustup:

```bash
# Install rustup via Homebrew
brew install rustup-init

# Run the initializer
rustup-init
```

During installation, choose option `1` for the default installation.

After installation completes:

```bash
# Add Rust to your PATH
source $HOME/.cargo/env
```

**Why this approach?**
- Homebrew manages the rustup binary itself
- rustup manages Rust versions, toolchains, and components
- Best of both worlds!

### 1.2 Linux / Alternative Method

If you're on Linux or prefer not to use Homebrew:

```bash
# Install rustup directly
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

During installation, choose option `1` for the default installation.

### 1.2 Verify Installation

After installation, restart your terminal or run:

```bash
source $HOME/.cargo/env
```

Then verify:

```bash
# Check Rust version
rustc --version
# Should output something like: rustc 1.75.0 (82e1608df 2023-12-21)

# Check Cargo version
cargo --version
# Should output something like: cargo 1.75.0 (1d8b05cdd 2023-11-20)

# Check rustup version
rustup --version
# Should output something like: rustup 1.26.0 (5af9b9484 2023-04-05)
```

### 1.3 Update Rust

Keep Rust updated:

```bash
# Update to latest stable
rustup update stable

# Update rustup itself
rustup self update
```

---

## 2. Configure Your Shell

### 2.1 Add to PATH

The installer should add this automatically, but verify your shell config has:

**For Bash (~/.bashrc or ~/.bash_profile):**
```bash
# Rust
export PATH="$HOME/.cargo/bin:$PATH"
```

**For Zsh (~/.zshrc):**
```bash
# Rust
export PATH="$HOME/.cargo/bin:$PATH"
```

**For Fish (~/.config/fish/config.fish):**
```fish
# Rust
set -gx PATH $HOME/.cargo/bin $PATH
```

### 2.2 Enable Cargo Completions

**Bash:**
```bash
# Add to ~/.bashrc
source "$(rustc --print sysroot)/etc/bash_completion.d/cargo"
```

**Zsh:**
```bash
# Add to ~/.zshrc
autoload -U compinit
compinit
fpath=(~/.zfunc $fpath)
rustup completions zsh > ~/.zfunc/_rustup
rustup completions zsh cargo > ~/.zfunc/_cargo
```

**Fish:**
```fish
# Run once
mkdir -p ~/.config/fish/completions
rustup completions fish > ~/.config/fish/completions/rustup.fish
rustup completions fish cargo > ~/.config/fish/completions/cargo.fish
```

---

## 3. Essential Tools

### 3.1 Install Required Components

```bash
# Code formatting
rustup component add rustfmt

# Linting
rustup component add clippy

# Documentation
rustup component add rust-docs

# Rust Language Server (for IDE support)
rustup component add rust-analyzer
```

### 3.2 Install Useful Cargo Extensions

```bash
# Fast file watcher for development
cargo install cargo-watch

# Check all features compile
cargo install cargo-hack

# Show dependency tree
cargo install cargo-tree

# Audit dependencies for vulnerabilities
cargo install cargo-audit

# Generate code coverage
cargo install cargo-tarpaulin

# Profile performance (optional)
cargo install flamegraph

# Faster linking (Linux only - recommended)
# First install lld: sudo apt install lld (Ubuntu) or sudo dnf install lld (Fedora)

# Faster linking (macOS - use default or zld)
# brew install michaeleisel/zld/zld
```

### 3.3 Configure Faster Linking (Recommended)

Create or edit `~/.cargo/config.toml`:

```toml
# Faster linking configuration

[target.x86_64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-unknown-linux-gnu]
linker = "clang"
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.x86_64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

[target.aarch64-apple-darwin]
rustflags = ["-C", "link-arg=-fuse-ld=lld"]

# Enable incremental compilation (default in dev, but be explicit)
[build]
incremental = true

# Use all CPU cores
[build]
jobs = 0  # 0 means auto-detect
```

### 3.4 System Dependencies

**macOS:**
```bash
# Install Xcode command line tools (if not installed)
xcode-select --install

# Optional: Install lld via Homebrew for faster linking
brew install llvm
```

**Ubuntu/Debian:**
```bash
# Build essentials
sudo apt update
sudo apt install build-essential pkg-config libssl-dev

# Faster linker (recommended)
sudo apt install lld clang
```

**Fedora:**
```bash
# Build essentials
sudo dnf groupinstall "Development Tools"
sudo dnf install openssl-devel

# Faster linker (recommended)
sudo dnf install lld clang
```

**Arch Linux:**
```bash
# Build essentials
sudo pacman -S base-devel openssl

# Faster linker (recommended)
sudo pacman -S lld clang
```

---

## 4. IDE Setup

### 4.1 VS Code (Recommended)

**Install Extensions:**

1. **rust-analyzer** (essential) - Rust language support
   - Extension ID: `rust-lang.rust-analyzer`

2. **Even Better TOML** - TOML file support
   - Extension ID: `tamasfe.even-better-toml`

3. **crates** - Dependency version hints
   - Extension ID: `serayuzgur.crates`

4. **Error Lens** - Inline error display
   - Extension ID: `usernamehw.errorlens`

**VS Code Settings (.vscode/settings.json):**

```json
{
  "rust-analyzer.checkOnSave.command": "clippy",
  "rust-analyzer.cargo.features": "all",
  "rust-analyzer.procMacro.enable": true,
  "rust-analyzer.inlayHints.parameterHints.enable": true,
  "rust-analyzer.inlayHints.typeHints.enable": true,
  "editor.formatOnSave": true,
  "[rust]": {
    "editor.defaultFormatter": "rust-lang.rust-analyzer",
    "editor.tabSize": 4
  }
}
```

### 4.2 JetBrains (RustRover or IntelliJ + Plugin)

1. Download RustRover: https://www.jetbrains.com/rust/
2. Or install the Rust plugin in IntelliJ IDEA

### 4.3 Neovim

If using Neovim with LSP:

```lua
-- In your LSP config
require('lspconfig').rust_analyzer.setup({
  settings = {
    ['rust-analyzer'] = {
      checkOnSave = {
        command = "clippy"
      },
      cargo = {
        features = "all"
      }
    }
  }
})
```

### 4.4 Terminal-Only Development

If you prefer terminal:

```bash
# Watch and rebuild on changes
cargo watch -x "check" -x "clippy" -x "test"

# Or just check
cargo watch -x check

# Run with auto-reload
cargo watch -x run
```

---

## 5. Project Setup

### 5.1 Clone and Setup

```bash
# Clone the repository (when created)
git clone https://github.com/yourusername/nrs.git
cd nrs

# Build the project
cargo build

# Run tests
cargo test

# Run the application
cargo run

# Run with arguments
cargo run -- --help
cargo run -- --list
```

### 5.2 Development Workflow

```bash
# Terminal 1: Watch for changes and check
cargo watch -x "clippy -- -D warnings"

# Terminal 2: Run the app when needed
cargo run

# Before committing
cargo fmt
cargo clippy -- -D warnings
cargo test
```

### 5.3 Create Project from Scratch

If starting fresh:

```bash
# Create new project
cargo new nrs
cd nrs

# Add dependencies
cargo add clap --features derive
cargo add ratatui
cargo add crossterm
cargo add serde --features derive
cargo add serde_json
cargo add toml
cargo add dirs
cargo add fuzzy-matcher
cargo add chrono --features serde
cargo add anyhow
cargo add thiserror

# Add dev dependencies
cargo add --dev criterion
cargo add --dev tempfile
cargo add --dev assert_cmd
cargo add --dev predicates
cargo add --dev insta
```

---

## 6. Common Commands

### 6.1 Building

```bash
# Debug build (fast compile, slow runtime)
cargo build

# Release build (slow compile, fast runtime)
cargo build --release

# Check without building (fastest)
cargo check

# Build documentation
cargo doc --open
```

### 6.2 Running

```bash
# Run debug build
cargo run

# Run with arguments
cargo run -- arg1 arg2

# Run release build
cargo run --release

# Run specific binary
cargo run --bin nrs
cargo run --bin ns
```

### 6.3 Testing

```bash
# Run all tests
cargo test

# Run specific test
cargo test test_name

# Run tests with output
cargo test -- --nocapture

# Run ignored tests
cargo test -- --ignored

# Run tests in release mode
cargo test --release
```

### 6.4 Linting & Formatting

```bash
# Format code
cargo fmt

# Check formatting without changing
cargo fmt -- --check

# Lint with clippy
cargo clippy

# Lint with warnings as errors
cargo clippy -- -D warnings

# Fix clippy warnings automatically (when possible)
cargo clippy --fix
```

### 6.5 Dependencies

```bash
# Add a dependency
cargo add package_name

# Add with features
cargo add serde --features derive

# Add dev dependency
cargo add --dev package_name

# Remove dependency
cargo remove package_name

# Update dependencies
cargo update

# Show dependency tree
cargo tree

# Audit for vulnerabilities
cargo audit
```

### 6.6 Other Useful Commands

```bash
# Clean build artifacts
cargo clean

# Show what would be compiled
cargo build --dry-run

# Generate and view docs
cargo doc --open

# Show project info
cargo metadata

# Run benchmarks (if defined)
cargo bench
```

---

## 7. Troubleshooting

### 7.1 Common Issues

**"cargo: command not found"**
```bash
# Add to PATH
source $HOME/.cargo/env
# Or restart your terminal
```

**"linker 'cc' not found"**
```bash
# macOS
xcode-select --install

# Ubuntu/Debian
sudo apt install build-essential

# Fedora
sudo dnf groupinstall "Development Tools"
```

**"failed to run custom build command for openssl-sys"**
```bash
# Ubuntu/Debian
sudo apt install pkg-config libssl-dev

# Fedora
sudo dnf install openssl-devel

# macOS
brew install openssl
export OPENSSL_DIR=$(brew --prefix openssl)
```

**Slow compilation**
```bash
# Use faster linker (see section 3.3)
# Or use mold linker (fastest on Linux)
cargo install mold
# Then in ~/.cargo/config.toml:
# [target.x86_64-unknown-linux-gnu]
# linker = "clang"
# rustflags = ["-C", "link-arg=-fuse-ld=mold"]
```

**rust-analyzer not working in VS Code**
```bash
# Restart rust-analyzer
# VS Code: Ctrl+Shift+P -> "rust-analyzer: Restart Server"

# Check rust-analyzer is installed
rustup component add rust-analyzer

# Make sure you opened the folder containing Cargo.toml
```

### 7.2 Reset Everything

If things are broken:

```bash
# Remove rustup completely
rustup self uninstall

# Remove cargo cache
rm -rf ~/.cargo

# Reinstall
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
```

### 7.3 Getting Help

```bash
# Rust documentation
rustup doc

# Book (The Rust Programming Language)
rustup doc --book

# Standard library docs
rustup doc --std

# Cargo book
rustup doc --cargo
```

**Online Resources:**
- The Rust Book: https://doc.rust-lang.org/book/
- Rust by Example: https://doc.rust-lang.org/rust-by-example/
- Rustlings (exercises): https://github.com/rust-lang/rustlings
- Rust Cookbook: https://rust-lang-nursery.github.io/rust-cookbook/

---

## Quick Start Checklist

```bash
# 1. Install Rust (macOS with Homebrew)
brew install rustup-init
rustup-init
source $HOME/.cargo/env

# -- OR on Linux --
# curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
# source $HOME/.cargo/env

# 2. Verify
rustc --version
cargo --version

# 3. Add components
rustup component add rustfmt clippy rust-analyzer

# 4. Install cargo-watch
cargo install cargo-watch

# 5. Clone project
git clone <repo-url>
cd nrs

# 6. Build and run
cargo build
cargo run

# You're ready! 🎉
```