Skip to content

Commit 8c9c722

Browse files
committed
add proj config command, remove legacy DEV_ROOT, minor help text updates
1 parent 2205436 commit 8c9c722

File tree

4 files changed

+54
-43
lines changed

4 files changed

+54
-43
lines changed

CHANGELOG.md

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,19 @@ This project follows the [Keep a Changelog](https://keepachangelog.com/) convent
1414
- `completion.bats`
1515
- `proj_config_sets_root.bats`
1616

17+
## [0.1.4] - 2025-06-30
18+
19+
### Added
20+
21+
- Sub‑command `proj config <dir>` for setting **PROJ_DEV_ROOT** and persisting it to _~/.zshrc_.
22+
- Tab‑completion support for the new sub‑command.
23+
24+
### Changed
25+
26+
- Replaced the standalone helper `proj-config` with the new sub‑command.
27+
- Removed legacy **DEV_ROOT** variable; the plugin now relies solely on **PROJ_DEV_ROOT**.
28+
- Updated help text, completion logic, and internal code to reflect the single‑variable configuration.
29+
1730
## [0.1.3] - 2025‑06‑30
1831

1932
### Added

README.md

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
```text
66
proj listy # → /Volumes/dog_house/development/projects/listy
77
proj # fuzzy‑pick a project (needs fzf)
8-
proj-config ~/code # one‑time helper to set a different root
8+
proj config ~/code # one‑time helper to set a different root
99
```
1010

1111
--------------------------------------------------------------------------------
@@ -16,7 +16,7 @@ proj-config ~/code # one‑time helper to set a different root
1616
- **One‑word `proj <name>`** – faster than typing long paths.
1717
- **Interactive picker** – choose from a fuzzy list when you just run `proj` (uses **fzf** if available).
1818
- **Tab completion**`proj sa<Tab>``proj savage`.
19-
- **Config helper**`proj-config /path` adds `export PROJ_DEV_ROOT=/path` to your `.zshrc`.
19+
- **Config helper**`proj config /path` adds `export PROJ_DEV_ROOT=/path` to your `.zshrc`.
2020

2121
--------------------------------------------------------------------------------
2222

@@ -52,14 +52,13 @@ Jump to a project | `proj savage` | `cd` into _savage_
5252
Pick interactively | `proj` | fuzzy list via **fzf**
5353
List projects (no fzf) | `proj` | prints directory names
5454
Tab‑complete | `proj li<Tab>` | expands to _listy_
55-
Set a new root | `proj-config ~/code` | writes `export PROJ_DEV_ROOT=~/code` to `.zshrc`
55+
Set a new root | `proj config ~/code` | writes `export PROJ_DEV_ROOT=~/code` to `.zshrc`
5656

5757
### Environment variables
5858

5959
Variable | Purpose
60-
--------------- | ----------------------------------------------------------------------
61-
`PROJ_DEV_ROOT` | Override the default root (`/Volumes/dog_house/development/projects`).
62-
`DEV_ROOT` | Alias kept for compatibility.
60+
--------------- | ------------------------------------------------
61+
`PROJ_DEV_ROOT` | Override the default root (`$HOME/development`).
6362

6463
--------------------------------------------------------------------------------
6564

_proj

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
11
#compdef proj
22

33
_arguments \
4-
'1:project name:_files -W "$DEV_ROOT" -/"*"' && return 0
4+
'1:project name:_files -W "$PROJ_DEV_ROOT" -/"*"' && return 0

proj-jumper.plugin.zsh

Lines changed: 35 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,10 @@
11
#!/usr/bin/env zsh
22
# proj-jumper — jump quickly into a project directory under $DEV_ROOT
3-
# v0.1.3-dev
3+
# v0.1.4-dev
44

55
# -------- configuration ------
6-
: ${DEV_ROOT:=${PROJ_DEV_ROOT:-"~/development"}}
7-
# allow users to export PROJ_DEV_ROOT or DEV_ROOT to override
8-
export DEV_ROOT
6+
# A single variable controls the root; fallback is ~/development.
7+
: ${PROJ_DEV_ROOT:="$HOME/development"}
98

109
# ───────── help text ─────────
1110
_proj_usage() {
@@ -14,20 +13,20 @@ proj-jumper — jump to project directories
1413
1514
Usage:
1615
proj <name> cd into the project called <name>
16+
proj config <dir> set PROJ_DEV_ROOT to <dir> and save it in ~/.zshrc
1717
proj interactive picker (fzf if available, else list)
1818
proj -h | --help show this help
1919
2020
Options:
2121
-h, --help display this help and exit
2222
2323
Environment variables:
24-
PROJ_DEV_ROOT override the default root path ($DEV_ROOT)
25-
DEV_ROOT same as above (kept for compatibility)
24+
PROJ_DEV_ROOT override the default root path ($PROJ_DEV_ROOT)
2625
2726
Examples:
28-
proj savage → cd \$DEV_ROOT/savage
27+
proj savage → cd \$PROJ_DEV_ROOT/savage
2928
proj → fuzzy-select a project
30-
proj-config ~/code → write export PROJ_DEV_ROOT=~/code to ~/.zshrc
29+
proj config ~/code → write export PROJ_DEV_ROOT=~/code to ~/.zshrc
3130
EOF
3231
}
3332

@@ -37,53 +36,53 @@ proj () {
3736
# 0. help first
3837
[[ "$1" == "-h" || "$1" == "--help" ]] && { _proj_usage; return 0 }
3938

39+
# configure root
40+
if [[ "$1" == "config" ]]; then
41+
local new_root=$2
42+
if [[ -z $new_root ]]; then
43+
print -u2 "Usage: proj config /path/to/root"
44+
return 1
45+
fi
46+
[[ -d $new_root ]] || { print -u2 "Directory does not exist: $new_root"; return 1; }
47+
48+
export PROJ_DEV_ROOT="$new_root"
49+
local rcfile=${ZDOTDIR:-$HOME}/.zshrc
50+
sed -i '' '/^export PROJ_DEV_ROOT=/d' "$rcfile"
51+
echo "export PROJ_DEV_ROOT=$new_root" >>"$rcfile"
52+
print "PROJ_DEV_ROOT set to $new_root (added to $rcfile)."
53+
print "Restart your shell or run: source $rcfile"
54+
return 0
55+
fi
56+
57+
local root="${PROJ_DEV_ROOT:-$HOME/development}"
58+
59+
4060
# 1. verify disk
41-
[[ -d $DEV_ROOT ]] || { print -u2 "⚠️ $DEV_ROOT not found"; return 1 }
61+
[[ -d $root ]] || { print -u2 "⚠️ $root not found"; return 1 }
4262

4363
# 2. arg-aware behaviour
4464
if [[ -z $1 ]]; then
4565
# no arg → interactive picker if fzf present, else list
4666
if command -v fzf >/dev/null; then
4767
local sel
48-
sel=$(command ls -1 "$DEV_ROOT" | fzf --prompt='project> ')
49-
[[ -n $sel ]] && cd "$DEV_ROOT/$sel"
68+
sel=$(command ls -1 "$root" | fzf --prompt='project> ')
69+
[[ -n $sel ]] && cd "$root/$sel"
5070
else
51-
print "Projects:"; command ls "$DEV_ROOT"
71+
print "Projects:"; command ls "$root"
5272
fi
5373
else
5474
# arg → direct cd with safety
55-
local target="$DEV_ROOT/$1"
75+
local target="$root/$1"
5676
[[ -d $target ]] && cd "$target" || {
5777
print -u2 "No such project: $1"; return 1
5878
}
5979
fi
6080
}
6181

62-
# ───────── config helper ─────────
63-
proj-config () {
64-
local new_root=${1:-}
65-
[[ -z $new_root ]] && {
66-
print -u2 "Usage: proj-config /path/to/root"
67-
return 1
68-
}
69-
if [[ ! -d $new_root ]]; then
70-
print -u2 "Directory does not exist: $new_root"
71-
return 1
72-
fi
73-
74-
local rcfile=${ZDOTDIR:-$HOME}/.zshrc
75-
# strip any existing line that sets the var, then append the new one
76-
sed -i '' '/^export PROJ_DEV_ROOT=/d' "$rcfile"
77-
echo "export PROJ_DEV_ROOT=$new_root" >>"$rcfile"
78-
print "PROJ_DEV_ROOT set to $new_root (added to $rcfile)."
79-
print "Restart your shell or run: source $rcfile"
80-
}
81-
compdef _files proj-config # tab-complete directories
82-
8382
# ─────── completion helpers ───────
8483
# Late-bound because the volume could mount after shell start
8584
_proj_complete () {
86-
[[ -d $DEV_ROOT ]] || return
87-
compadd -- $(command ls -1 "$DEV_ROOT")
85+
local root="${PROJ_DEV_ROOT:-$HOME/development}"
86+
[[ -d $root ]] || returncompadd -- $(command ls -1 "$root")
8887
}
8988
compdef _proj_complete proj

0 commit comments

Comments
 (0)