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

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

问题描述

谁能给我一个提示,如何使用 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.

推荐答案

最简单的方法(感谢 Aaron Patterson/n0kada):

Simplest way possible (thanks Aaron Patterson/n0kada):

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
}

它默认在端口 3000 上服务当前目录,但您也可以指定端口:

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天全站免登陆