romkatv / powerlevel10k

A Zsh theme

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

alias expansion

p1r473 opened this issue · comments

Hi,
I've added

function prompt_my_alias() {
  p10k segment -b blue -f yellow -e -t '${my_expanded_command//\%/%%}'
}

function p10k-on-post-widget() {
  emulate -L zsh
  local buf=$PREBUFFER$BUFFER
  local words=(${(Z+C+)buf})
  words[1]=$aliases[$words[1]]
  local cmd
  [[ -n $words[1] ]] && cmd="$words"
  if [[ $cmd != $my_expanded_command ]]; then
    my_expanded_command="$cmd"
    p10k display -r
  fi
}

POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(my_alias)

to my ~/.p10k.zsh however I cant seem to get alias expansion to work

What are you trying to achieve?

I am trying to get the aliases to autoexpand as I type them
For example. Ive aliased ssh. So when I type ssh, it should expand to what its aliased to
Adding in some debug statements shows it does print stuff in the debug statements but it never expands the prompt to show the alias

  print "Buffer: $buf"
  print "Command: $cmd"
  print "Expanded Command: $my_expanded_command"

Powerlevel10k is a prompt. It doesn't do anything other than displaying prompt. What you are trying to achieve cannot be done through powerlevel10k because auto-expanding aliases isn't about displaying prompt.

Can you explain to me what that code is supposed to do then that I found on that other issue?
I am trying to get the alias to show what its aliased to

The original issue says "I was looking for a way to display a right prompt segment displaying the expanded value of an alias, while typing, if the command being typed on the command line would expand as an alias." which is what I am trying to do

The first two functions define a prompt segment. The last line adds that segment to right prompt.

So there is no way to get the prompt to change what I am typing to be an expanded alias?

Like so:
ssh is an alias to custom_ssh

So if I type on the prompt
$ ssh
it expands to
$ custom_ssh

and allows me to keep typing

Zsh is very flexible, so you can of course achieve this. Only not with powerlevel10k because powerlevel10k is a prompt. It cannot do anything other than display prompt.