gnachman / iterm2-website

Website for iTerm2
http://iterm2.com/
GNU General Public License v2.0
81 stars 65 forks source link

Simplify the fish_prompt function #38

Closed maxnordlund closed 7 years ago

maxnordlund commented 7 years ago

This rewrites it into more idiomatic fish, and greatly simplifies it in the process.

I manually tested this on my machine, and it seems to work, even with multiline prompts and printf format strings. To reproduce what I have, just append printf "\n\n%%s > \n" to your fish_prompt function.

Side note: It would be nice if this was part of the main app instead of here, which also would allow to ship the current version in the app. So you could source /Applications/iTerm.app/Contents/integration/iterm.fish or something similar.

gnachman commented 7 years ago

This doesn't appear to strip the trailing newline. I ran a test at the command line and got different results vs the old code:

New code. Note the ⏎ at the end:

gln@gln-mbp ~/g/i/s/misc> printf "%b" (string join "\n" (iterm2_fish_prompt))
gln@gln-mbp ~/g/i/s/misc> ⏎       

Old code, no ⏎:

gln@gln-mbp ~/g/i/s/misc> for line in (iterm2_fish_prompt)
                              set -q last_line; and echo $last_line
                              set last_line $line
                          end
gln@gln-mbp ~/g/i/s/misc>
maxnordlund commented 7 years ago

The ⏎ character means no newline, see printf "no newline" vs printf "newline\n". Which means the old code actually didn't strip the trailing newline…

However, fish handles that for you in your prompt, and I actually think it might strip the last newline if there is one. Try adding printf "\n", printf "\n\n" etc to your fish_prompt.

gnachman commented 7 years ago

Ah, you're right of course. Thanks for the clarification and the PR, this looks good.

gnachman commented 7 years ago

This will go live on the next website update (when 3.0.15 goes into beta, most likely)

maxnordlund commented 7 years ago

Not a problem, always happy to help 😄