As a developer, I am always on the lookout for improving the configuration of my laptop. I want it to behave in a way that works best for me. I use z shell together with Oh My Zsh to work faster within a console.
One trick I like is extending your command prompt. You can extend oh-my-zsh very easily using shell scripts. Using these scripts, you can make a JDK switch or add Conda to your path.
First, locate the installation folder of oh-my-zsh. On the Mac, it can be found here:
~/.oh-my-zshIn here there is a folder custom. Within this folder, create a file with the .zsh extension. That is it, really.
~/.oh-my-zsh/custom/setjava.zshCheck below for two examples.
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/jettrocoenradie/Development/anaconda/anaconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/Users/jettrocoenradie/Development/anaconda/anaconda3/etc/profile.d/conda.sh" ]; then
. "/Users/jettrocoenradie/Development/anaconda/anaconda3/etc/profile.d/conda.sh"
CONDA_CHANGEPS1=false conda activate base
else
export PATH="/Users/jettrocoenradie/Development/anaconda/anaconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda init <<<
export PATH="/Users/jettrocoenradie/Development/anaconda/anaconda3/bin:$PATH"# Provide a function to switch between java installations
function setjdk() {
if [ $# -ne 0 ]; then
removeFromPath '/System/Library/Frameworks/JavaVM.framework/Home/bin'
if [ -n "${JAVA_HOME+x}" ]; then
removeFromPath $JAVA_HOME
fi
export JAVA_HOME=`/usr/libexec/java_home -v $@`
export PATH=$JAVA_HOME/bin:$PATH
fi
}
function removeFromPath() {
export PATH=$(echo $PATH | sed -E -e "s;:$1;;" -e "s;$1:?;;")
}
# set the default java sdk
setjdk 11
Originally published on
jettro.dev