0

I am using iTerm2 on MacOS Catalina. Here is my PS1 into ~/.bashrc, using a function ps1 :

function ps1 {
        # PROMPT SECTION
        BLUE='\[\033[0;34m\]'
        LIGHT_CYAN='\[\033[1;36m\]'
        DEFAULT='\[\033[0m\]'
        PURPLE='\[\033[0;35m\]'
        LIGHT_PURPLE='\[\033[1;35m\]'
        LIGHT_GREEN='\[\033[0;32m\]'
        PINK='\[\033\[0;31m\]'


        # \! - History number of last command
        # $? - Exit value of last command
        # \t - Exit time of last command
        # \w - Current directory (relative)

PS1="$PURPLE|$DEFAULT$LIGHT_GREEN\u@$DEFAULT$LIGHT_CYAN\h$DEFAULT$PURPLE|$DEFAULT\t$PURPLE|$DEFAULT$LIGHT_PURPLE\w$DEFAULT$PURPLE|$DEFAULT "
}

ps1

The issue happens when I have long path, it seems to be broken on second or third line like this:

enter image description here

I tried to increase the number of columns (to 1000) into iTerm2 -> Preferences but it doesn't seem to fix this issue.

I can't see where the error comes from. What might be wrong?

  fab@astro|13:12:32|~/Phd_2019_2020/Travail_2_faire_varier_Omega_DE_sur_CAMB_et_regarder_si_les_P_k_changent_21_Octobre_2019/Main_Directory_Work/TSAF_lvl_up_Derivatives_15_points_on_Cl_stabilite_Code_is_surel
y_VALIDATED_for_15_points_derivatives_AND_After_trying_to_solve_the_pathologic_zone_1e-5_TO_1e-2_13_Novembre_2019/Test_FAIRE_VARIER_TOUS_LES_PARAMETRES_AVEC_les_2_pas_2e-2_et_1e-1_AVEC_Takabird_SECONDE_TENTATIVE_AVEC_LA_VAR        IATION_de_wde_EN_FLAT_DANS_Camb_launcher_6_DECEMBRE_2019/CAMB_der_3_pts/fortran|

Update

Solution finally found on this link.

halfer
  • 19,824
  • 17
  • 99
  • 186
  • 1
    **DO NOT post images of code, data, error messages, etc.** - copy or type the text into the question. [How To Ask](https://stackoverflow.com/help/how-to-ask) – Rob Dec 07 '19 at 12:20
  • 1
    @Rob But I couldn't illustrate the issue with text, it is difficult to reproduce, so that's why I used an image. Regards –  Dec 07 '19 at 12:26
  • 1
    Your image **is** text. How can you not illustrate the problem?! – Rob Dec 07 '19 at 12:27
  • @Rob I talk about the third line of prompt path which is broken like if there were a '\n' character. –  Dec 07 '19 at 12:30
  • 1
    I don't understand the `broken` can you point out where in the image , or which specific character – JerryZhou Dec 11 '19 at 07:27
  • @JerryZhou the broken part is visible on the part : `...AVEC_LA_VAR IATION_de_wde_EN...` . I must precise that I also use grc to colorify my terminal, maybe it could come from this but not really convinced by that. –  Dec 11 '19 at 10:34
  • 3
    oh, I see, it's not an error, it's just display long text, it's break when possible (I think in this case it meet the first space), and the break rule sometime related to the shell. – JerryZhou Dec 11 '19 at 12:45

1 Answers1

1

Stopping the word-wrapping on iTerm2 is still an open feature request. So I'm afraid that if your line is too long, it'll get wrapped automatically anyway.

However, you could build your PS1 such that the line won't overflow by trimming the path down.

For that, you'd need the command tput cols to get the number of columns on your terminal if you want to do it manually, or just use one of the answers in there.

If you are open to changing your shell from bash to zsh, a lot of thems in zsh trim the paths so that they don't overflow the line.

An example of zsh trimming paths

Another solution given in this answer would be to use the commands tput rmam to discard output that overflow, then re-enable wrapping with tput smam

WayToDoor
  • 1,180
  • 9
  • 24