haslersn / any-nix-shell

fish and zsh support for the nix run and nix-shell environments of the Nix package manager
MIT License
253 stars 17 forks source link

fish: `--info-right` prompt degrades text selection by adding trailing whitespace #28

Open isker opened 1 year ago

isker commented 1 year ago

Relevant code: https://github.com/haslersn/any-nix-shell/blob/c8536fa43f0e8b506e9dd1a91e2f01ceccca0251/bin/any-nix-shell#L61-L65

Here's a copy-pasted terminal session involving different fish_right_prompts' effects on text selection. Highlight the entire code block and observe that the prompt line has a ton of trailing whitespace, depending on the value of fish_right_prompt.

Welcome to fish, the friendly interactive shell
Type help for instructions on how to use fish
~ λ echo "start with a shell without the prompt added by --info-right"
start with a shell without the prompt added by --info-right
~ λ 
~ λ function fish_right_prompt
    end
~ λ echo "notice that had no effect on text selection"
notice that had no effect on text selection
~ λ 
~ λ function fish_right_prompt
        printf " "
    end
~ λ echo "see how that makes the selection copy the entire line?  it's because it inserted a single-space right-prmopt instead of nothing"                                                                                                      
see how that makes the selection copy the entire line?  it's because it inserted a single-space right-prmopt instead of nothing
~ λ                                                                                                                                                                                                                                             
~ λ function fish_right_prompt                                                                                                                                                                                                                  
        nix-shell-info
    end
~ λ echo "nix-shell-info prints nothing by default, so text selection is still fine"
nix-shell-info prints nothing by default, so text selection is still fine
~ λ 
~ λ function fish_right_prompt
        nix-shell-info
        printf " "
    end
~ λ echo "here's the actual right prompt generated by any-nix-shell, just to illustrate"                                                                                                                                                        
here's the actual right prompt generated by any-nix-shell, just to illustrate

This trailing whitespace is really bothersome when copy/pasting from the terminal into, say... GitHub issue descriptions!

Either we should delete the printf " " entirely, or make it conditional on nix-shell-info outputting something.