zsh-users
 help / color / mirror / code / Atom feed
* How to stop dir expansion in the prompt?
@ 2014-11-04  3:23 Shiyao Ma
  2014-11-04  3:43 ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Shiyao Ma @ 2014-11-04  3:23 UTC (permalink / raw)
  To: zsh-users

Hi.
I am using this prompt:

PROMPT="%(?.${success_color}.${failure_color})${SSH_TTY:+[%n@%m]}%B%${max_path_chars}<...<"'${vcs_info_msg_0_%%}'"%<<%(!.${root_char}.${user_char})%b%f
"

The whole script is here: https://bpaste.net/show/52184a546984#56


If I cd to a directory like ~/.virtualenvs, the prompt will show as
~WORKON_HOME.
It's expanded to the environment variable WORKON_HOME.

I wonder, is there a option to disable the auto expansion?

If not, possible to modify the above prompt to show the real path?
Note, it's not a straightforward modification like ${PWD/#$HOME/~}
because vcs_info_msg_0 is inside and should be taken care of.



Thanks in advance.


Regards.




-- 

吾輩は猫である。ホームーページはhttp://introo.me。


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to stop dir expansion in the prompt?
  2014-11-04  3:23 How to stop dir expansion in the prompt? Shiyao Ma
@ 2014-11-04  3:43 ` Bart Schaefer
  2014-11-04  6:30   ` Shiyao Ma
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2014-11-04  3:43 UTC (permalink / raw)
  To: zsh-users

On Nov 4, 11:23am, Shiyao Ma wrote:
}
} If I cd to a directory like ~/.virtualenvs, the prompt will show as
} ~WORKON_HOME.
} 
} I wonder, is there a option to disable the auto expansion?

That expansion is the %~ prompt replacement, so one way to avoid this
is to change

    zstyle ':vcs_info:*' nvcsformats "%~" ""

to

    zstyle ':vcs_info:*' nvcsformats "%2d" ""

or similar.

If this is unsatisfactory, you should

    unsetopt AUTO_NAME_DIRS

and possibly also

    unsetopt CDABLE_VARS

unless you are actually using those features.  There's no way to disable
the action of %~ on named directories once a named directory entry is
created.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to stop dir expansion in the prompt?
  2014-11-04  3:43 ` Bart Schaefer
@ 2014-11-04  6:30   ` Shiyao Ma
  2014-11-04  7:36     ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Shiyao Ma @ 2014-11-04  6:30 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Thanks.
Really a right direction.

I now set :
zstyle ':vcs_info:*' nvcsformats "%d" ""


To replace $HOME with ~, I do this:
PROMPT="%(?.${success_color}.${failure_color})${SSH_TTY:+[%n@%m]}%B%${max_path_chars}<...<"'${${vcs_info_msg_0_%%}/#$HOME/~}'"%<<%(!.${root_char}.${user_char})%b%f
"

But it doesn't work as if the replace never happened.
(Does zsh support nested variable expansion?)

Where am I doing wrong?


Regards

2014-11-04 11:43 GMT+08:00 Bart Schaefer <schaefer@brasslantern.com>:
> On Nov 4, 11:23am, Shiyao Ma wrote:
> }
> } If I cd to a directory like ~/.virtualenvs, the prompt will show as
> } ~WORKON_HOME.
> }
> } I wonder, is there a option to disable the auto expansion?
>
> That expansion is the %~ prompt replacement, so one way to avoid this
> is to change
>
>     zstyle ':vcs_info:*' nvcsformats "%~" ""
>
> to
>
>     zstyle ':vcs_info:*' nvcsformats "%2d" ""
>
> or similar.
>
> If this is unsatisfactory, you should
>
>     unsetopt AUTO_NAME_DIRS
>
> and possibly also
>
>     unsetopt CDABLE_VARS
>
> unless you are actually using those features.  There's no way to disable
> the action of %~ on named directories once a named directory entry is
> created.



-- 

吾輩は猫である。ホームーページはhttp://introo.me。


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to stop dir expansion in the prompt?
  2014-11-04  6:30   ` Shiyao Ma
@ 2014-11-04  7:36     ` Bart Schaefer
  2014-11-04  9:42       ` Shiyao Ma
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2014-11-04  7:36 UTC (permalink / raw)
  To: zsh-users

On Nov 4,  2:30pm, Shiyao Ma wrote:
}
} To replace $HOME with ~, I do this:
} PROMPT="%(?.${success_color}.${failure_color})${SSH_TTY:+[%n@%m]}%B%${max_path_chars}<...<"'${${vcs_info_msg_0_%%}/#$HOME/~}'"%<<%(!.${root_char}.${user_char})%b%f
} "
} 
} Where am I doing wrong?

/#$HOME/ means the pattern has to match at the start of the string.
Are you sure the value of $vcs_info_msg_0_ starts with the directory
name?  Also, why is the %% in the inner expansion?  (I guess it was in
your original example too, but it's extraneous if there's nothing
between it and the closing brace.)

} (Does zsh support nested variable expansion?)

Yes.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to stop dir expansion in the prompt?
  2014-11-04  7:36     ` Bart Schaefer
@ 2014-11-04  9:42       ` Shiyao Ma
  2014-11-04 16:43         ` Bart Schaefer
  0 siblings, 1 reply; 7+ messages in thread
From: Shiyao Ma @ 2014-11-04  9:42 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

2014-11-04 15:36 GMT+08:00 Bart Schaefer <schaefer@brasslantern.com>:

> /#$HOME/ means the pattern has to match at the start of the string.
> Are you sure the value of $vcs_info_msg_0_ starts with the directory
> name?

When outside a vcs directory, `echo $vcs_info_msg_0_` gives %d, which
is the same string in zstyle nvcsformat.
So in this scenario, it would be better to let it expand to the actual
full path so that I can do the replacement.
Any idea on that? (My last idea is to insert a function into the
prompt, but it's ugly).


 >Also, why is the %% in the inner expansion?  (I guess it was in
> your original example too, but it's extraneous if there's nothing
> between it and the closing brace.)
Yup. One minor question. No matter how many % I write, like this
one:echo  ${vcs_info_msg_0_%%%%%}, it's the same as echo
${vcs_info_msg_0_}. So what's % here?


Again. Thanks for your help.


-- 

吾輩は猫である。ホームーページはhttp://introo.me。


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to stop dir expansion in the prompt?
  2014-11-04  9:42       ` Shiyao Ma
@ 2014-11-04 16:43         ` Bart Schaefer
  2014-11-05  1:27           ` Shiyao Ma
  0 siblings, 1 reply; 7+ messages in thread
From: Bart Schaefer @ 2014-11-04 16:43 UTC (permalink / raw)
  To: zsh-users, zsh-users

On Nov 4,  5:42pm, Shiyao Ma wrote:
}
} When outside a vcs directory, `echo $vcs_info_msg_0_` gives %d, which
} is the same string in zstyle nvcsformat.

Ah, of course.  You want:

PROMPT="%(?.${success_color}.${failure_color})${SSH_TTY:+[%n@%m]}%B%${max_path_chars}<...<"'${${(%)vcs_info_msg_0_}/#$HOME/~}'"%<<%(!.${root_char}.${user_char})%b%f
"

The (%) in ${(%)vcs_info_msg_0_} tells it to do prompt expansion right
away, rather than return the format for the prompt to expand later, so
then the /#$HOME/ can do its work.

} Yup. One minor question. No matter how many % I write, like this
} one:echo  ${vcs_info_msg_0_%%%%%}, it's the same as echo
} ${vcs_info_msg_0_}. So what's % here?

${NAME%PATTERN}
${NAME%%PATTERN}
     If the PATTERN matches the end of the value of NAME, then
     substitute the value of NAME with the matched portion deleted;
     otherwise, just substitute the value of NAME.  In the first form,
     the smallest matching pattern is preferred; in the second form,
     the largest matching pattern is preferred.

So after the first two %%, any more % you add become the pattern, which
is unlikely to match in a directory name.

I don't know why Julien left %% in there with no pattern after it.


^ permalink raw reply	[flat|nested] 7+ messages in thread

* Re: How to stop dir expansion in the prompt?
  2014-11-04 16:43         ` Bart Schaefer
@ 2014-11-05  1:27           ` Shiyao Ma
  0 siblings, 0 replies; 7+ messages in thread
From: Shiyao Ma @ 2014-11-05  1:27 UTC (permalink / raw)
  To: Bart Schaefer; +Cc: zsh-users

Thanks.

Problem solved.

2014-11-05 0:43 GMT+08:00 Bart Schaefer <schaefer@brasslantern.com>:
> On Nov 4,  5:42pm, Shiyao Ma wrote:
> }
> } When outside a vcs directory, `echo $vcs_info_msg_0_` gives %d, which
> } is the same string in zstyle nvcsformat.
>
> Ah, of course.  You want:
>
> PROMPT="%(?.${success_color}.${failure_color})${SSH_TTY:+[%n@%m]}%B%${max_path_chars}<...<"'${${(%)vcs_info_msg_0_}/#$HOME/~}'"%<<%(!.${root_char}.${user_char})%b%f
> "
>
> The (%) in ${(%)vcs_info_msg_0_} tells it to do prompt expansion right
> away, rather than return the format for the prompt to expand later, so
> then the /#$HOME/ can do its work.
>
> } Yup. One minor question. No matter how many % I write, like this
> } one:echo  ${vcs_info_msg_0_%%%%%}, it's the same as echo
> } ${vcs_info_msg_0_}. So what's % here?
>
> ${NAME%PATTERN}
> ${NAME%%PATTERN}
>      If the PATTERN matches the end of the value of NAME, then
>      substitute the value of NAME with the matched portion deleted;
>      otherwise, just substitute the value of NAME.  In the first form,
>      the smallest matching pattern is preferred; in the second form,
>      the largest matching pattern is preferred.
>
> So after the first two %%, any more % you add become the pattern, which
> is unlikely to match in a directory name.
>
> I don't know why Julien left %% in there with no pattern after it.



-- 

吾輩は猫である。ホームーページはhttp://introo.me。


^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2014-11-05  1:27 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2014-11-04  3:23 How to stop dir expansion in the prompt? Shiyao Ma
2014-11-04  3:43 ` Bart Schaefer
2014-11-04  6:30   ` Shiyao Ma
2014-11-04  7:36     ` Bart Schaefer
2014-11-04  9:42       ` Shiyao Ma
2014-11-04 16:43         ` Bart Schaefer
2014-11-05  1:27           ` Shiyao Ma

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).