Skip to content

invarianz/pj

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 

Repository files navigation

(P)ro(j)ect → pj

pj is a simple, fully POSIX-compliant shell script that lets you set project directories ($PJROOT) and set an environment variable ($PJ) when you enter them via the cli.

  • Goals: Keep it short, simple, and POSIX-compliant
  • Non-Goals:

Installation

Copy pj to a directory on your $PATH, for example:

cp pj /usr/local/bin
chmod +x /usr/local/bin/pj

Ensure that $PJROOT is set.

Usage

export PJROOT="$HOME/Projects:$HOME/Tools:$HOME/DB"
cd() { # cd with auto ls and pj setting
	command cd "$@" >/dev/null || return 1
	pj_buf=$(pj -s)
	[ -n "$pj_buf" ] && export PJ="$pj_buf"
	unset pj_buf
}
p() { # Fast  Project dir jumping
	if [ "$#" -eq 0 ]; then
		if [ -n "$PJ" ]; then
			cd "$PJ" || return 3
			return 0
		else
			echo "Error: No project set" >&2
			return 4
		fi
	elif [ "$1" = "-d" ]; then
		unset PJ
		return 0
	elif [ "$#" -eq 1 ]; then
		for proj in $(pj -a); do
			case "${proj##*\/}" in
			"$1"*)
				cd "$proj" || return 3
				return 0
			;;
			esac
		done
		echo "Error: No project folder found" >&2
		return 5
	else
		echo "Usage: p projectdir"
		return 2
	fi
}

About

POSIX script to set a project environment variable when a project directory is entered.

Resources

License

Stars

Watchers

Forks

Languages