 ﻿#SingleInstance, Force
 #NoTrayIcon
 
-msg .= "a  =>  打开记事本并粘贴`n"
-msg .= "b  =>  显示剪切板内容`n"
-msg .= "c  =>  显示IP`n"
-msg .= "d  =>  使用mintty运行剪切板的命令`n"
-msg .= "e  =>  测试`n"
+global msg
 
-HotKey, a, RunNotepad
-HotKey, b, ShowClipboard
-HotKey, c, ShowIp
-HotKey, d, RunClipboardMintty
-HotKey, e, test
+AddAction("a", "RunNotepad", "用记事本显示剪切板内容")
+AddAction("b", "ShowClipboard", "显示剪切板内容")
+AddAction("c", "ShowIp", "显示IP")
+AddAction("d", "RunClipboardWithMintty", "运行剪切板的命令")
+AddAction("z", "test", "测试")
+
 MsgBox, %msg%
 
 ExitApp
+
+AddAction(key, label, info)
+{
+    msg .= key "  =>  " info "`n"
+    HotKey, %key%, %label%
+}
+
+RunWithBash(command)
+{
+    shell := ComObjCreate("WScript.Shell")
+    exec := shell.Exec("bash -c '" command " | iconv -f utf-8 -t gbk -c")
+    return exec.StdOut.ReadAll()
+}
+
+RunWithCmd(command)
+{
+    shell := ComObjCreate("WScript.Shell")
+    exec := shell.Exec(ComSpec " /C " command)
+    return exec.StdOut.ReadAll()
+}
+
+; ===========
 
 RunNotepad:
     Run, notepad

	ExitApp
return

RunWithBash(command)
{
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec("bash -c '" command " | iconv -f utf-8 -t gbk -c")
    return exec.StdOut.ReadAll()
}

RunWithCmd(command)
{
    shell := ComObjCreate("WScript.Shell")
    exec := shell.Exec(ComSpec " /C " command)
    return exec.StdOut.ReadAll()
}

test:
    MsgBox, test
    ExitApp

    ExitApp
return

RunClipboardWithMintty:
	MsgBox % clipboard
    ;MsgBox % RunWithBash(clipboard)
    ;Run, mintty -e sh -c '%clipboard%; read'
