Bash prompt configuration

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP












0














I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly.
I used zsh before, and for some reasons I want to go back to bash but I'd love
to get the same prompt "theme" that I had with zsh, whish was very sober.



zsh "fishy" theme



I especially like the way it only display the first character of the directories names in the path except the current one.



I'm searching how I could write this in the .bashrc but I'm not finding anything.










share|improve this question




























    0














    I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly.
    I used zsh before, and for some reasons I want to go back to bash but I'd love
    to get the same prompt "theme" that I had with zsh, whish was very sober.



    zsh "fishy" theme



    I especially like the way it only display the first character of the directories names in the path except the current one.



    I'm searching how I could write this in the .bashrc but I'm not finding anything.










    share|improve this question


























      0












      0








      0


      0





      I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly.
      I used zsh before, and for some reasons I want to go back to bash but I'd love
      to get the same prompt "theme" that I had with zsh, whish was very sober.



      zsh "fishy" theme



      I especially like the way it only display the first character of the directories names in the path except the current one.



      I'm searching how I could write this in the .bashrc but I'm not finding anything.










      share|improve this question















      I've recently switched to Parrot linux and I'm very happy with it, but there's just one thing, this default fancy bash prompt is really ugly.
      I used zsh before, and for some reasons I want to go back to bash but I'd love
      to get the same prompt "theme" that I had with zsh, whish was very sober.



      zsh "fishy" theme



      I especially like the way it only display the first character of the directories names in the path except the current one.



      I'm searching how I could write this in the .bashrc but I'm not finding anything.







      bash prompt bashrc






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Dec 21 '18 at 0:00









      Rui F Ribeiro

      39.1k1479130




      39.1k1479130










      asked Dec 20 '18 at 22:17









      Zest

      11




      11




















          1 Answer
          1






          active

          oldest

          votes


















          1














          Borrowing heavily from Dennis Kaarsemaker's answer:



          PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
          PS1='u@h $_abbrev_pwd> '


          The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:



          • the output of a sed command: $(sed -e ... <<< ...)

          • a forward slash /

          • the "current" directory: $(basename "$PWD")

          The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):



          1. replace any appearance of your "$HOME" directory with a tilde, and

          2. replace any path element (forward slash, a captured single character ., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with the g flag. I've used : as the sed search & replace delimiter instead of the common /, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.

          Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.






          share|improve this answer




















            Your Answer








            StackExchange.ready(function()
            var channelOptions =
            tags: "".split(" "),
            id: "106"
            ;
            initTagRenderer("".split(" "), "".split(" "), channelOptions);

            StackExchange.using("externalEditor", function()
            // Have to fire editor after snippets, if snippets enabled
            if (StackExchange.settings.snippets.snippetsEnabled)
            StackExchange.using("snippets", function()
            createEditor();
            );

            else
            createEditor();

            );

            function createEditor()
            StackExchange.prepareEditor(
            heartbeatType: 'answer',
            autoActivateHeartbeat: false,
            convertImagesToLinks: false,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: null,
            bindNavPrevention: true,
            postfix: "",
            imageUploader:
            brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
            contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
            allowUrls: true
            ,
            onDemand: true,
            discardSelector: ".discard-answer"
            ,immediatelyShowMarkdownHelp:true
            );



            );













            draft saved

            draft discarded


















            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490222%2fbash-prompt-configuration%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown

























            1 Answer
            1






            active

            oldest

            votes








            1 Answer
            1






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            1














            Borrowing heavily from Dennis Kaarsemaker's answer:



            PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
            PS1='u@h $_abbrev_pwd> '


            The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:



            • the output of a sed command: $(sed -e ... <<< ...)

            • a forward slash /

            • the "current" directory: $(basename "$PWD")

            The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):



            1. replace any appearance of your "$HOME" directory with a tilde, and

            2. replace any path element (forward slash, a captured single character ., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with the g flag. I've used : as the sed search & replace delimiter instead of the common /, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.

            Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.






            share|improve this answer

























              1














              Borrowing heavily from Dennis Kaarsemaker's answer:



              PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
              PS1='u@h $_abbrev_pwd> '


              The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:



              • the output of a sed command: $(sed -e ... <<< ...)

              • a forward slash /

              • the "current" directory: $(basename "$PWD")

              The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):



              1. replace any appearance of your "$HOME" directory with a tilde, and

              2. replace any path element (forward slash, a captured single character ., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with the g flag. I've used : as the sed search & replace delimiter instead of the common /, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.

              Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.






              share|improve this answer























                1












                1








                1






                Borrowing heavily from Dennis Kaarsemaker's answer:



                PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
                PS1='u@h $_abbrev_pwd> '


                The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:



                • the output of a sed command: $(sed -e ... <<< ...)

                • a forward slash /

                • the "current" directory: $(basename "$PWD")

                The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):



                1. replace any appearance of your "$HOME" directory with a tilde, and

                2. replace any path element (forward slash, a captured single character ., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with the g flag. I've used : as the sed search & replace delimiter instead of the common /, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.

                Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.






                share|improve this answer












                Borrowing heavily from Dennis Kaarsemaker's answer:



                PROMPT_COMMAND='_abbrev_pwd=$(sed -e "s:$HOME:~:" -e "s:/(.)[^/]*:/1:g" <<< "$(dirname "$PWD")")/"$(basename "$PWD")"'
                PS1='u@h $_abbrev_pwd> '


                The PROMPT_COMMAND variable is a special bash variable that is executed each time a prompt is about to be printed. The code here sets a variable named _abbrev_pwd to the concatenation of the following elements:



                • the output of a sed command: $(sed -e ... <<< ...)

                • a forward slash /

                • the "current" directory: $(basename "$PWD")

                The sed command itself takes a here-string as input; that here-string is the result of calling dirname "$PWD" in order to strip off the current directory. That string is then subject to two replacements (given in the -e sed options):



                1. replace any appearance of your "$HOME" directory with a tilde, and

                2. replace any path element (forward slash, a captured single character ., then any number of non-forward-slashes) with a forward slash followed by that (captured) single character; repeat that pattern match "globally" with the g flag. I've used : as the sed search & replace delimiter instead of the common /, in order to avoid leaning toothpick syndrome in trying to escape the desired forward slashes.

                Lastly, we set PS1 to use the _abbrev_pwd variable where you would normally put the $PWD.







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Dec 28 '18 at 17:27









                Jeff Schaller

                38.8k1053125




                38.8k1053125



























                    draft saved

                    draft discarded
















































                    Thanks for contributing an answer to Unix & Linux Stack Exchange!


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.





                    Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


                    Please pay close attention to the following guidance:


                    • Please be sure to answer the question. Provide details and share your research!

                    But avoid


                    • Asking for help, clarification, or responding to other answers.

                    • Making statements based on opinion; back them up with references or personal experience.

                    To learn more, see our tips on writing great answers.




                    draft saved


                    draft discarded














                    StackExchange.ready(
                    function ()
                    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f490222%2fbash-prompt-configuration%23new-answer', 'question_page');

                    );

                    Post as a guest















                    Required, but never shown





















































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown

































                    Required, but never shown














                    Required, but never shown












                    Required, but never shown







                    Required, but never shown






                    Popular posts from this blog

                    Peggy Mitchell

                    The Forum (Inglewood, California)

                    Palaiologos