1、修复右键选择定位不正确的问题;2、修改了本地片段列表文件后自动Reload config
This commit is contained in:
parent
eb025cede4
commit
7352b399f4
@ -59,6 +59,10 @@
|
|||||||
"subText" : "cmd|mv file1 file2|移动文件名或目录、重命名",
|
"subText" : "cmd|mv file1 file2|移动文件名或目录、重命名",
|
||||||
"text" : "mv"
|
"text" : "mv"
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
"subText" : "cmd|npm install <package>|使用npm安装软件",
|
||||||
|
"text" : "npm install <package>"
|
||||||
|
},
|
||||||
{
|
{
|
||||||
"subText" : "cmd|passwd|修改用户密码",
|
"subText" : "cmd|passwd|修改用户密码",
|
||||||
"text" : "passwd"
|
"text" : "passwd"
|
||||||
@ -128,8 +132,8 @@
|
|||||||
"text" : "\/** \n* @Title: ${file_name} \n* @Package ${package_name} \n* @Description: ${todo}(用一句话描述该文件做什么) \n* @author sugood\n* @date ${date} ${time} \n* @version V1.0 \n*\/"
|
"text" : "\/** \n* @Title: ${file_name} \n* @Package ${package_name} \n* @Description: ${todo}(用一句话描述该文件做什么) \n* @author sugood\n* @date ${date} ${time} \n* @version V1.0 \n*\/"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"subText" : "code|java|author注释模板",
|
"subText" : "ins|brew install node|安装node",
|
||||||
"text" : "something"
|
"text" : "brew install node"
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
"subText" : "key|Command+Option+C|复制路径",
|
"subText" : "key|Command+Option+C|复制路径",
|
3
init.lua
3
init.lua
@ -4,3 +4,6 @@ require "modules/system"
|
|||||||
require "modules/windows"
|
require "modules/windows"
|
||||||
require "modules/launcher"
|
require "modules/launcher"
|
||||||
require "modules/snippet"
|
require "modules/snippet"
|
||||||
|
|
||||||
|
-- 监听~./hammerspoon/data/中的文件,如果有改变就自动更新
|
||||||
|
hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/data", hs.reload):start()
|
||||||
|
@ -2,26 +2,43 @@ local chooser = require("hs.chooser")
|
|||||||
local console = require("hs.console")
|
local console = require("hs.console")
|
||||||
|
|
||||||
console.clearConsole()
|
console.clearConsole()
|
||||||
local historyPath= "~/.hammerspoon/history.json"
|
local historyPath= "~/.hammerspoon/data/history.json"
|
||||||
local maxLength = 1000
|
local maxLength = 1000
|
||||||
local history = {}
|
local history = {}
|
||||||
|
local mChooser
|
||||||
|
|
||||||
function initData()
|
function initData()
|
||||||
if hs.json.read(historyPath) ~= nil then
|
if hs.json.read(historyPath) ~= nil then
|
||||||
history = hs.json.read(historyPath)
|
history = hs.json.read(historyPath)
|
||||||
end
|
end
|
||||||
|
isSearck = false
|
||||||
end
|
end
|
||||||
-- 初始化,读取本地数据
|
-- 初始化,读取本地数据
|
||||||
initData()
|
initData()
|
||||||
-- 查重
|
-- 查重
|
||||||
function duplicate(tablea,keys)
|
function duplicate(table,keys)
|
||||||
for k,v in ipairs(tablea) do
|
for k,v in ipairs(table) do
|
||||||
if v.text == keys then
|
if v.text == keys then
|
||||||
return true
|
return true
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
|
-- 字符串判空
|
||||||
|
function isEmpty(str)
|
||||||
|
return str == nil or str == ''
|
||||||
|
end
|
||||||
|
-- 查询text是否存在并返回索引index
|
||||||
|
-- 等于0为没有查询到,大于0为查询到
|
||||||
|
function searchByText(table,text)
|
||||||
|
for k,v in ipairs(table) do
|
||||||
|
if v.text == text then
|
||||||
|
print("结果:"..k)
|
||||||
|
return k
|
||||||
|
end
|
||||||
|
end
|
||||||
|
return 0
|
||||||
|
end
|
||||||
-- 清除收尾空格
|
-- 清除收尾空格
|
||||||
function trim(input)
|
function trim(input)
|
||||||
return (string.gsub(input, "^%s*(.-)%s*$", "%1"))
|
return (string.gsub(input, "^%s*(.-)%s*$", "%1"))
|
||||||
@ -100,8 +117,17 @@ function modifyHistory(text, subText, isText, index)
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
-- 右键弹出菜单
|
-- 右键弹出菜单
|
||||||
local menuFn = function(index)
|
local rightClickCallbackFn = function(index)
|
||||||
if index then
|
if index and index > 0 then
|
||||||
|
local selectResult = mChooser:selectedRowContents(index)
|
||||||
|
if selectResult == nil or isEmpty(selectResult.text) then
|
||||||
|
return
|
||||||
|
end
|
||||||
|
index = searchByText(history,selectResult.text)
|
||||||
|
if index == 0 then
|
||||||
|
hs.alert.show("找不到片段")
|
||||||
|
return
|
||||||
|
end
|
||||||
menubar = hs.menubar.new(false)
|
menubar = hs.menubar.new(false)
|
||||||
menubar:setTitle("Hidden Menu")
|
menubar:setTitle("Hidden Menu")
|
||||||
menubar:setMenu( {
|
menubar:setMenu( {
|
||||||
@ -135,9 +161,9 @@ local menuFn = function(index)
|
|||||||
end
|
end
|
||||||
-- 选取片段内容(按下快捷键时显示片段列表,点击选中的快捷键将自动粘贴)
|
-- 选取片段内容(按下快捷键时显示片段列表,点击选中的快捷键将自动粘贴)
|
||||||
hs.hotkey.bind({ "ctrl", "cmd" }, "V", function ()
|
hs.hotkey.bind({ "ctrl", "cmd" }, "V", function ()
|
||||||
chooser.new(completionFn)
|
mChooser = chooser.new(completionFn)
|
||||||
:choices(history)
|
:choices(history)
|
||||||
:rightClickCallback(menuFn)
|
:rightClickCallback(rightClickCallbackFn)
|
||||||
:searchSubText(true)
|
:searchSubText(true)
|
||||||
:show()
|
:show()
|
||||||
end)
|
end)
|
||||||
|
Loading…
Reference in New Issue
Block a user