diff --git a/dot/.bashrc.d/android-studio.bash b/dot/.bashrc.d/android-studio.bash index a1fbd7f..2fb75cf 100644 --- a/dot/.bashrc.d/android-studio.bash +++ b/dot/.bashrc.d/android-studio.bash @@ -5,7 +5,9 @@ unset basedir export JAVA_HOME="/opt/android-studio/jbr" export ANDROID_HOME="${HOME}/Android/Sdk" -export NDK_HOME="$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)" -add-to-path "${ANDROID_HOME}/emulator" "${ANDROID_HOME}/platform-tools" +if [[ -d "${ANDROID_HOME}/ndk" ]]; then + export NDK_HOME="$ANDROID_HOME/ndk/$(ls -1 $ANDROID_HOME/ndk)" +fi +add-to-path -s "${ANDROID_HOME}/emulator" "${ANDROID_HOME}/platform-tools" diff --git a/dot/.bashrc.d/function.bash b/dot/.bashrc.d/function.bash index 3fef356..3714360 100644 --- a/dot/.bashrc.d/function.bash +++ b/dot/.bashrc.d/function.bash @@ -31,13 +31,36 @@ generate-bash-completion() { } add-to-path() { - if [[ $# -eq 0 ]]; then - echo "usage: add-to-path [path2 ...]" >&2 + local silence=false + local -a dirs=() + + while [[ $# -gt 0 ]]; do + case "$1" in + -s) + silence=true + shift + ;; + --) + shift + dirs+=("$@") + break + ;; + *) + dirs+=("$1") + shift + ;; + esac + done + + if [[ ${#dirs[@]} -eq 0 ]]; then + echo "usage: add-to-path [-s] [path2 ...]" >&2 + echo "" >&2 + echo " -s: if some path not exist, just skip it silently" >&2 + echo "" >&2 echo "example: add-to-path /usr/local/bin /tmp/my-dir" >&2 return 1 fi - local -a dirs=("$@") local dir local dir_normalized local new_path="$PATH" @@ -47,7 +70,9 @@ add-to-path() { dir_normalized="${dir%/}" if [[ ! -d "$dir_normalized" ]]; then - echo "WARNING: '${dir}' is not a valid directory, skipped." >&2 + if [[ "$silence" == false ]]; then + echo "WARNING: '${dir}' is not a valid directory, skipped." >&2 + fi continue fi diff --git a/dot/.bashrc.d/pnpm.bash b/dot/.bashrc.d/pnpm.bash index 57633fd..5929129 100755 --- a/dot/.bashrc.d/pnpm.bash +++ b/dot/.bashrc.d/pnpm.bash @@ -4,7 +4,7 @@ source "${basedir}/function.bash" unset basedir export PNPM_HOME="${HOME}/.local/share/pnpm" -add-to-path $PNPM_HOME +add-to-path -s $PNPM_HOME if [[ -x "$(type -p pnpm)" ]]; then generate-bash-completion pnpm "pnpm completion bash" diff --git a/dot/.bashrc.d/volta.bash b/dot/.bashrc.d/volta.bash index 8d3d572..a0b2628 100644 --- a/dot/.bashrc.d/volta.bash +++ b/dot/.bashrc.d/volta.bash @@ -21,5 +21,3 @@ if [[ -x $(type -p volta) || -x "${VOLTA_HOME}/bin/volta" ]]; then unhash-command-in-dirs "$bin_dir" } fi - -