Skip to content

Instantly share code, notes, and snippets.

@0x3333
Created March 18, 2022 13:42
Show Gist options
  • Save 0x3333/5e1875975b74d3c01727358e3ed9b112 to your computer and use it in GitHub Desktop.
Save 0x3333/5e1875975b74d3c01727358e3ed9b112 to your computer and use it in GitHub Desktop.
Initialize jenv only if inside a Java folder
function evaluate_jenv() {
if [ ! -v JENV_LOADED ]; then
setopt local_options nullglob
[ -f pom.xml -o -f build.gradle.kts -o -f build.sbt -o -f build.xml -o -f .java-version -o -f .deps.edn -o -f project.clj -o -f build.boot ] && files=1
if [ ! -v files ]; then
extensions=(*.java, *.class, *.gradle, *.jar, *.cljs, *.cljc)
if [ -z "$extensions" ]; then
return
fi
fi
echo "Initializing jenv..."
eval "$(jenv init -)"
fi
}
typeset -a precmd_functions
precmd_functions+=(evaluate_jenv)

jenv initializer

jenv is a nice app, but its bootstrap is slow. I dislike initializing it every terminal I open.

I created this zsh function to initialize it only if you enter a directory of a java project.

It is evaluated before the prompt using precmd function.

  /   cd /tmp
Initializing jenv...
  /home/user/java/project/ via ☕ v11.0.15 
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment