Color specific filenames (not extensions) in `ls` output like Makefile or CMakeLists.txt












0














I am currently working on a C++ project. I am using CMake as a build system and I would love to have all the CMake related files (like CMakeLists.txt) colored differently in the ls command output. This way I could easily distinguish them from the source code files.



I was trying to both use dircolors and edit directly $LS_COLORS env var. I failed in both cases. It seems that those solutions only provide a way to color either some Linux specific files (eg. links) or selected extensions.



To sum it up, this is what I did:



OLD_LS_COLORS=$LS_COLORS # Backup
export LS_COLORS="${LS_COLORS}CMakeLists.txt=00;36:" # Adding it at the beginning of the list also fails
ls # No colors at all
export LS_COLORS=$OLD_LS_COLORS # Cleanup
dircolors -p > ~/.dir_colors
echo "CMakeLists.txt 01;33" >> ~/.dir_colors
eval `dircolors ~/.dir_colors` # Throws "unrecognized keyword CMakeLists.txt"


Workaround for my problem would be to color the source files (.hxx, .cxx) instead but I would like to stick with coloring CMake files only. On the other hand I could just color .txt and .cmake files but then all the text files would be colored in such fashion.



Coloring a Makefile (a file with no extension) in ls output would be a nice bonus.



I am using Debian 9 with bash 4.4.12 and ls 8.26.



Thanks in advance.










share|improve this question



























    0














    I am currently working on a C++ project. I am using CMake as a build system and I would love to have all the CMake related files (like CMakeLists.txt) colored differently in the ls command output. This way I could easily distinguish them from the source code files.



    I was trying to both use dircolors and edit directly $LS_COLORS env var. I failed in both cases. It seems that those solutions only provide a way to color either some Linux specific files (eg. links) or selected extensions.



    To sum it up, this is what I did:



    OLD_LS_COLORS=$LS_COLORS # Backup
    export LS_COLORS="${LS_COLORS}CMakeLists.txt=00;36:" # Adding it at the beginning of the list also fails
    ls # No colors at all
    export LS_COLORS=$OLD_LS_COLORS # Cleanup
    dircolors -p > ~/.dir_colors
    echo "CMakeLists.txt 01;33" >> ~/.dir_colors
    eval `dircolors ~/.dir_colors` # Throws "unrecognized keyword CMakeLists.txt"


    Workaround for my problem would be to color the source files (.hxx, .cxx) instead but I would like to stick with coloring CMake files only. On the other hand I could just color .txt and .cmake files but then all the text files would be colored in such fashion.



    Coloring a Makefile (a file with no extension) in ls output would be a nice bonus.



    I am using Debian 9 with bash 4.4.12 and ls 8.26.



    Thanks in advance.










    share|improve this question

























      0












      0








      0







      I am currently working on a C++ project. I am using CMake as a build system and I would love to have all the CMake related files (like CMakeLists.txt) colored differently in the ls command output. This way I could easily distinguish them from the source code files.



      I was trying to both use dircolors and edit directly $LS_COLORS env var. I failed in both cases. It seems that those solutions only provide a way to color either some Linux specific files (eg. links) or selected extensions.



      To sum it up, this is what I did:



      OLD_LS_COLORS=$LS_COLORS # Backup
      export LS_COLORS="${LS_COLORS}CMakeLists.txt=00;36:" # Adding it at the beginning of the list also fails
      ls # No colors at all
      export LS_COLORS=$OLD_LS_COLORS # Cleanup
      dircolors -p > ~/.dir_colors
      echo "CMakeLists.txt 01;33" >> ~/.dir_colors
      eval `dircolors ~/.dir_colors` # Throws "unrecognized keyword CMakeLists.txt"


      Workaround for my problem would be to color the source files (.hxx, .cxx) instead but I would like to stick with coloring CMake files only. On the other hand I could just color .txt and .cmake files but then all the text files would be colored in such fashion.



      Coloring a Makefile (a file with no extension) in ls output would be a nice bonus.



      I am using Debian 9 with bash 4.4.12 and ls 8.26.



      Thanks in advance.










      share|improve this question













      I am currently working on a C++ project. I am using CMake as a build system and I would love to have all the CMake related files (like CMakeLists.txt) colored differently in the ls command output. This way I could easily distinguish them from the source code files.



      I was trying to both use dircolors and edit directly $LS_COLORS env var. I failed in both cases. It seems that those solutions only provide a way to color either some Linux specific files (eg. links) or selected extensions.



      To sum it up, this is what I did:



      OLD_LS_COLORS=$LS_COLORS # Backup
      export LS_COLORS="${LS_COLORS}CMakeLists.txt=00;36:" # Adding it at the beginning of the list also fails
      ls # No colors at all
      export LS_COLORS=$OLD_LS_COLORS # Cleanup
      dircolors -p > ~/.dir_colors
      echo "CMakeLists.txt 01;33" >> ~/.dir_colors
      eval `dircolors ~/.dir_colors` # Throws "unrecognized keyword CMakeLists.txt"


      Workaround for my problem would be to color the source files (.hxx, .cxx) instead but I would like to stick with coloring CMake files only. On the other hand I could just color .txt and .cmake files but then all the text files would be colored in such fashion.



      Coloring a Makefile (a file with no extension) in ls output would be a nice bonus.



      I am using Debian 9 with bash 4.4.12 and ls 8.26.



      Thanks in advance.







      linux command-line bash colors






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Aug 8 at 8:54









      Maciej Stanek

      31




      31






















          2 Answers
          2






          active

          oldest

          votes


















          0














          You can do that with ls.



          *Makefile       38;5;155
          *CMakeLists.txt 48;5;89;38;5;197;1;3;4;7


          See https://github.com/trapd00r/LS_COLORS/blob/master/LS_COLORS






          share|improve this answer





















          • Thanks! This is precisely what I needed!
            – Maciej Stanek
            Nov 23 at 9:54



















          0














          I don't know if you can do that with ls directly. (But it might be...)



          My Idea would be, to pipe the output of ls to sed, which can color it's regex matches.



          There is a nice snippet which does this: https://github.com/kepkin/dev-shell-essentials/blob/master/highlight.sh



          You could write a chain of pipes which matches all cmake files:
          ls | highlight blue CMakeLists.txt | highlight blue foobar.baz ... (and create an alias for this)



          But this is of course a workaround.



          My personal choice would be to use out-of-source builds and keep the cmake files seperated to a certain degree. But this is not an answer to your question and might not be possible in your project structure...






          share|improve this answer





















            Your Answer








            StackExchange.ready(function() {
            var channelOptions = {
            tags: "".split(" "),
            id: "3"
            };
            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: true,
            noModals: true,
            showLowRepImageUploadWarning: true,
            reputationToPostImages: 10,
            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%2fsuperuser.com%2fquestions%2f1347106%2fcolor-specific-filenames-not-extensions-in-ls-output-like-makefile-or-cmakel%23new-answer', 'question_page');
            }
            );

            Post as a guest















            Required, but never shown

























            2 Answers
            2






            active

            oldest

            votes








            2 Answers
            2






            active

            oldest

            votes









            active

            oldest

            votes






            active

            oldest

            votes









            0














            You can do that with ls.



            *Makefile       38;5;155
            *CMakeLists.txt 48;5;89;38;5;197;1;3;4;7


            See https://github.com/trapd00r/LS_COLORS/blob/master/LS_COLORS






            share|improve this answer





















            • Thanks! This is precisely what I needed!
              – Maciej Stanek
              Nov 23 at 9:54
















            0














            You can do that with ls.



            *Makefile       38;5;155
            *CMakeLists.txt 48;5;89;38;5;197;1;3;4;7


            See https://github.com/trapd00r/LS_COLORS/blob/master/LS_COLORS






            share|improve this answer





















            • Thanks! This is precisely what I needed!
              – Maciej Stanek
              Nov 23 at 9:54














            0












            0








            0






            You can do that with ls.



            *Makefile       38;5;155
            *CMakeLists.txt 48;5;89;38;5;197;1;3;4;7


            See https://github.com/trapd00r/LS_COLORS/blob/master/LS_COLORS






            share|improve this answer












            You can do that with ls.



            *Makefile       38;5;155
            *CMakeLists.txt 48;5;89;38;5;197;1;3;4;7


            See https://github.com/trapd00r/LS_COLORS/blob/master/LS_COLORS







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered Nov 22 at 17:48









            japh

            16




            16












            • Thanks! This is precisely what I needed!
              – Maciej Stanek
              Nov 23 at 9:54


















            • Thanks! This is precisely what I needed!
              – Maciej Stanek
              Nov 23 at 9:54
















            Thanks! This is precisely what I needed!
            – Maciej Stanek
            Nov 23 at 9:54




            Thanks! This is precisely what I needed!
            – Maciej Stanek
            Nov 23 at 9:54













            0














            I don't know if you can do that with ls directly. (But it might be...)



            My Idea would be, to pipe the output of ls to sed, which can color it's regex matches.



            There is a nice snippet which does this: https://github.com/kepkin/dev-shell-essentials/blob/master/highlight.sh



            You could write a chain of pipes which matches all cmake files:
            ls | highlight blue CMakeLists.txt | highlight blue foobar.baz ... (and create an alias for this)



            But this is of course a workaround.



            My personal choice would be to use out-of-source builds and keep the cmake files seperated to a certain degree. But this is not an answer to your question and might not be possible in your project structure...






            share|improve this answer


























              0














              I don't know if you can do that with ls directly. (But it might be...)



              My Idea would be, to pipe the output of ls to sed, which can color it's regex matches.



              There is a nice snippet which does this: https://github.com/kepkin/dev-shell-essentials/blob/master/highlight.sh



              You could write a chain of pipes which matches all cmake files:
              ls | highlight blue CMakeLists.txt | highlight blue foobar.baz ... (and create an alias for this)



              But this is of course a workaround.



              My personal choice would be to use out-of-source builds and keep the cmake files seperated to a certain degree. But this is not an answer to your question and might not be possible in your project structure...






              share|improve this answer
























                0












                0








                0






                I don't know if you can do that with ls directly. (But it might be...)



                My Idea would be, to pipe the output of ls to sed, which can color it's regex matches.



                There is a nice snippet which does this: https://github.com/kepkin/dev-shell-essentials/blob/master/highlight.sh



                You could write a chain of pipes which matches all cmake files:
                ls | highlight blue CMakeLists.txt | highlight blue foobar.baz ... (and create an alias for this)



                But this is of course a workaround.



                My personal choice would be to use out-of-source builds and keep the cmake files seperated to a certain degree. But this is not an answer to your question and might not be possible in your project structure...






                share|improve this answer












                I don't know if you can do that with ls directly. (But it might be...)



                My Idea would be, to pipe the output of ls to sed, which can color it's regex matches.



                There is a nice snippet which does this: https://github.com/kepkin/dev-shell-essentials/blob/master/highlight.sh



                You could write a chain of pipes which matches all cmake files:
                ls | highlight blue CMakeLists.txt | highlight blue foobar.baz ... (and create an alias for this)



                But this is of course a workaround.



                My personal choice would be to use out-of-source builds and keep the cmake files seperated to a certain degree. But this is not an answer to your question and might not be possible in your project structure...







                share|improve this answer












                share|improve this answer



                share|improve this answer










                answered Aug 8 at 10:14









                Jounathaen

                307111




                307111






























                    draft saved

                    draft discarded




















































                    Thanks for contributing an answer to Super User!


                    • 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%2fsuperuser.com%2fquestions%2f1347106%2fcolor-specific-filenames-not-extensions-in-ls-output-like-makefile-or-cmakel%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

                    AnyDesk - Fatal Program Failure

                    How to calibrate 16:9 built-in touch-screen to a 4:3 resolution?

                    QoS: MAC-Priority for clients behind a repeater