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
1514Usage:
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
2020Options:
2121 -h, --help display this help and exit
2222
2323Environment 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
2726Examples:
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
3130EOF
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}
8988compdef _proj_complete proj
0 commit comments