Skip to content

Instantly share code, notes, and snippets.

@faywong
Last active August 23, 2021 09:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save faywong/ef12da41ffd8304b684e1591d7033b8a to your computer and use it in GitHub Desktop.
Save faywong/ef12da41ffd8304b684e1591d7033b8a to your computer and use it in GitHub Desktop.
用 Lua 来代替 Bash.md
  • environment setup

amalg - merge several lua scripts into standalone one net-url - url parser luash - invoke sh commands from lua

brew install --use-clang luarocks
luarocks install --server=http://luarocks.org/dev amalg net-url luash
  • write your main lua script
require('sh')

local wd = tostring(pwd()) -- calls `pwd` and returns its output as a string

local files = tostring(ls('/tmp')) -- calls `ls /tmp`
for f in string.gmatch(files, "[^\n]+") do
        print(f)
end

url = require "net.url"
query = url.parseQuery("first=abc&a[]=123&a[]=false&b[]=str&c[]=3.5&a[]=last")

print(query.a[2])
  • generate dependency cache
lua -lamalg main.lua
  • generate merged standalone lua script
amalg.lua -o out.lua -a -s main.lua -c
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment