pathmaster 0.2.2

pathmaster is a powerful command-line tool written in Rust for managing your system's PATH environment variable.
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
# **README**

# pathmaster

## **Table of Contents**

- [**README**]#readme
- [pathmaster]#pathmaster
  - [**Table of Contents**]#table-of-contents
  - [**Introduction**]#introduction
- [pathmaster]#pathmaster-1
  - [New in Version 0.2.2]#new-in-version-022
  - [Features]#features
    - [Core Features (Updated in 0.2.2)]#core-features-updated-in-022
    - [Path Management]#path-management
    - [Safety Features]#safety-features
  - [Usage]#usage
    - [Checking PATH Sources]#checking-path-sources
    - [Flushing Invalid Paths]#flushing-invalid-paths
  - [Configuration Files]#configuration-files
  - [Documentation]#documentation
  - [Technical Details]#technical-details
  - [Upgrading]#upgrading
  - [Known Issues]#known-issues
  - [Coming in Future Releases]#coming-in-future-releases
  - [**Features**]#features-1
  - [**Installation**]#installation
    - [**Prerequisites**]#prerequisites
    - [**Building from Source**]#building-from-source
  - [**Usage**]#usage-1
    - [**Command Overview**]#command-overview
    - [**Commands**]#commands
      - [**add**]#add
      - [**remove**]#remove
      - [**list**]#list
      - [**check**]#check
      - [**flush**]#flush
      - [**history**]#history
      - [**restore**]#restore
    - [**Examples**]#examples
  - [**Configuration**]#configuration
  - [**Backup Management**]#backup-management
    - [**Backup Modes**]#backup-modes
    - [**Backup Storage**]#backup-storage
  - [**Contributing**]#contributing
  - [**License**]#license

## **Introduction**

**pathmaster** is a powerful command-line tool written in Rust for managing your system's `PATH` environment variable. It simplifies the process of adding and removing directories from your `PATH`, ensures backups are created automatically, and provides tools to restore previous configurations.

Managing the `PATH` variable is crucial for system performance and command execution. `pathmaster` provides a safe and efficient way to handle `PATH` modifications, with features designed to prevent errors and maintain system stability.

# pathmaster

## New in Version 0.2.2

- Enhanced PATH validation and scanning capabilities
- Improved detection of PATH modifications across system
- Accurate identification of PATH entry sources
- Better handling of different shell configurations
- Fixed issues with PATH entry detection and validation

## Features

### Core Features (Updated in 0.2.2)

- **Enhanced PATH Scanning**: More accurate detection of PATH modifications
- **Source Identification**: Identifies whether PATH modifications require sudo
- **Improved Validation**: Better handling of different PATH modification formats
- **Shell Support**: Enhanced detection of shell-specific configurations
- **Framework Integration**: Better support for shell framework configurations
- **Safety Features**: Automatic backups, configuration preservation, validation

### Path Management

- Add/remove directories from PATH
- List current PATH entries
- Validate PATH entries
- Automatic backups
- Configuration preservation
- Detailed feedback

### Safety Features

- Automatic backups before modifications
- Shell configuration preservation
- Detailed user feedback
- Recovery options

## Usage

### Checking PATH Sources

```bash
pathmaster check
```

Now provides enhanced output showing:

- Invalid directories in PATH
- Source of each PATH modification
- Whether sudo is required for changes
- Shell-specific configuration details

### Flushing Invalid Paths

```bash
pathmaster flush
```

Improved in v0.2.2 with:

- More accurate invalid path detection
- Better feedback for removed paths
- Enhanced shell configuration handling
- Improved backup creation

## Configuration Files

pathmaster now better handles various configuration files:

- Shell-specific files (.bashrc, .zshrc)
- System-wide configurations (/etc/profile, etc.)
- Shell framework configurations
- Distribution-specific locations

## Documentation

Please see the man page (`man pathmaster`) for detailed information about all commands and features.

## Technical Details

For v0.2.2, significant improvements were made to:

- PATH modification detection
- Shell configuration handling
- System vs user file differentiation
- Framework integration
- Error handling and reporting

## Upgrading

When upgrading to v0.2.2:

1. Backup your current configuration
2. Update using your package manager or cargo
3. Review any system-wide PATH modifications
4. Check shell framework compatibility

## Known Issues

None in current release.

## Coming in Future Releases

- Backup mode configuration (v0.2.3)
- Additional shell framework support
- Enhanced configuration options
- Performance optimizations

## **Features**

- **Effortless Management**: Easily add or remove directories from your `PATH`.
- **Automatic Backups**: Creates time-stamped backups of your `PATH` before any changes.
- **Restoration**: Restore your `PATH` from any previous backup.
- **Listing**: View all current entries in your `PATH`.
- **Cross-Platform**: Compatible with Unix/Linux and macOS systems.
- **Safe Modifications**: Validates directories before adding them to prevent errors.
- **Persistent Changes**: Updates your shell configuration to make changes permanent.
- **Enhanced Path Validation**: Robust detection and removal of invalid PATH entries
- **Shell Configuration Safety**: Automatic backup of shell configuration files before modifications
- **Detailed Feedback**: Clear reporting of all PATH modifications and their outcomes
- **Session and Permanent Changes**: Updates both current session and shell configuration files

## **Installation**

### **Prerequisites**

- **Rust Toolchain**: Ensure you have Rust installed. You can install Rust using [rustup]https://www.rust-lang.org/tools/install:

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

### **Building from Source**

