diff --git a/config/fish/functions/fish_right_prompt.fish b/config/fish/functions/fish_right_prompt.fish index ae29d58..a81d078 100644 --- a/config/fish/functions/fish_right_prompt.fish +++ b/config/fish/functions/fish_right_prompt.fish @@ -5,6 +5,6 @@ function fish_right_prompt if contains rbenv (functions) echo $red(rbenv version-name)$normal else if contains asdf (functions) - echo $red(asdf current ruby | awk '{print $2}')$normal + echo $red(fast-asdf-ruby-version | awk '$1 == "ruby" { print $2 }')$normal end end diff --git a/local/bin/fast-asdf-ruby-version b/local/bin/fast-asdf-ruby-version new file mode 100755 index 0000000..1e7bee6 --- /dev/null +++ b/local/bin/fast-asdf-ruby-version @@ -0,0 +1,31 @@ +#!/bin/bash + +asdf_path="$PWD" +asdf_info= + +# Make sure asdf is currently active. +if [ "$ASDF_DIR" ]; then + + # Traverse up directories until we hit an asdf directory or filesystem root. + while [ -z "$asdf_info" -o $asdf_path != '' ]; do + if [ -f "$asdf_path/.tool-versions" ]; then + asdf_path="$asdf_path/.tool-versions" + break + elif [ -f "$asdf_path/.ruby-version" ]; then + asdf_path="$asdf_path/.ruby-version" + break + else + asdf_path="${asdf_path%/*}" + fi + done + + # Use array manipulations and IFS to replace newlines with '/'. + if [ -f "$asdf_path" ]; then + IFS=$'\n' + asdf_info=($(<"$asdf_path")) + IFS='/' + asdf_info="${asdf_info[*]}" + fi +fi + +echo $asdf_info diff --git a/tool-versions b/tool-versions index a7e49f2..e69d0de 100644 --- a/tool-versions +++ b/tool-versions @@ -1 +1,2 @@ ruby 3.0.1 +nodejs 14.17.3