Script to create files in a template
Clash Royale CLAN TAG#URR8PPP
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
add a comment |
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
1
It'd probably be easier to save your templates in some directorysite_template/
, and just do a recursive copy from the template folder to the new site folder, followed by whatevercd
andvim
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 likescons
to do this.
– Faheem Mitha
Feb 10 '12 at 5:25
add a comment |
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
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
bash vim function
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 directorysite_template/
, and just do a recursive copy from the template folder to the new site folder, followed by whatevercd
andvim
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 likescons
to do this.
– Faheem Mitha
Feb 10 '12 at 5:25
add a comment |
1
It'd probably be easier to save your templates in some directorysite_template/
, and just do a recursive copy from the template folder to the new site folder, followed by whatevercd
andvim
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 likescons
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
add a comment |
2 Answers
2
active
oldest
votes
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.
add a comment |
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.
add a comment |
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
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
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.
add a comment |
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.
add a comment |
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.
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.
answered Feb 10 '12 at 5:25
PatrickPatrick
50.3k11127179
50.3k11127179
add a comment |
add a comment |
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.
add a comment |
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.
add a comment |
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.
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.
answered Feb 10 '12 at 4:34
Hai VuHai Vu
92148
92148
add a comment |
add a comment |
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.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
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 whatevercd
andvim
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