1. **Clone the Repository**

   ```bash
   git clone https://github.com/jwliles/pathmaster.git
   cd pathmaster
   ```

2. **Build the Project**

   ```bash
   cargo build --release
   ```

   This command compiles the project in release mode, producing an optimized binary.

3. **Install the Binary**

   Optionally, you can install the binary system-wide:

   ```bash
   sudo cp target/release/pathmaster /usr/local/bin/
   ```

   Or add it to your `PATH`:

   ```bash
   export PATH="$PATH:$(pwd)/target/release"
   ```

## **Usage**

### **Command Overview**

```bash
pathmaster [COMMAND] [OPTIONS]
```

### **Commands**

#### **add**

Add a directory to your `PATH`.

**Usage:**

```bash
pathmaster add <directory>
```

**Options:**

- `<directory>`: The directory path to add to your `PATH`.

#### **remove**

Remove a directory from your `PATH`.

**Usage:**

```bash
pathmaster remove <directory>
```

**Options:**

- `<directory>`: The directory path to remove from your `PATH`.

#### **list**

List all current entries in your `PATH`.

**Usage:**

```bash
pathmaster list
```

#### **check**

Validate current PATH entries and identify invalid or missing directories.

**Usage:**

```bash
pathmaster check
```

**Example Output:**

```bash
Invalid directories in PATH:
  /home/user/.config/emacs/bin
  /home/user/old/scripts
```

#### **flush**

The `flush` command provides a safe way to remove invalid directories from your PATH:

**Usage:**

```bash
pathmaster flush
# or
pathmaster -f
```

**Process:**

1. Creates a backup of current PATH
2. Creates a backup of shell configuration file
3. Identifies invalid directory entries
4. Removes invalid entries from PATH
5. Updates shell configuration for persistence
6. Provides detailed feedback about changes

**Safety Features:**

- Automatic PATH backup creation
- Shell configuration file backup
- Detailed removal reporting
- Recovery options via backup system
- Session-only fallback if configuration update fails

**Example Output:**

```bash
Created backup of shell config at: /home/user/.bashrc.bak
Removing invalid path: /home/user/.config/emacs/bin
Removing invalid path: /home/user/old/scripts
Successfully removed 2 invalid path(s) and updated shell configuration.
```

#### **history**

Show the backup history of your `PATH`.

**Usage:**

```bash
pathmaster history
```

#### **restore**

Restore your `PATH` from a previous backup.

**Usage:**

```bash
pathmaster restore [--timestamp <timestamp>]
```

**Options:**

- `--timestamp <timestamp>`: (Optional) The timestamp of the backup to restore. If not provided, the most recent backup is used.

### **Examples**

- **Add a Directory to PATH**

  ```bash
  pathmaster add ~/my/custom/bin
  ```

- **Remove a Directory from PATH**

  ```bash
  pathmaster remove ~/my/old/bin
  ```

- **List PATH Entries**

  ```bash
  pathmaster list
  ```

  **Sample Output:**

  ```
  Current PATH entries:
  - /usr/local/bin
  - /usr/bin
  - /bin
  - /usr/local/sbin
  - /usr/sbin
  - /sbin
  - ~/my/custom/bin
  ```

- **Show Backup History**

  ```bash
  pathmaster history
  ```

  **Sample Output:**

  ```
  Available backups:
  - backup_20231007_120000.json
  - backup_20231008_090000.json
  ```

- **Restore PATH from a Specific Backup**

  ```bash
  pathmaster restore --timestamp 20231007_120000
  ```

- **Restore PATH from the Most Recent Backup**

  ```bash
  pathmaster restore
  ```

## **Configuration**

`pathmaster` modifies your shell configuration file to make changes to `PATH` persistent across sessions.

- **Supported Shells**: Bash (`.bashrc`), Zsh (`.zshrc`), or a generic `.profile` if the shell is not recognized.
- **Backup Directory**: Backups are stored in `~/.pathmaster_backups`.

**Note**: Always review changes made to your shell configuration files. `pathmaster` adds an export command to update your `PATH`.

## **Backup Management**

pathmaster provides flexible backup management with configurable backup modes:

### **Backup Modes**

Use the `--backup-mode` flag to control what gets backed up:

- `default`: Back up both PATH and shell configurations (default behavior)
- `path`: Back up only PATH entries
- `shell`: Back up only shell configuration
- `switch`: Toggle between PATH-only and shell-only backups

**Examples:**

```bash
# Only back up PATH when adding a directory
pathmaster --backup-mode path add ~/bin

# Only back up shell config when flushing invalid paths
pathmaster --backup-mode shell flush

# Reset to backing up both
pathmaster --backup-mode default

# Toggle between backup modes
pathmaster --backup-mode switch
```

### **Backup Storage**

- **PATH Backups**: Stored as JSON files in `~/.pathmaster_backups`
- **Shell Configuration Backups**: Created as `.bak` files alongside your shell config:
  - Bash: `~/.bashrc.bak`
  - Zsh: `~/.zshrc.bak`
  - Generic: `~/.profile.bak`

## **Contributing**

Contributions are welcome! Please follow these steps:

1. **Fork the Repository**

2. **Create a Feature Branch**

   ```bash
   git checkout -b feature/your-feature
   ```

3. **Commit Your Changes**

   ```bash
   git commit -am 'Add your feature'
   ```

4. **Push to the Branch**

   ```bash
   git push origin feature/your-feature
   ```

5. **Create a Pull Request**

## **License**

This project is licensed under the MIT License - see the [LICENSE](LICENSE) file for details.