Skip to content

Instantly share code, notes, and snippets.

@ax3l
Last active June 30, 2020 04:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ax3l/0eff53b4db43865b769414a76247daa9 to your computer and use it in GitHub Desktop.
Save ax3l/0eff53b4db43865b769414a76247daa9 to your computer and use it in GitHub Desktop.
multiple_pkg_managers
# snippet for file: $HOME/.bashrc
#
# License: CC0
#
# register a bash function that calls the script above
activate-env () {
. $HOME/bin/impl-activate-env $@
}
# bash completion for the above function
_activate-env()
{
local cur prev names
cur="${COMP_WORDS[COMP_CWORD]}"
prv="${COMP_WORDS[COMP_CWORD]}"
names="conda emsdk rust spack brew" # all primary options
if [ "${COMP_WORDS[1]}" == "conda" ]; then # sub envs: conda
local cenvs=$(ls $HOME/sw/miniconda3/envs)
COMPREPLY=( $(compgen -W "${cenvs}" -- ${cur}))
return 0;
fi
if [ ${COMP_CWORD} -gt 1 ]; then return 0; fi # no other sub
if [ "${cur}" == "" ]; then # no arg
COMPREPLY=(${names})
else # during arg eval
COMPREPLY=($(compgen -W "${names}" -- ${cur}))
fi
}
complete -F _activate-env activate-env
# file: $HOME/bin/impl-activate-env
#
# License: CC0
#
case "${1}" in
conda)
export PATH="$HOME/src/miniconda3/bin:${PATH}"
conda_env=${2:-base}
source activate ${conda_env}
if [ "${conda_env}" == "base" ]; then
conda info --envs
echo "Activate via: \"conda activate <env>\""
echo "New environments:"
echo " conda create -n py36 python=3.6 anaconda"
echo " conda create -n openpmd-api -c conda-forge openpmd-api"
fi
;;
brew)
eval $($HOME/src/brew/bin/brew shellenv)
;;
spack)
. $HOME/src/spack/share/spack/setup-env.sh
spack env list
echo "Activate via: \"spack env activate <env>\""
;;
rust)
export PATH="$HOME/.cargo/bin:${PATH}"
;;
emsdk)
source $HOME/src/emsdk/emsdk_env.sh --build=Release
export CC=$(which emcc)
export CXX=$(which em++)
echo -n "Reminder: -DCMAKE_TOOLCHAIN_FILE=$HOME/src/"
echo "emscripten/cmake/Modules/Platform/Emscripten.cmake"
;;
*)
echo "Usage: $0 {conda [env]|emsdk|rust|spack|brew}"
esac
# file: .bashrc
# register a bash function that calls the script above
activate-env () {
. $HOME/bin/impl-activate-env $@
}
# bash completion for the above function
_activate-env()
{
local cur prev names
cur="${COMP_WORDS[COMP_CWORD]}"
prv="${COMP_WORDS[COMP_CWORD]}"
names="conda emsdk rust spack brew" # all primary options
if [ "${COMP_WORDS[1]}" == "conda" ]; then # sub envs: conda
local cenvs=$(ls $HOME/sw/miniconda3/envs)
COMPREPLY=( $(compgen -W "${cenvs}" -- ${cur}))
return 0;
fi
if [ ${COMP_CWORD} -gt 1 ]; then return 0; fi # no other sub
if [ "${cur}" == "" ]; then # no arg
COMPREPLY=(${names})
else # during arg eval
COMPREPLY=($(compgen -W "${names}" -- ${cur}))
fi
}
complete -F _activate-env activate-env
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment