Jekyll serve and run

Being lazy, I would like to combine the following two commands so that it works with one simple alias bash.

jekyll -w serve 

starts the development server for my jekyll instance.

 open "http://localhost:4000" 

launches my jekyll application in my default browser.

How can I link them together so that I can type one simple alias on my command line for maintenance and startup?

NOTES

  • Please note that using && or ; for the jekyll -w serve and open "http://localhost:4000" chain open "http://localhost:4000" will not work, because jekyll -w serve starts the constant webrick process in stdout. This means that the second open "http://localhost:4000" command open "http://localhost:4000" will not be executed because the first process (webrick) never "terminated".

  • When webrick begins, we can see a typical output as follows: -

 Configuration file: /Users/calvin/work/calviny/_config.yml Source: /Users/calvin/work/calviny Destination: /Users/calvin/work/calviny/_site Generating... done. Auto-regeneration: enabled [2013-09-08 18:43:58] INFO WEBrick 1.3.1 [2013-09-08 18:43:58] INFO ruby 1.9.3 (2013-06-27) [x86_64-darwin11.4.2] [2013-09-08 18:43:58] INFO WEBrick::HTTPServer#start: pid=6183 port=4000 
+6
source share
5 answers

Currently, I see the following options:

  • use expect to start jekyll, and then in the browser, depending on the specific output line from jekyll , which shows that you can now start the browser.

  • write a small program that sequentially tries to connect to port 4000 . If the connection can be established at a specified time, the browser can be started. Of course, you can also use wget or curl and try to load index.html sequentially.

  • you can recognize that jekyll ready based on the availability of certain files. You can encode something with inotifywait to launch the browser after creating such a file. (But I don't know jekyll , I'm not sure if this is really an option)

0
source
 function jek { jekyll -w serve & open "http://localhost:4000" } 

solves the problem. One & .

+1
source

I'm not 100% on terminal teams, but that seems to have solved this for me. I tested it several times without problems. (I use osx 10.8 if that makes any difference to you)

 function jek { jekyll -w serve & sleep 5 && open "http://localhost:4000" } 
0
source

As hek2mgl suggested, you can do this with expect :

 set timeout 5 spawn jekyll serve expect { -re {Server address:\s+(.+)$} { set address $expect_out(1,string) } } expect "Server running..." catch { exec xdg-open $address } interact 
0
source

jekyll serve > /dev/null 2>&1 & sleep 5 && open "http://localhost:4000"

0
source

Source: https://habr.com/ru/post/953422/


All Articles