从命令行服务当前目录 [英] serve current directory from command line

查看:117
本文介绍了从命令行服务当前目录的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人可以给我一个提示,如何从命令行与ruby服务当前目录?如果我可以有一些系统范围的配置(例如mime类型),并只需从每个目录启动它将是巨大的。

could someone give me a hint, howto serve the current directory from command line with ruby? it would be great, if i can have some system wide configuration (e.g. mime-types) and simply launch it from every directory.

推荐答案

p>最简单的方法(感谢 Aaron Patterson ):

Simplest way possible (thanks Aaron Patterson):

ruby -run -e httpd . -p 9090

替代,更复杂的方式:

ruby -r webrick -e "s = WEBrick::HTTPServer.new(:Port => 9090, :DocumentRoot => Dir.pwd); trap('INT') { s.shutdown }; s.start"






即使第一个命令很难记住,所以我只需要在我的 .bashrc

function serve {
  port="${1:-3000}"
  ruby -run -e httpd . -p $port
}

它提供端口上的当前目录 / em>,但您也可以指定端口:

It serves the current directory on port 3000 by default, but you can also specify the port:

~ $ cd tmp
~/tmp $ serve      # ~/tmp served on port 3000
~/tmp $ cd ../www
~/www $ serve 5000   # ~/www served on port 5000

这篇关于从命令行服务当前目录的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