New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open markdown file after running hexo new? #1007

Closed
andrewboni opened this Issue Jan 25, 2015 · 5 comments

Comments

4 participants
@andrewboni

andrewboni commented Jan 25, 2015

Hi, I'm wondering how to run some custom commands after doing a hexo new "My post". I'd like to immediately open the my-post.md file in my editor of choice (with a vi my-post.md). Anyone have a solution to this? Thanks!

@tommy351

This comment has been minimized.

Show comment
Hide comment
@tommy351

tommy351 Jan 26, 2015

Member

You can try to listen to the new event. For example:

var spawn = require('child_process').spawn;

// Hexo 2.x
hexo.on('new', function(path){
  spawn('vi', [path]);
});

// Hexo 3
hexo.on('new', function(data){
  spawn('vi', [data.path]);
});
Member

tommy351 commented Jan 26, 2015

You can try to listen to the new event. For example:

var spawn = require('child_process').spawn;

// Hexo 2.x
hexo.on('new', function(path){
  spawn('vi', [path]);
});

// Hexo 3
hexo.on('new', function(data){
  spawn('vi', [data.path]);
});

@tommy351 tommy351 added the question label Jan 26, 2015

@andrewboni

This comment has been minimized.

Show comment
Hide comment
@andrewboni

andrewboni Jan 26, 2015

Thanks for the reply. Where should this live?

On Sun, Jan 25, 2015 at 7:47 PM, Tommy Chen notifications@github.com
wrote:

You can try to listen to the new event. For example:

var spawn = require('child_process').spawn;
// Hexo 2.x
hexo.on('new', function(path){
spawn('vi', [path]);
});
// Hexo 3
hexo.on('new', function(data){
spawn('vi', [data.path]);
});


Reply to this email directly or view it on GitHub
#1007 (comment).

andrewboni commented Jan 26, 2015

Thanks for the reply. Where should this live?

On Sun, Jan 25, 2015 at 7:47 PM, Tommy Chen notifications@github.com
wrote:

You can try to listen to the new event. For example:

var spawn = require('child_process').spawn;
// Hexo 2.x
hexo.on('new', function(path){
spawn('vi', [path]);
});
// Hexo 3
hexo.on('new', function(data){
spawn('vi', [data.path]);
});


Reply to this email directly or view it on GitHub
#1007 (comment).

@tommy351

This comment has been minimized.

Show comment
Hide comment
@tommy351

tommy351 Jan 26, 2015

Member

You can add a JavaScript file to scripts folder.
http://hexo.io/docs/plugins.html#Script

Member

tommy351 commented Jan 26, 2015

You can add a JavaScript file to scripts folder.
http://hexo.io/docs/plugins.html#Script

@Xuanwo

This comment has been minimized.

Show comment
Hide comment
@Xuanwo

Xuanwo Dec 15, 2015

Contributor

Closed for no more update.

Contributor

Xuanwo commented Dec 15, 2015

Closed for no more update.

@Xuanwo Xuanwo closed this Dec 15, 2015

@ArchitectBeaver

This comment has been minimized.

Show comment
Hide comment
@ArchitectBeaver

ArchitectBeaver Aug 20, 2017

var spawn = require('child_process').spawn;
// Hexo 3
hexo.on('new', function(data){
spawn('vi', [data.path]);
});

For me, this failed to open Vim in terminal.
I added { stdio: 'inherit' } option to let Vim use parent's stdios.

var spawn = require('child_process').spawn;
 // Hexo 3
hexo.on('new', function(data){
spawn('vim', [data.path], { stdio: 'inherit' });
});

It opens Vim in terminal now.

ArchitectBeaver commented Aug 20, 2017

var spawn = require('child_process').spawn;
// Hexo 3
hexo.on('new', function(data){
spawn('vi', [data.path]);
});

For me, this failed to open Vim in terminal.
I added { stdio: 'inherit' } option to let Vim use parent's stdios.

var spawn = require('child_process').spawn;
 // Hexo 3
hexo.on('new', function(data){
spawn('vim', [data.path], { stdio: 'inherit' });
});

It opens Vim in terminal now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment