Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 34 additions & 18 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,24 +73,6 @@ curl -sSL https://raw.githubusercontent.com/s33g/proj/main/scripts/install.sh |
proj
```

### Shell Integration (Recommended)

To enable the "Change Directory" feature, add this to your `~/.bashrc` or `~/.zshrc`:

```bash
# proj - TUI project navigator
proj() {
local output=$(mktemp)
PROJ_CD_FILE="$output" command ~/.local/bin/proj "$@"
if [ -s "$output" ]; then
cd "$(cat "$output")"
fi
rm -f "$output"
}
```

Then reload your shell: `source ~/.bashrc`

## Usage

### Keyboard Shortcuts
Expand Down Expand Up @@ -147,6 +129,40 @@ When you select a project, these actions are available:

> See [docs/DOCKER.md](docs/DOCKER.md) for full Docker integration guide

## Shell Integration

Shell integration allows `proj` to change your terminal's working directory when you navigate to a project.

### Automatic Setup

The installer will detect your shell and set up integration automatically:

```bash
curl -sSL https://raw.githubusercontent.com/s33g/proj/main/scripts/install.sh | bash
```

### Supported Shells

- **Bash** - Full support with auto-detection
- **Zsh** - Full support with auto-detection
- **Fish** - Full support with auto-detection
- **Others** - Manual setup required (see [docs](docs/INSTALL.md#shell-integration))

### Manual Setup

For manual integration or unsupported shells, see:
- [Installation Guide](docs/INSTALL.md#shell-integration) - Setup instructions
- [Contributing Guide](docs/CONTRIBUTING.md#adding-shell-support) - Adding new shell support

### How It Works

1. The installer creates a wrapper function that replaces the `proj` command
2. When you select a project in the TUI, `proj` writes the target directory to a temporary file
3. The wrapper function reads this file and changes to that directory
4. Your shell's working directory is now in the selected project

Without shell integration, `proj` still works perfectly - you just won't get automatic directory changes.

## Configuration

Configuration is stored in `~/.config/proj/config.json`.
Expand Down
34 changes: 1 addition & 33 deletions docs/CONFIG.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,9 +48,7 @@ proj --config # Open config in $EDITOR
},
"display": {
"showHiddenDirs": false,
"sortBy": "lastModified",
"showGitStatus": true,
"showLanguage": true
"sortBy": "lastModified"
},
"excludePatterns": [
".git",
Expand Down Expand Up @@ -305,36 +303,6 @@ How to sort projects in the list.
}
```

#### display.showGitStatus

**Type:** `boolean`
**Default:** `true`

Whether to show git branch and dirty status in the project list.

```json
{
"display": {
"showGitStatus": false
}
}
```

#### display.showLanguage

**Type:** `boolean`
**Default:** `true`

Whether to show detected language in the project list.

```json
{
"display": {
"showLanguage": false
}
}
```

---

### excludePatterns
Expand Down
102 changes: 102 additions & 0 deletions docs/CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -264,6 +264,108 @@ make test-coverage
- Add comments to exported types and functions
- Include examples where helpful

## Adding Shell Support

proj supports shell integration to enable directory changing from the TUI. We welcome contributions for additional shell support!

### How Shell Integration Works

Shell integration uses a wrapper function that:
1. Runs the actual `proj` binary with user arguments
2. Checks for a temporary file at `~/.config/proj/.proj_last_dir`
3. Changes to the directory specified in that file (if it exists)
4. Cleans up the temporary file

The Go binary writes to this file when a project is selected in the TUI.

### Adding a New Shell

To add support for a new shell:

1. **Create the integration script:**
```bash
touch scripts/shells/yourshell.ext
```

2. **Implement the wrapper function** following this pattern:
```shell
# Your shell's syntax for defining functions
proj() {
# Store original directory
original_dir=$(pwd) # or your shell's equivalent

# Run the actual proj binary
command proj "$@" # or your shell's equivalent for passing args

# Check for directory change file
proj_dir_file="$HOME/.config/proj/.proj_last_dir"
if [ -f "$proj_dir_file" ]; then
target_dir=$(cat "$proj_dir_file")
if [ -d "$target_dir" ] && [ "$target_dir" != "$original_dir" ]; then
echo "Changing to: $target_dir"
cd "$target_dir"
fi
rm -f "$proj_dir_file"
fi
}
```

3. **Add auto-setup detection** for when the script is sourced:
```shell
# Your shell's method for detecting if sourced vs executed
if [[ sourced_condition ]]; then
setup_function_or_direct_call
fi
```

4. **Update the installer script** in `scripts/install.sh`:
- Add your shell to the case statement in `setup_shell_integration()`
- Create a `setup_yourshell_integration()` function
- Follow the pattern used by bash/zsh/fish functions

5. **Test your integration:**
```bash
# Source your script manually
source scripts/shells/yourshell.ext

# Test the proj function
proj
# Navigate to a project and verify directory changes work
```

6. **Add examples to documentation:**
- Add manual setup instructions to `docs/INSTALL.md`
- Include your shell in supported shells list

### Supported Shells

Currently supported:
- **bash** (`scripts/shells/bash.sh`)
- **zsh** (`scripts/shells/zsh.sh`)
- **fish** (`scripts/shells/fish.fish`)

Requested shells (contributions welcome):
- PowerShell
- Nushell
- Elvish
- Oil
- Ion
- Xonsh

### Shell Integration Examples

See existing implementations for reference:
- [Bash integration](../scripts/shells/bash.sh)
- [Zsh integration](../scripts/shells/zsh.sh)
- [Fish integration](../scripts/shells/fish.fish)

When contributing shell support, please ensure:
- The wrapper function preserves all `proj` arguments
- Error handling doesn't break the shell session
- The integration works in both interactive and non-interactive modes
- Clean up temporary files properly
- Follow your shell's best practices for function definitions

## Pull Request Process

1. **Ensure all tests pass:**
Expand Down
124 changes: 70 additions & 54 deletions docs/INSTALL.md
Original file line number Diff line number Diff line change
Expand Up @@ -157,58 +157,7 @@ proj --set-path ~/code

Replace `~/code` with your actual projects directory.

### 5. Shell Integration (Highly Recommended)

Shell integration enables the "Change Directory" action to actually change your terminal's current directory.

**For Bash (`~/.bashrc`):**

```bash
# proj - TUI project navigator
proj() {
local output=$(mktemp)
PROJ_CD_FILE="$output" command ~/.local/bin/proj "$@"
if [ -s "$output" ]; then
cd "$(cat "$output")"
fi
rm -f "$output"
}
```

**For Zsh (`~/.zshrc`):**

```zsh
# proj - TUI project navigator
proj() {
local output=$(mktemp)
PROJ_CD_FILE="$output" command ~/.local/bin/proj "$@"
if [ -s "$output" ]; then
cd "$(cat "$output")"
fi
rm -f "$output"
}
```

**For Fish (`~/.config/fish/config.fish`):**

```fish
# proj - TUI project navigator
function proj
set -l output (mktemp)
PROJ_CD_FILE="$output" command ~/.local/bin/proj $argv
if test -s "$output"
cd (cat "$output")
end
rm -f "$output"
end
```

Then reload your shell:
```bash
source ~/.bashrc # or ~/.zshrc, or restart terminal
```

### 6. Test Everything
### 5. Test Everything

```bash
# Launch the TUI
Expand Down Expand Up @@ -298,8 +247,8 @@ chmod +x ~/.local/bin/proj
Shell integration is not set up.

**Solution:**
1. Add the shell function from [Step 5](#5-shell-integration-highly-recommended)
2. Reload your shell: `source ~/.bashrc`
1. See [Shell Integration](#shell-integration) section below
2. Reload your shell: `source ~/.bashrc` or start a new terminal
3. Use `proj` (the function) not `~/.local/bin/proj` (the binary)

### Old version still running
Expand Down Expand Up @@ -374,6 +323,73 @@ cd proj
make install
```

## Shell Integration

Shell integration allows `proj` to change your current directory when you navigate to a project. This feature is optional but highly recommended.

### Automatic Setup

The install script will automatically detect your shell and offer to set up integration:

```bash
curl -sSL https://raw.githubusercontent.com/s33g/proj/main/scripts/install.sh | bash
```

### Manual Setup

If automatic setup doesn't work or you prefer manual setup:

#### Bash
```bash
# Download the integration script
curl -sSL https://raw.githubusercontent.com/s33g/proj/main/scripts/shells/bash.sh -o ~/.config/proj/bash_integration.sh

# Add to ~/.bashrc
echo 'source ~/.config/proj/bash_integration.sh' >> ~/.bashrc

# Reload shell
source ~/.bashrc
```

#### Zsh
```bash
# Download the integration script
curl -sSL https://raw.githubusercontent.com/s33g/proj/main/scripts/shells/zsh.sh -o ~/.config/proj/zsh_integration.sh

# Add to ~/.zshrc
echo 'source ~/.config/proj/zsh_integration.sh' >> ~/.zshrc

# Reload shell
source ~/.zshrc
```

#### Fish
```bash
# Download the integration script
curl -sSL https://raw.githubusercontent.com/s33g/proj/main/scripts/shells/fish.fish -o ~/.config/fish/conf.d/proj.fish

# Integration will be active in new fish sessions
```

### Unsupported Shells

For shells not listed above (PowerShell, Nushell, Elvish, etc.), you can:

1. **Contribute support**: See [Adding Shell Support](CONTRIBUTING.md#adding-shell-support)
2. **Manual integration**: Create your own wrapper function based on the examples
3. **Use without integration**: `proj` works fine without shell integration, you just won't get automatic directory changes

### How It Works

Shell integration works by:
1. Creating a wrapper function that replaces the `proj` command
2. Running the actual `proj` binary with your arguments
3. Checking for a temporary file containing the target directory
4. Changing to that directory if it exists
5. Cleaning up the temporary file

The temporary file is created at `~/.config/proj/.proj_last_dir` when you select a project in the TUI.

## Installation Locations

| Location | Description |
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ require (
github.com/charmbracelet/bubbles v0.21.0
github.com/charmbracelet/bubbletea v1.3.10
github.com/charmbracelet/lipgloss v1.1.0
github.com/spf13/cobra v1.10.2
github.com/spf13/viper v1.21.0
)

Expand Down Expand Up @@ -36,7 +37,6 @@ require (
github.com/sourcegraph/conc v0.3.1-0.20240121214520-5f936abd7ae8 // indirect
github.com/spf13/afero v1.15.0 // indirect
github.com/spf13/cast v1.10.0 // indirect
github.com/spf13/cobra v1.10.2 // indirect
github.com/spf13/pflag v1.0.10 // indirect
github.com/subosito/gotenv v1.6.0 // indirect
github.com/xo/terminfo v0.0.0-20220910002029-abceb7e1c41e // indirect
Expand Down
Loading
Loading