Export : Update for Nix.

This commit is contained in:
Dmitry Voronin 2024-01-24 17:05:52 +03:00
parent 1ea36ef9d3
commit b057f47294
2 changed files with 23 additions and 24 deletions

View file

@ -11,9 +11,6 @@ export EDITOR=nvim
# specify man page viewer. # specify man page viewer.
export MANPAGER="nvim +Man!" export MANPAGER="nvim +Man!"
# specify java path.
export JAVA_HOME="${HOME}/app/java/x64/latest"
# specify android sdk root. # specify android sdk root.
export ANDROID_SDK_ROOT="$HOME/.android/sdk" export ANDROID_SDK_ROOT="$HOME/.android/sdk"
@ -28,31 +25,14 @@ export TEXMFLOCAL="${HOME}/app/tex/data/local"
export BASH_MODULE_PATH="${HOME}/.config/bash/module" export BASH_MODULE_PATH="${HOME}/.config/bash/module"
# Set java version. Sets to latest when not specified. # Set java version. Sets to latest when not specified.
# Usage: export_java [VERSION] # Usage: export_java <VERSION>
function export_java() { function export_java() {
local version="${1}" local version="${1}"
if [[ "${version}" = "" ]]; then if [[ "${version}" = "" ]]; then
export JAVA_HOME="${HOME}/app/java/x64/latest" help export_java
return return 2
fi fi
local available=($(_get_java_versions)) export JAVA_HOME="$(find_nix openjdk-${version})"
if ! _contains ${version} ${available[@]}; then
_error "Version ${version} is not available."
return 1
fi
export JAVA_HOME="${HOME}/app/java/x64/jdk_${version}"
} }
function _get_java_versions() {
ls "${HOME}/app/java/x64/" | grep "jdk_" | sed -e "s/.*_//" | sort -g 2> /dev/null
}
function _comp_java_versions() {
_autocomplete_first "$(_get_java_versions)"
}
complete -o nosort -F _comp_java_versions export_java

View file

@ -0,0 +1,19 @@
# Find Nix package path.
# Usage: find_nix <PACKAGE>
function find_nix() {
local IFS=$'\n'
local package="${1}"
if [[ "${package}" = "" ]]; then
help find_nix
return 2
fi
local found=$(ls --classify /nix/store/ | grep "${package}".*/)
if [[ "${found}" != "" ]]; then
echo "/nix/store/${found%/}"
else
false
fi
}