lukesampson / pshazz

Give your powershell some pizazz.
The Unlicense
577 stars 40 forks source link

special character for replacing the '$' #33

Closed nugrahawahyu closed 8 years ago

nugrahawahyu commented 8 years ago

I love this, but I'm facing a problem by default, it's look like something like this,

My documents $

I want to replace that '$' with this character '⚡', but what i got is:

my documents âš¡

is it impossible using special character for that?

lukesampson commented 8 years ago

I think it might be a limitation with the built in console not supporting Unicode, but I'm not sure.

nugrahawahyu commented 8 years ago

I found the solution,

[ "yellow", "", " $([char]0x26A1)" ]

now my command line looks cooler with that lightning bolt :D

( Tested using ConEmu )

lukesampson commented 8 years ago

Awesome :)

eugenesvk commented 8 years ago

Hm, I've tried to change the default theme with "prompt_unstaged": " $([char]0x26A1)", but as an output I got AheadBehind master $([char]0x26A1)$([char]0xF02C) (second symbol was supposed to be untracked). But pasting this code directly (e.g. "$([char]0xF06B)" with or without quotes) works fine!

lukesampson commented 8 years ago

I think the strings under "git" are treated as literals, which is why it's outputting the string rather than interpolating the $() expression. If you want to include symbols, you can do it under "prompt"—the strings there are evaluated as expressions.

eugenesvk commented 8 years ago

Do you mean the the prompt function in the lib\prompt.ps1? If so, then it outputs concatenated variable that only includes relevant symbols after performing many useful conditional check (in plugins\git.ps1 if I'm correct), so it's not trivial to change include symbols there (that's what the theme variables are for ;)

Also, I didn't really understood why I can't store special chars in the vars that git.ps1 is using. When I assign a special char to a var and then print it in prompt, it works just fine without those âš¡ and without having to input a unicode codepoint.

eugenesvk commented 8 years ago

Found the culprit!, remembering I had a similar issue with unicode chars. You have to save your files with UTF-8 with BOM encoding (primarily this is relevant for themes/XYZ.json files, but just in case I've also changed the git.ps1 and prompt.ps1, didn't test it separately). Would you please change encodings for all the theme files to have BOM (and just in case for the prompt and git files)?

It's pathetic though that MS in 2015 needs BOM to understand that a file should be considered Unicode :(

eugenesvk commented 8 years ago

And with this change there is no need to go the weird path of entering Unicode codepoints, you can just paste special symbols as is.

lukesampson commented 8 years ago

Good to know. Do you want to submit a pull request?

eugenesvk commented 8 years ago

Sure can do

lukesampson commented 8 years ago

I'm thinking if you modify the get-content call (gc) in load_theme in theme.ps1 to always assume unicode, that might be a good option.

lukesampson commented 8 years ago

Sorry, should have just linked https://github.com/lukesampson/pshazz/blob/master/lib/theme.ps1#L24

eugenesvk commented 8 years ago

Sorry, don't know enough PS to do that. I've sent PR meanwhile with files converted with BOM. Will check out later if can find out about the get-content call.

lukesampson commented 8 years ago

Help for get-content is here. What you've done might be enough though. If you've tested and it works well, feel free to close this.

eugenesvk commented 8 years ago

It's already closed :) Yep, it's working fine, the issue was in reading a file that wasn't marked as BOM, so the Unicode chars would get scrambled. I've had this issue earlier when was setting up my PowerShell.

By the way, if I wanted to change the colors of individual git status symbols, what would be the easiest way? Am I correct that it would require changing the git module (and reflect it in my prompt function) since it concatenates all statuses into one variable and after that it would be impossible to separate them? Also, am I correct that there is currently no function to output number of commits ahead/behind that I can attack to an up/down arrow symbol?

lukesampson commented 8 years ago

Haha whoops. Cool.

Yeah you can only currently display the variables that the git plugin gives you, like git_staged, git_unstaged, git_stash, git_tracked, git_untracked. If you want to use more, you'd have to expose them in plugins/git.ps1.

Happy to accept a pull request for that. Maybe you could just check what the performance cost is to calculate these, and if it's significant you might need to add a config option to enable these, because not everyone will want to use the additional symbols.