powerlevel10k icon indicating copy to clipboard operation
powerlevel10k copied to clipboard

Feature request: add segment for rtx

Open dhanak opened this issue 1 year ago • 21 comments

rtx is a drop-in replacement for asdf, serving identical purposes. It is compatible with asdf in many respects, including the backend and the CLI. It would be great if p10k had a segment for rtx as well as asdf.

dhanak avatar Mar 07 '23 10:03 dhanak

I managed to create an implementation by copy-pasting the asdf functions, deleting what seemed to be unnecessary, and piggybacking on the ASDF p10k settings.

function prompt_rtx() {

emulate -L zsh -o extended_glob

typeset -ga _p9k_rtx_meta_files
typeset -ga _p9k_rtx_meta_non_files
typeset -g  _p9k_rtx_meta_sig

# plugin => installed_version_pattern
# example: (ruby '2.7.0|2.6.3|system' lua 'system' chubaka '1.0.0|system')
typeset -gA _p9k_rtx_plugins

# dir => mtime ':' ${(pj:\0:)files}
typeset -gA _p9k_rtx_dir2files

# :file       => mtime ':' ${(pj:\0:)tool_versions}
# plugin:file => mtime ':' version
typeset -gA _p9k_rtx_file2versions

function _p9k_rtx_check_meta() {
    [[ -n $_p9k_rtx_meta_sig ]] || return
    [[ -z $^_p9k_rtx_meta_non_files(#qN) ]] || return
    local -a stat
    if (( $#_p9k_rtx_meta_files )); then
        zstat -A stat +mtime -- $_p9k_rtx_meta_files 2>/dev/null || return
    fi
    [[ $_p9k_rtx_meta_sig == $RTX_CONFIG_FILE$'\0'$RTX_DATA_DIR$'\0'${(pj:\0:)stat} ]] || return
}

function _p9k_rtx_init_meta() {
    local last_sig=$_p9k_rtx_meta_sig
    {
        local -a files

        _p9k_rtx_plugins=()

        local cfg=${RTX_CONFIG_FILE:-~/.config/rtx/config.toml}
        files+=$cfg
        local root=${RTX_DATA_DIR:-~/.local/share/rtx}
        files+=$root/plugins
        if [[ -d $root/plugins ]]; then
            local plugin
            for plugin in $root/plugins/[^[:space:]]##(/N); do
                files+=$root/installs/${plugin:t}
                local -aU installed=($root/installs/${plugin:t}/[^[:space:]]##(/N:t) system)
                _p9k_rtx_plugins[${plugin:t}]=${(j:|:)${(@b)installed}}
            done
        fi

        _p9k_rtx_meta_files=($^files(N))
        _p9k_rtx_meta_non_files=(${files:|_p9k_rtx_meta_files})

        local -a stat
        if (( $#_p9k_rtx_meta_files )); then
            zstat -A stat +mtime -- $_p9k_rtx_meta_files 2>/dev/null || return
        fi
        _p9k_rtx_meta_sig=$RTX_CONFIG_FILE$'\0'$RTX_DATA_DIR$'\0'${(pj:\0:)stat}
        _p9k_rtx_dir2files=()
        _p9k_rtx_file2versions=()
    } always {
        if (( $? == 0 )); then
            _p9k__state_dump_scheduled=1
            return
        fi
        [[ -n $last_sig ]] && _p9k__state_dump_scheduled=1
        _p9k_rtx_meta_files=()
        _p9k_rtx_meta_non_files=()
        _p9k_rtx_meta_sig=
        _p9k_rtx_plugins=()
        _p9k_rtx_dir2files=()
        _p9k_rtx_file2versions=()
    }
}

# Usage: _p9k_rtx_parse_version_file <file>
#
# Mutates `versions` on success.
function _p9k_rtx_parse_version_file() {
    local file=$1
    local -a stat
    zstat -A stat +mtime $file 2>/dev/null || return
    local cached=$_p9k_rtx_file2versions[:$file]
    if [[ $cached == $stat[1]:* ]]; then
        local file_versions=(${(0)${cached#*:}})
    else
        local file_versions=()
        { local lines=(${(@)${(@)${(f)"$(<$file)"}%$'\r'}/\#*}) } 2>/dev/null
        local line
        for line in $lines; do
            local words=($=line)
            (( $#words > 1 )) || continue
            local installed=$_p9k_rtx_plugins[$words[1]]
            [[ -n $installed ]] || continue
            file_versions+=($words[1] ${${words:1}[(r)$installed]:-$words[2]})
        done
        _p9k_rtx_file2versions[:$file]=$stat[1]:${(pj:\0:)file_versions}
        _p9k__state_dump_scheduled=1
    fi
    local plugin version
    for plugin version in $file_versions; do
        : ${versions[$plugin]=$version}
    done
    return 0
}

_p9k_rtx_check_meta || _p9k_rtx_init_meta || return

local -A versions
local -a stat
local -i has_global
local dirs=($_p9k__parent_dirs)
local mtimes=($_p9k__parent_mtimes)
if [[ $dirs[-1] != ~ ]]; then
    zstat -A stat +mtime ~ 2>/dev/null || return
    dirs+=(~)
    mtimes+=($stat[1])
fi

local elem
for elem in ${(@)${:-{1..$#dirs}}/(#m)*/${${:-$MATCH:$_p9k_rtx_dir2files[$dirs[MATCH]]}#$MATCH:$mtimes[MATCH]:}}; do
    if [[ $elem == *:* ]]; then
        local dir=$dirs[${elem%%:*}]
        zstat -A stat +mtime $dir 2>/dev/null || return
        local files=($dir/.tool-versions(N))
        _p9k_rtx_dir2files[$dir]=$stat[1]:${(pj:\0:)files}
    else
        local files=(${(0)elem})
    fi
    if [[ ${files[1]:h} == ~ ]]; then
        has_global=1
        local -A local_versions=(${(kv)versions})
        versions=()
    fi
    local file=
    for file in $files; do
        _p9k_rtx_parse_version_file $file || return
    done
done

if (( ! has_global )); then
    has_global=1
    local -A local_versions=(${(kv)versions})
    versions=()
fi

if [[ -r $RTX_DEFAULT_TOOL_VERSIONS_FILENAME ]]; then
    _p9k_rtx_parse_version_file $RTX_DEFAULT_TOOL_VERSIONS_FILENAME || return
fi

local plugin
for plugin in ${(k)_p9k_rtx_plugins}; do
    local upper=${${(U)plugin//-/_}//İ/I}
    if (( $+parameters[_POWERLEVEL9K_ASDF_${upper}_SOURCES] )); then
        local sources=(${(P)${:-_POWERLEVEL9K_ASDF_${upper}_SOURCES}})
    else
        local sources=($_POWERLEVEL9K_ASDF_SOURCES)
    fi

    local version="${(P)${:-RTX_${upper}_VERSION}}"
    if [[ -n $version ]]; then
        (( $sources[(I)shell] )) || continue
    else
        version=$local_versions[$plugin]
        if [[ -n $version ]]; then
            (( $sources[(I)local] )) || continue
        else
            version=$versions[$plugin]
            [[ -n $version ]] || continue
            (( $sources[(I)global] )) || continue
        fi
    fi

    if [[ $version == $versions[$plugin] ]]; then
        if (( $+parameters[_POWERLEVEL9K_ASDF_${upper}_PROMPT_ALWAYS_SHOW] )); then
            (( _POWERLEVEL9K_ASDF_${upper}_PROMPT_ALWAYS_SHOW )) || continue
        else
            (( _POWERLEVEL9K_ASDF_PROMPT_ALWAYS_SHOW )) || continue
        fi
    fi

    if [[ $version == system ]]; then
        if (( $+parameters[_POWERLEVEL9K_ASDF_${upper}_SHOW_SYSTEM] )); then
            (( _POWERLEVEL9K_ASDF_${upper}_SHOW_SYSTEM )) || continue
        else
            (( _POWERLEVEL9K_ASDF_SHOW_SYSTEM )) || continue
        fi
    fi

    _p9k_get_icon prompt_asdf_$upper ${upper}_ICON $plugin
    _p9k_prompt_segment prompt_asdf_$upper green $_p9k_color1 $'\1'$_p9k__ret 0 '' ${version//\%/%%}
done

}

POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[(r)asdf]=(asdf rtx)

I'm sure it could be done much better, I don't really understand half of what is going on up there. But it might be a good start, and it does the job for me (for now).

Also, this doesn't work for .rtx.toml files, it only supports .tool-versions files.

dhanak avatar Mar 09 '23 09:03 dhanak

Rtx is quite fast, so it may also be reasonable to use its output rather than parsing config files (it's definitely easier 🙂). I'm currently using this for an rtx segment:

function prompt_rtx() {
  local plugins=("${(@f)$(rtx current)}")
  local plugin
  for plugin in ${(k)plugins}; do
    local parts=("${(@s/ /)plugin}")
    local upper=${(U)parts[1]}
    local version=${parts[2]}

    _p9k_get_icon prompt_rtx_$upper ${upper}_ICON $plugin
    _p9k_prompt_segment prompt_rtx_$upper green $_p9k_color1 $'\1'$_p9k__ret 0 '' ${version//\%/%%}
  done
}

typeset -g POWERLEVEL9K_RTX_FOREGROUND=$CYAN
typeset -g POWERLEVEL9K_RTX_RUBY_FOREGROUND=$RED 
...

jason0x43 avatar Mar 24 '23 23:03 jason0x43

@jason0x43 Thanks for sharing!

Seems this should promising, but I’m not sure where to include this or if there is more to it.

I've tried but _p9k_ stuff is … dense. 😄

travismiller avatar Mar 29 '23 23:03 travismiller

I included the prompt_rtx function and the color definitions near the end of my p10k.zsh config, and I added rtx to the POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS list:

  typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
    # =========================[ Line #1 ]=========================
    status                  # exit code of the last command
    command_execution_time  # duration of the last command
    background_jobs         # presence of background jobs
    direnv                  # direnv status (https://direnv.net/)
    npm                     # custom npm registry host
    asdf                    # asdf version manager (https://github.com/asdf-vm/asdf)
    rtx                     # rtx version manager (https://github.com/jdxcode/rtx)
    virtualenv              # python virtual environment (https://docs.python.org/3/library/venv.html)
    ...

I've tried but p9k stuff is … dense.

Very dense.

jason0x43 avatar Mar 29 '23 23:03 jason0x43

Thanks @jason0x43! I forgot about POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS. 🤦‍♂️

I found that until I removed the asdf plugin, it was continuing to print versions to prompt and rtx wasn't actually working for me. Here is my current working implementation with an oh-my-zsh custom plugin.

  • ${(k)_p9k_rtx_plugins} was not working for me so I tweaked the version parsing
  • Rather than defining the colors with POWERLEVEL9K_RTX_*_FOREGROUND variables, I'm just relying on the existing POWERLEVEL9K_ASDF_*_FOREGROUND variables
  • Added _p9k_prompt_rtx_init like all the other prompts, but I don’t really know what it does or if it’s necessary.
  • I couldn't figure out how to work around the instant prompt warning like you can with direnv.

~/.zshrc

# …

export ZSH="/Users/travis/.oh-my-zsh"

ZSH_THEME=powerlevel10k/powerlevel10k

plugins=(git rtx)

source $ZSH/oh-my-zsh.sh

[[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh

# …

~/.oh-my-zsh/custom/plugins/rtx/rtx.plugin.zsh

# Oh My Zsh plugin for rtx
#
# https://github.com/jdxcode/rtx
# https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/asdf
# https://github.com/ohmyzsh/ohmyzsh/tree/master/plugins/direnv
# [Feature request: add segment for rtx](https://github.com/romkatv/powerlevel10k/issues/2212)
#
# TODO: Instant Prompt
# - https://github.com/romkatv/powerlevel10k/issues/702#issuecomment-626222730
# - https://github.com/romkatv/powerlevel10k#how-do-i-initialize-direnv-when-using-instant-prompt
#

# Don't continue if rtx is not found
command -v rtx &>/dev/null || return

source <(rtx activate zsh)

function prompt_rtx() {
  local plugin_versions=("${(@f)$(rtx current 2>/dev/null)}")
  local plugin_version
  for plugin_version in $plugin_versions; do
    local parts=("${(@s/ /)plugin_version}")
    local plugin=${parts[1]}
    local version=${parts[2]}
    local upper=${(U)plugin}

    _p9k_get_icon prompt_asdf_$upper ${upper}_ICON $plugin
    _p9k_prompt_segment prompt_asdf_$upper green $_p9k_color1 $'\1'$_p9k__ret 0 '' ${version//\%/%%}
  done
}

_p9k_prompt_rtx_init() {
  typeset -g "_p9k__segment_cond_${_p9k__prompt_side}[_p9k__segment_index]"='${commands[rtx]:-${${+functions[rtx]}:#0}}'
}

~/.p10k.zsh

# …

# The list of segments shown on the right. Fill it with less important segments.
# Right prompt on the last prompt line (where you are typing your commands) gets
# automatically hidden when the input line reaches it. Right prompt above the
# last prompt line gets hidden if it would overlap with left prompt.
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(
  # =========================[ Line #1 ]=========================
  status                  # exit code of the last command
  command_execution_time  # duration of the last command
  background_jobs         # presence of background jobs
  direnv                  # direnv status (https://direnv.net/)
  #asdf                   # asdf version manager (https://github.com/asdf-vm/asdf)
  rtx                     # rtx version manager (https://github.com/jdxcode/rtx)
  virtualenv              # python virtual environment (https://docs.python.org/3/library/venv.html)

# …

# Instant prompt mode.
#
#   - off:     Disable instant prompt. Choose this if you've tried instant prompt and found
#              it incompatible with your zsh configuration files.
#   - quiet:   Enable instant prompt and don't print warnings when detecting console output
#              during zsh initialization. Choose this if you've read and understood
#              https://github.com/romkatv/powerlevel10k/blob/master/README.md#instant-prompt.
#   - verbose: Enable instant prompt and print a warning when detecting console output during
#              zsh initialization. Choose this if you've never tried instant prompt, haven't
#              seen the warning, or if you are unsure what this all means.
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet

# …
image

travismiller avatar Mar 31 '23 17:03 travismiller

Keep in mind that all powerlevel10k variables and functions that start with an underscore are internal. If you use them, your prompt can do anything when you update powerlevel10k. It might delete all your files or turn mouse on fire. There are no guarantees whatsoever.

romkatv avatar Mar 31 '23 17:03 romkatv

${(k)_p9k_rtx_plugins} was not working for me so I tweaked the version parsing

Sorry about that -- I had actually fixed that locally and forgotten to update my post.

Keep in mind that all powerlevel10k variables and functions that start with an underscore are internal.

For some reason I entirely forgot about p10k segment, even though I was already using that for another custom segment. 🤦

A better version:

  function prompt_rtx() {
    local plugins=("${(@f)$(rtx current)}")
    local plugin
    for plugin in ${(k)plugins}; do
      local parts=("${(@s/ /)plugin}")
      local tool=${(U)parts[1]}
      local version=${parts[2]}
      p10k segment -r -i "${tool}_ICON" -s $tool -t "$version"
    done
  }

p10k segment will automatically use POWERLEVEL9K_RTX_*_FOREGROUND colors and POWERLEVEL9K_RTX_*_VISUAL_IDENTIFIER_EXPANSION replacement icons.

jason0x43 avatar Mar 31 '23 17:03 jason0x43

OK, here’s where I am now. Thank you!

  • No longer mixing concerns: oh-my-zsh plugin and p10k prompt hook
  • rtx current 2>/dev/null so that prompt hook doesn’t leak missing tool warnings (rtx activate zsh handles that)
  • Mutate POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS which by default includes asdf from p10k configure.

https://gist.github.com/travismiller/7a22b3a1227a9d0ac3cc2d2b33921abd

# Powerlevel10k prompt segments for rtx
#
# https://github.com/romkatv/powerlevel10k
# https://github.com/jdxcode/rtx
# [Feature request: add segment for rtx](https://github.com/romkatv/powerlevel10k/issues/2212)
#
# Usage in ~/.zshrc:
#
#   # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
#   [[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh
#   [[ -f ~/.p10k.rtx.zsh ]] && source ~/.p10k.rtx.zsh
#

() {
  function prompt_rtx() {
    local plugins=("${(@f)$(rtx current 2>/dev/null)}")
    local plugin
    for plugin in ${(k)plugins}; do
      local parts=("${(@s/ /)plugin}")
      local tool=${(U)parts[1]}
      local version=${parts[2]}
      p10k segment -r -i "${tool}_ICON" -s $tool -t "$version"
    done
  }

  typeset -g POWERLEVEL9K_RTX_FOREGROUND=66

  typeset -g POWERLEVEL9K_RTX_DOTNET_CORE_FOREGROUND=134
  typeset -g POWERLEVEL9K_RTX_ELIXIR_FOREGROUND=129
  typeset -g POWERLEVEL9K_RTX_ERLANG_FOREGROUND=125
  typeset -g POWERLEVEL9K_RTX_FLUTTER_FOREGROUND=38
  typeset -g POWERLEVEL9K_RTX_GOLANG_FOREGROUND=37
  typeset -g POWERLEVEL9K_RTX_HASKELL_FOREGROUND=172
  typeset -g POWERLEVEL9K_RTX_JAVA_FOREGROUND=32
  typeset -g POWERLEVEL9K_RTX_JULIA_FOREGROUND=70
  typeset -g POWERLEVEL9K_RTX_LUA_FOREGROUND=32
  typeset -g POWERLEVEL9K_RTX_NODEJS_FOREGROUND=70
  typeset -g POWERLEVEL9K_RTX_PERL_FOREGROUND=67
  typeset -g POWERLEVEL9K_RTX_PHP_FOREGROUND=99
  typeset -g POWERLEVEL9K_RTX_POSTGRES_FOREGROUND=31
  typeset -g POWERLEVEL9K_RTX_PYTHON_FOREGROUND=37
  typeset -g POWERLEVEL9K_RTX_RUBY_FOREGROUND=168
  typeset -g POWERLEVEL9K_RTX_RUST_FOREGROUND=37

  # Substitute the default asdf prompt element
  typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=("${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]/asdf/rtx}")
}

travismiller avatar Mar 31 '23 20:03 travismiller

https://gist.github.com/travismiller/7a22b3a1227a9d0ac3cc2d2b33921abd

Thanks for this. I used your code as a base and made a small change so that it excludes tools defined in ~/.tool-versions, since I only care if a tool version differs from the global config.

local plugins=("${(@f)$(rtx ls --current 2>/dev/null | awk '$3!="~/.tool-versions" {print $1, $2}')}")

For example, if the output of rtx ls --current is:

nodejs 18.16.0 ~/.tool-versions               lts
python 3.11.3  ~/.tool-versions               3.11.3
ruby   3.2.2   ~/Developer/MySampleProject/.ruby-version 3.2.2

It will only show ruby in the prompt

 3.2.2

landonepps avatar May 30 '23 19:05 landonepps

@landonepps I modified your code for people that prefer to use ~/.config/rtx/config.toml (which is the default if you run rtx use -g [package@version]), and also added a check for (symlink) because if you install node@lts it will be displayed like this:

> rtx ls --current
node   lts (symlink) ~/.config/rtx/config.toml      lts

So we have to account for that extra string.

Here is the code:

local plugins=("${(@f)$(rtx ls --current 2>/dev/null | awk '!/\(symlink\)/ && $3!="~/.config/rtx/config.toml" {print $1, $2}')}")

pprotas avatar Aug 09 '23 07:08 pprotas

Thanks a lot for this :) I use 8 instead of 256 colors. So I updated mine like this.

# Powerlevel10k prompt segments for rtx
#
# https://github.com/romkatv/powerlevel10k
# https://github.com/jdxcode/rtx
# [Feature request: add segment for rtx](https://github.com/romkatv/powerlevel10k/issues/2212)
#
# Usage in ~/.zshrc:
#
#   # To customize prompt, run `p10k configure` or edit ~/.p10k.zsh.
#   [[ -f ~/.p10k.zsh ]] && source ~/.p10k.zsh
#   [[ -f ~/.p10k.rtx.zsh ]] && source ~/.p10k.rtx.zsh
#

() {
  function prompt_rtx() {
    local plugins=("${(@f)$(rtx ls --current 2>/dev/null | awk '!/\(symlink\)/ && $3!="~/.tool-versions" && $3!="~/.config/rtx/config.toml" {print $1, $2}')}")
    local plugin
    for plugin in ${(k)plugins}; do
      local parts=("${(@s/ /)plugin}")
      local tool=${(U)parts[1]}
      local version=${parts[2]}
      p10k segment -r -i "${tool}_ICON" -s $tool -t "$version"
    done
  }

  typeset -g POWERLEVEL9K_RTX_FOREGROUND=6

  typeset -g POWERLEVEL9K_RTX_RUBY_FOREGROUND=1
  typeset -g POWERLEVEL9K_RTX_PYTHON_FOREGROUND=6
  typeset -g POWERLEVEL9K_RTX_GOLANG_FOREGROUND=6
  typeset -g POWERLEVEL9K_RTX_NODEJS_FOREGROUND=2
  typeset -g POWERLEVEL9K_RTX_RUST_FOREGROUND=4
  typeset -g POWERLEVEL9K_RTX_DOTNET_CORE_FOREGROUND=5
  typeset -g POWERLEVEL9K_RTX_FLUTTER_FOREGROUND=4
  typeset -g POWERLEVEL9K_RTX_LUA_FOREGROUND=4
  typeset -g POWERLEVEL9K_RTX_JAVA_FOREGROUND=4
  typeset -g POWERLEVEL9K_RTX_PERL_FOREGROUND=6
  typeset -g POWERLEVEL9K_RTX_ERLANG_FOREGROUND=1
  typeset -g POWERLEVEL9K_RTX_ELIXIR_FOREGROUND=5
  typeset -g POWERLEVEL9K_RTX_POSTGRES_FOREGROUND=6
  typeset -g POWERLEVEL9K_RTX_PHP_FOREGROUND=5
  typeset -g POWERLEVEL9K_RTX_HASKELL_FOREGROUND=3
  typeset -g POWERLEVEL9K_RTX_JULIA_FOREGROUND=2

  # Substitute the default asdf prompt element
  typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=("${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]/asdf/rtx}")
}

deepanchal avatar Aug 19 '23 18:08 deepanchal

Thanks a lot this looks great, for people who want to use background colors in their prompts, you can add this

  typeset -g POWERLEVEL9K_RTX_RUBY_BACKGROUND=196

Result will look like so:

image

My full p10k.rtx.zsh if you are interested: https://github.com/2KAbhishek/dots2k/blob/main/config/shell/p10k.rtx.zsh

2KAbhishek avatar Oct 03 '23 08:10 2KAbhishek

Not sure about you guys, but I'm thinking of getting rid of this. rtx ls takes 100ms or more. This results in the p10k prompt to be a bit delayed. When I remove the rtx-related configs from my ~/.p10k.zsh, the prompt feels much snappier.

So every time I enter a command, there is a noticeable delay before the prompt shows up again fully. This little delay really annoys me over time, especially in situations where I want to type in multiple commands in quick succession.

Any thoughts?

pprotas avatar Oct 27 '23 17:10 pprotas

rtx has been renamed to mise

  • https://mise.jdx.dev/rtx.html
  • https://github.com/jdx/mise/releases/tag/v2024.1.0

deepanchal avatar Jan 10 '24 17:01 deepanchal

I have updated the script to use mise

# Powerlevel10k prompt segments for mise
# [Feature request: add segment for mise](https://github.com/romkatv/powerlevel10k/issues/2212)
# Usage in ~/.zshrc:
#   [[ -f ~/.config/shell/p10k.mise.zsh ]] && source ~/.config/shell/p10k.mise.zsh

() {
  function prompt_mise() {
    local plugins=("${(@f)$(mise ls --current 2>/dev/null | awk '!/\(symlink\)/ && $3!="~/.tool-versions" && $3!="~/.config/mise/config.toml" {print $1, $2}')}")
    local plugin
    for plugin in ${(k)plugins}; do
      local parts=("${(@s/ /)plugin}")
      local tool=${(U)parts[1]}
      local version=${parts[2]}
      p10k segment -r -i "${tool}_ICON" -s $tool -t "$version"
    done
  }

  # Colors
  typeset -g POWERLEVEL9K_MISE_BACKGROUND=1

  typeset -g POWERLEVEL9K_MISE_DOTNET_CORE_BACKGROUND=5
  typeset -g POWERLEVEL9K_MISE_ELIXIR_BACKGROUND=5
  typeset -g POWERLEVEL9K_MISE_ERLANG_BACKGROUND=1
  typeset -g POWERLEVEL9K_MISE_FLUTTER_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_GOLANG_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_HASKELL_BACKGROUND=3
  typeset -g POWERLEVEL9K_MISE_JAVA_BACKGROUND=7
  typeset -g POWERLEVEL9K_MISE_JULIA_BACKGROUND=2
  typeset -g POWERLEVEL9K_MISE_LUA_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_NODEJS_BACKGROUND=2
  typeset -g POWERLEVEL9K_MISE_PERL_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_PHP_BACKGROUND=5
  typeset -g POWERLEVEL9K_MISE_POSTGRES_BACKGROUND=6
  typeset -g POWERLEVEL9K_MISE_PYTHON_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_RUBY_BACKGROUND=1
  typeset -g POWERLEVEL9K_MISE_RUST_BACKGROUND=208

  # Substitute the default asdf prompt element
  typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=("${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]/asdf/mise}")
}

Link to file: https://github.com/2KAbhishek/dots2k/blob/main/config/shell/p10k.mise.zsh

2KAbhishek avatar Jan 12 '24 12:01 2KAbhishek

I have updated the script to use mise

# Powerlevel10k prompt segments for mise
# [Feature request: add segment for mise](https://github.com/romkatv/powerlevel10k/issues/2212)
# Usage in ~/.zshrc:
#   [[ -f ~/.config/shell/p10k.mise.zsh ]] && source ~/.config/shell/p10k.mise.zsh

() {
  function prompt_mise() {
    local plugins=("${(@f)$(mise ls --current 2>/dev/null | awk '!/\(symlink\)/ && $3!="~/.tool-versions" && $3!="~/.config/mise/config.toml" {print $1, $2}')}")
    local plugin
    for plugin in ${(k)plugins}; do
      local parts=("${(@s/ /)plugin}")
      local tool=${(U)parts[1]}
      local version=${parts[2]}
      p10k segment -r -i "${tool}_ICON" -s $tool -t "$version"
    done
  }

  # Colors
  typeset -g POWERLEVEL9K_MISE_BACKGROUND=1

  typeset -g POWERLEVEL9K_MISE_DOTNET_CORE_BACKGROUND=5
  typeset -g POWERLEVEL9K_MISE_ELIXIR_BACKGROUND=5
  typeset -g POWERLEVEL9K_MISE_ERLANG_BACKGROUND=1
  typeset -g POWERLEVEL9K_MISE_FLUTTER_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_GOLANG_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_HASKELL_BACKGROUND=3
  typeset -g POWERLEVEL9K_MISE_JAVA_BACKGROUND=7
  typeset -g POWERLEVEL9K_MISE_JULIA_BACKGROUND=2
  typeset -g POWERLEVEL9K_MISE_LUA_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_NODEJS_BACKGROUND=2
  typeset -g POWERLEVEL9K_MISE_PERL_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_PHP_BACKGROUND=5
  typeset -g POWERLEVEL9K_MISE_POSTGRES_BACKGROUND=6
  typeset -g POWERLEVEL9K_MISE_PYTHON_BACKGROUND=4
  typeset -g POWERLEVEL9K_MISE_RUBY_BACKGROUND=1
  typeset -g POWERLEVEL9K_MISE_RUST_BACKGROUND=208

  # Substitute the default asdf prompt element
  typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=("${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]/asdf/mise}")
}

Link to file: 2KAbhishek/dots2k@main/config/shell/p10k.mise.zsh

getting error: zsh: unrecognized modifier 'F'

MustCodeAl avatar Apr 03 '24 03:04 MustCodeAl

@2KAbhishek thanks for the updated script for mise! What is the purpose of the !/\(symlink\)/ expression in the awk command? Under what condition does the string (symlink) show up in mise ls --current and in what column?

From an example project of mine:

$ mise ls --current
Plugin  Version  Config Source     Requested
node    18.16.0  ~/…/.node-version 18.16.0
ruby    3.2.2    ~/…/.ruby-version 3.2.2

travismiller avatar Apr 03 '24 21:04 travismiller

@travismiller I believe the awk command is filtering the output of mise ls --current to exclude lines that contain the string "symlink"

I'm not sure under what condition it shows up, this is something I got from another response in this issue

2KAbhishek avatar Apr 05 '24 06:04 2KAbhishek

@2KAbhishek I migrated from asdf to mise. To avoid re-downloading every Go install, (and I was only experimenting with mise initially so for being able to switch back to asdf,) I symlinked asdf's Go installs to mise's directory:

# listing a few only
$ ls -lah  ~/.local/share/mise/installs/go
total 0
drwxr-xr-x  32 frederick  frederick   1.0K 24 May 13:30 .
drwxr-xr-x   8 frederick  frederick   256B 24 Jan 11:53 ..
lrwxr-xr-x   1 frederick  frederick    52B 22 Feb 13:01 1.19 -> /Users/frederick/.asdf/installs/golang/1.19/go
lrwxr-xr-x   1 frederick  frederick    55B 22 Feb 13:01 1.19.12 -> /Users/frederick/.asdf/installs/golang/1.19.12/go
lrwxr-xr-x   1 frederick  frederick    54B 22 Feb 13:01 1.19.2 -> /Users/frederick/.asdf/installs/golang/1.19.2/go
lrwxr-xr-x   1 frederick  frederick    54B 22 Feb 13:01 1.19.3 -> /Users/frederick/.asdf/installs/golang/1.19.3/go
lrwxr-xr-x   1 frederick  frederick    52B 29 Jan 12:47 1.19.4 -> /Users/frederick/.asdf/installs/golang/1.19.12
lrwxr-xr-x   1 frederick  frederick    54B 22 Feb 13:01 1.19.6 -> /Users/frederick/.asdf/installs/golang/1.19.6/go

$ mise list go
Plugin  Version            Config Source Requested
go      1.19 (symlink)
go      1.19.2 (symlink)
go      1.19.3 (symlink)
go      1.19.4 (symlink)
go      1.19.6 (symlink)

Frederick888 avatar May 27 '24 07:05 Frederick888