diff options
| author | ruki <[email protected]> | 2017-10-13 00:34:19 +0800 |
|---|---|---|
| committer | ruki <[email protected]> | 2017-10-12 21:25:56 +0800 |
| commit | b8c25ec5b6d445464fa9c2e5dd33c5a640b5bcd4 (patch) | |
| tree | 39f84cb332f8465b54cb36f6e20e666463039f2a | |
| parent | 62fe8c95b363434e3c9fe109f7bdd7e1af41c2eb (diff) | |
add xmake macro ..
| -rw-r--r-- | CHANGELOG.md | 2 | ||||
| -rw-r--r-- | xmake/plugins/macro/main.lua | 40 | ||||
| -rw-r--r-- | xmake/plugins/macro/xmake.lua | 3 |
3 files changed, 40 insertions, 5 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index 50c24efb9..b9f96a074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -8,6 +8,7 @@ * Add `xmake -y/--yes` to confirm the user input by default * Add `xmake l package.manager.install xxx` to install software package * Add xmake plugin for vscode editor, [xmake-vscode](https://marketplace.visualstudio.com/items?itemName=tboox.xmake-vscode#overview) +* Add `xmake macro ..` to run the last command ### Changes @@ -375,6 +376,7 @@ * 添加`xmake -y/--yes`去确认用户输入 * 添加`xmake l package.manager.install xxx`模块,进行跨平台一致性安装软件包 * 添加vscode编辑器插件支持,更加方便的使用xmake,[xmake-vscode](https://marketplace.visualstudio.com/items?itemName=tboox.xmake-vscode#overview) +* 添加`xmake macro ..`快速运行最近一次命令 ### 改进 diff --git a/xmake/plugins/macro/main.lua b/xmake/plugins/macro/main.lua index 662ed2a0c..0e144f823 100644 --- a/xmake/plugins/macro/main.lua +++ b/xmake/plugins/macro/main.lua @@ -288,16 +288,48 @@ end -- run macro function _run(macroname) + -- run last command? + if macroname == ".." then + + -- enter local history + history.enter("local.history") + + -- load the history: cmdlines + local cmdlines = history.load("cmdlines") + + -- get the last command + local lastcmd = nil + if cmdlines then + local total = #cmdlines + local index = total + while index ~= 0 do + + -- ignore "xmake m .." and "xmake macro .." + local cmdline = cmdlines[index] + if not cmdline:startswith("__macro_") and not cmdline:find("xmake%s+macro%s*") and not cmdline:find("xmake%s+m%s*") then + lastcmd = cmdline + break + end + + -- the previous line + index = index - 1 + end + end + + -- run the last command + if lastcmd then + os.exec(lastcmd) + end + return + end + -- is anonymous? if macroname == '.' then macroname = "anonymous" end - -- load macro - local macro = import(macroname, {rootdir = _directory(macroname)}) - -- run macro - macro.main(option.get("arguments") or {}) + import(macroname, {rootdir = _directory(macroname), anonymous = true})(option.get("arguments") or {}) end -- main diff --git a/xmake/plugins/macro/xmake.lua b/xmake/plugins/macro/xmake.lua index 5aadd0263..fdfff037c 100644 --- a/xmake/plugins/macro/xmake.lua +++ b/xmake/plugins/macro/xmake.lua @@ -73,7 +73,8 @@ task("macro") , {nil, "name", "v", ".", "Set the macro name." , ".e.g" , " Run the given macro: xmake macro test" - , " Run the anonymous macro: xmake macro ." } + , " Run the anonymous macro: xmake macro ." + , " Run the last command: xmake macro .." } , {nil, "arguments", "vs", nil, "Set the macro arguments." } } } |
