On Sat, Aug 26, 2017 at 3:43 PM, Andrew Toskin <summerfallsa...@gmail.com>
wrote:

> I have my fish prompt configured to show the full absolute path of the
> current working directory, if there's enough room. I do this by running `wc
> --chars` on the full generated prompt, and comparing with $COLUMNS. The
> wc part of this test looks like this:
>
> echo -n "$USER@$__fish_prompt_hostname" ( pwd )( __fish_vcs_prompt ) | wc 
> --chars
>
>
> When in the directory of a local git project, by my count, that echo
> command generates a string that's 59 characters long. However, wc counts
> 101 characters. What's going on here that would explain this 42-character
> discrepency?
>
> When trying to research the issue, I saw a lot of forum posts where wc
> counted one extra character, because echo by default appends a newline, but
> doing echo -n takes care of that issue.
>
> I then thought that maybe wc was counting bytes instead of characters, in
> spite of the --chars switch, but when I copy-paste the generated prompt
> string and echo *that* to wc, it counts the correct number of characters.
> This discrepency only happens in VCS directories, when __fish_vcs_prompt
> has anything to show. Are there 42 control characters involved in setting
> the colors for __fish_vcs_prompt? How do I get an accurate count of the
> characters in my prompt string?
>

As you guessed it's almost certainly escape sequences to color the output.
Run `__fish_vcs_prompt | od -tx1z` to see them. At the moment there is no
good way to get a count of the displayable characters. I opened an issue to
propose implementing a `string width` command to help with this but it
hasn't been implemented yet.



-- 
Kurtis Rader
Caretaker of the exceptional canines Junior and Hank
------------------------------------------------------------------------------
Check out the vibrant tech community on one of the world's most
engaging tech sites, Slashdot.org! http://sdm.link/slashdot
_______________________________________________
Fish-users mailing list
Fish-users@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/fish-users

Reply via email to