From b057f47294decc69c458ce6d002bfe9afd6007cf Mon Sep 17 00:00:00 2001 From: Dmitry Voronin Date: Wed, 24 Jan 2024 17:05:52 +0300 Subject: [PATCH] Export : Update for Nix. --- .config/bash/module/Export.sh | 28 ++++------------------------ .config/bash/module/Nix.sh | 19 +++++++++++++++++++ 2 files changed, 23 insertions(+), 24 deletions(-) create mode 100644 .config/bash/module/Nix.sh diff --git a/.config/bash/module/Export.sh b/.config/bash/module/Export.sh index 1467d0c..6c07192 100644 --- a/.config/bash/module/Export.sh +++ b/.config/bash/module/Export.sh @@ -11,9 +11,6 @@ export EDITOR=nvim # specify man page viewer. export MANPAGER="nvim +Man!" -# specify java path. -export JAVA_HOME="${HOME}/app/java/x64/latest" - # specify android sdk root. 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" # Set java version. Sets to latest when not specified. -# Usage: export_java [VERSION] +# Usage: export_java function export_java() { local version="${1}" if [[ "${version}" = "" ]]; then - export JAVA_HOME="${HOME}/app/java/x64/latest" - return + help export_java + return 2 fi - local available=($(_get_java_versions)) - - if ! _contains ${version} ${available[@]}; then - _error "Version ${version} is not available." - return 1 - fi - - export JAVA_HOME="${HOME}/app/java/x64/jdk_${version}" + export JAVA_HOME="$(find_nix openjdk-${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 diff --git a/.config/bash/module/Nix.sh b/.config/bash/module/Nix.sh new file mode 100644 index 0000000..d1c61cd --- /dev/null +++ b/.config/bash/module/Nix.sh @@ -0,0 +1,19 @@ +# Find Nix package path. +# Usage: find_nix +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 +}