Script to create files in a template

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












2















I just wrote a function in my ~/.bashrc that will let me create a folder for a new website with one command. The function looks like this:



function newsite() 
mkcd "$*" # mkdir and cd into it
mkdir "js"
mkdir "imgs"
touch "index.html"
touch "main.css"
vim "index.html"



Now what I would like to do is, instead of just touching index.html and main.css I'd like to create basic template files for index.html and main.css problem is I have absolutely no idea how to do that. I don't know much about writing to files using bash commands. Typically I'd just open the files in vim and go to town but I'd like to have something already started when I get into vim...










share|improve this question



















  • 1





    It'd probably be easier to save your templates in some directory site_template/, and just do a recursive copy from the template folder to the new site folder, followed by whatever cd and vim commands you want.

    – jw013
    Feb 10 '12 at 4:15












  • @jw013 AH Yes super simple! Thank you very much :D Make that an answer and I'll accept it.

    – CaldwellYSR
    Feb 10 '12 at 4:22












  • Looks like @HaiVu posted an answer already, so need for me to make another :)

    – jw013
    Feb 10 '12 at 4:38











  • You're better off using a build tool like scons to do this.

    – Faheem Mitha
    Feb 10 '12 at 5:25















2















I just wrote a function in my ~/.bashrc that will let me create a folder for a new website with one command. The function looks like this:



function newsite() 
mkcd "$*" # mkdir and cd into it
mkdir "js"
mkdir "imgs"
touch "index.html"
touch "main.css"
vim "index.html"



Now what I would like to do is, instead of just touching index.html and main.css I'd like to create basic template files for index.html and main.css problem is I have absolutely no idea how to do that. I don't know much about writing to files using bash commands. Typically I'd just open the files in vim and go to town but I'd like to have something already started when I get into vim...










share|improve this question



















  • 1





    It'd probably be easier to save your templates in some directory site_template/, and just do a recursive copy from the template folder to the new site folder, followed by whatever cd and vim commands you want.

    – jw013
    Feb 10 '12 at 4:15












  • @jw013 AH Yes super simple! Thank you very much :D Make that an answer and I'll accept it.

    – CaldwellYSR
    Feb 10 '12 at 4:22












  • Looks like @HaiVu posted an answer already, so need for me to make another :)

    – jw013
    Feb 10 '12 at 4:38











  • You're better off using a build tool like scons to do this.

    – Faheem Mitha
    Feb 10 '12 at 5:25













2












2








2


2






I just wrote a function in my ~/.bashrc that will let me create a folder for a new website with one command. The function looks like this:



function newsite() 
mkcd "$*" # mkdir and cd into it
mkdir "js"
mkdir "imgs"
touch "index.html"
touch "main.css"
vim "index.html"



Now what I would like to do is, instead of just touching index.html and main.css I'd like to create basic template files for index.html and main.css problem is I have absolutely no idea how to do that. I don't know much about writing to files using bash commands. Typically I'd just open the files in vim and go to town but I'd like to have something already started when I get into vim...










share|improve this question
















I just wrote a function in my ~/.bashrc that will let me create a folder for a new website with one command. The function looks like this:



function newsite() 
mkcd "$*" # mkdir and cd into it
mkdir "js"
mkdir "imgs"
touch "index.html"
touch "main.css"
vim "index.html"



Now what I would like to do is, instead of just touching index.html and main.css I'd like to create basic template files for index.html and main.css problem is I have absolutely no idea how to do that. I don't know much about writing to files using bash commands. Typically I'd just open the files in vim and go to town but I'd like to have something already started when I get into vim...







bash vim function






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Jan 13 at 21:44









Rui F Ribeiro

39.7k1479132




39.7k1479132










asked Feb 10 '12 at 3:53









CaldwellYSRCaldwellYSR

20228




20228







  • 1





    It'd probably be easier to save your templates in some directory site_template/, and just do a recursive copy from the template folder to the new site folder, followed by whatever cd and vim commands you want.

    – jw013
    Feb 10 '12 at 4:15












  • @jw013 AH Yes super simple! Thank you very much :D Make that an answer and I'll accept it.

    – CaldwellYSR
    Feb 10 '12 at 4:22












  • Looks like @HaiVu posted an answer already, so need for me to make another :)

    – jw013
    Feb 10 '12 at 4:38











  • You're better off using a build tool like scons to do this.

    – Faheem Mitha
    Feb 10 '12 at 5:25












  • 1





    It'd probably be easier to save your templates in some directory site_template/, and just do a recursive copy from the template folder to the new site folder, followed by whatever cd and vim commands you want.

    – jw013
    Feb 10 '12 at 4:15












  • @jw013 AH Yes super simple! Thank you very much :D Make that an answer and I'll accept it.

    – CaldwellYSR
    Feb 10 '12 at 4:22












  • Looks like @HaiVu posted an answer already, so need for me to make another :)

    – jw013
    Feb 10 '12 at 4:38











  • You're better off using a build tool like scons to do this.

    – Faheem Mitha
    Feb 10 '12 at 5:25







1




1





It'd probably be easier to save your templates in some directory site_template/, and just do a recursive copy from the template folder to the new site folder, followed by whatever cd and vim commands you want.

– jw013
Feb 10 '12 at 4:15






It'd probably be easier to save your templates in some directory site_template/, and just do a recursive copy from the template folder to the new site folder, followed by whatever cd and vim commands you want.

– jw013
Feb 10 '12 at 4:15














@jw013 AH Yes super simple! Thank you very much :D Make that an answer and I'll accept it.

– CaldwellYSR
Feb 10 '12 at 4:22






@jw013 AH Yes super simple! Thank you very much :D Make that an answer and I'll accept it.

– CaldwellYSR
Feb 10 '12 at 4:22














Looks like @HaiVu posted an answer already, so need for me to make another :)

– jw013
Feb 10 '12 at 4:38





Looks like @HaiVu posted an answer already, so need for me to make another :)

– jw013
Feb 10 '12 at 4:38













You're better off using a build tool like scons to do this.

– Faheem Mitha
Feb 10 '12 at 5:25





You're better off using a build tool like scons to do this.

– Faheem Mitha
Feb 10 '12 at 5:25










2 Answers
2






active

oldest

votes


















3














jw013's idea and HaiVu's answer are both correct. However for the sake of completeness for anyone who comes upon this question wanting the answer, here it is;



function newsite() 
mkcd "$*" # mkdir and cd into it
mkdir "js"
mkdir "imgs"
cat > index.html <<'EOI'
<html>
<head>
</head>
<body>
</body>
</html>
EOI
cat > main.css <<'EOI'
body
font-family: Arial;

EOI
vim "index.html"



The <<'EOI' thing is called a heredoc, most scripting languages have them.






share|improve this answer






























    6














    I like jw013's idea:



    mkdir -p ~/site_template/js,imgs
    # Creates all the files in this directory: index.html, main.css, ...


    Now, when it's time to create a new site:



    cp -r ~/site_template ~/my_site


    That would be much easier. Plus, you can edit your site template files any way you like.






    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%2f31343%2fscript-to-create-files-in-a-template%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









      3














      jw013's idea and HaiVu's answer are both correct. However for the sake of completeness for anyone who comes upon this question wanting the answer, here it is;



      function newsite() 
      mkcd "$*" # mkdir and cd into it
      mkdir "js"
      mkdir "imgs"
      cat > index.html <<'EOI'
      <html>
      <head>
      </head>
      <body>
      </body>
      </html>
      EOI
      cat > main.css <<'EOI'
      body
      font-family: Arial;

      EOI
      vim "index.html"



      The <<'EOI' thing is called a heredoc, most scripting languages have them.






      share|improve this answer



























        3














        jw013's idea and HaiVu's answer are both correct. However for the sake of completeness for anyone who comes upon this question wanting the answer, here it is;



        function newsite() 
        mkcd "$*" # mkdir and cd into it
        mkdir "js"
        mkdir "imgs"
        cat > index.html <<'EOI'
        <html>
        <head>
        </head>
        <body>
        </body>
        </html>
        EOI
        cat > main.css <<'EOI'
        body
        font-family: Arial;

        EOI
        vim "index.html"



        The <<'EOI' thing is called a heredoc, most scripting languages have them.






        share|improve this answer

























          3












          3








          3







          jw013's idea and HaiVu's answer are both correct. However for the sake of completeness for anyone who comes upon this question wanting the answer, here it is;



          function newsite() 
          mkcd "$*" # mkdir and cd into it
          mkdir "js"
          mkdir "imgs"
          cat > index.html <<'EOI'
          <html>
          <head>
          </head>
          <body>
          </body>
          </html>
          EOI
          cat > main.css <<'EOI'
          body
          font-family: Arial;

          EOI
          vim "index.html"



          The <<'EOI' thing is called a heredoc, most scripting languages have them.






          share|improve this answer













          jw013's idea and HaiVu's answer are both correct. However for the sake of completeness for anyone who comes upon this question wanting the answer, here it is;



          function newsite() 
          mkcd "$*" # mkdir and cd into it
          mkdir "js"
          mkdir "imgs"
          cat > index.html <<'EOI'
          <html>
          <head>
          </head>
          <body>
          </body>
          </html>
          EOI
          cat > main.css <<'EOI'
          body
          font-family: Arial;

          EOI
          vim "index.html"



          The <<'EOI' thing is called a heredoc, most scripting languages have them.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Feb 10 '12 at 5:25









          PatrickPatrick

          50.3k11127179




          50.3k11127179























              6














              I like jw013's idea:



              mkdir -p ~/site_template/js,imgs
              # Creates all the files in this directory: index.html, main.css, ...


              Now, when it's time to create a new site:



              cp -r ~/site_template ~/my_site


              That would be much easier. Plus, you can edit your site template files any way you like.






              share|improve this answer



























                6














                I like jw013's idea:



                mkdir -p ~/site_template/js,imgs
                # Creates all the files in this directory: index.html, main.css, ...


                Now, when it's time to create a new site:



                cp -r ~/site_template ~/my_site


                That would be much easier. Plus, you can edit your site template files any way you like.






                share|improve this answer

























                  6












                  6








                  6







                  I like jw013's idea:



                  mkdir -p ~/site_template/js,imgs
                  # Creates all the files in this directory: index.html, main.css, ...


                  Now, when it's time to create a new site:



                  cp -r ~/site_template ~/my_site


                  That would be much easier. Plus, you can edit your site template files any way you like.






                  share|improve this answer













                  I like jw013's idea:



                  mkdir -p ~/site_template/js,imgs
                  # Creates all the files in this directory: index.html, main.css, ...


                  Now, when it's time to create a new site:



                  cp -r ~/site_template ~/my_site


                  That would be much easier. Plus, you can edit your site template files any way you like.







                  share|improve this answer












                  share|improve this answer



                  share|improve this answer










                  answered Feb 10 '12 at 4:34









                  Hai VuHai Vu

                  92148




                  92148



























                      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.




                      draft saved


                      draft discarded














                      StackExchange.ready(
                      function ()
                      StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2funix.stackexchange.com%2fquestions%2f31343%2fscript-to-create-files-in-a-template%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

                      How to check contact read email or not when send email to Individual?

                      Bahrain

                      Postfix configuration issue with fips on centos 7; mailgun relay