diff --git a/hammerspoon/ime.lua b/hammerspoon/ime.lua index 9b8787b..b6e9303 100644 --- a/hammerspoon/ime.lua +++ b/hammerspoon/ime.lua @@ -1,7 +1,9 @@ log = hs.logger.new('ime', 'debug') +-- you can find the source id by running `hs.keycodes.currentSourceID()` + local function zh() - hs.keycodes.currentSourceID("im.rime.inputmethod.Squirrel.Rime") + hs.keycodes.currentSourceID("im.rime.inputmethod.Squirrel.Hans") end local function en() @@ -17,45 +19,54 @@ local function jp() end -- app to expected ime config -local app2Ime = { - {'/System/Library/CoreServices/Finder.app', 'zh'}, - {'/Applications/Alfred 4.app', 'zh'}, - {'/Applications/Bitwarden.app', 'zh'}, - {'/Applications/Dash.app', 'zh'}, - {'/Applications/iTerm.app', 'zh'}, - {'/Applications/Xcode.app', 'zh'}, - {'/Applications/GoldenDict.app', 'zh'}, - {'/Applications/Google Chrome.app', 'zh'}, - {'/Applications/KakaoTalk.app', 'zh'}, - {'/Applications/kitty.app', 'zh'}, - {'/Applications/NeteaseMusic.app', 'zh'}, - {'/Applications/System Preferences.app', 'zh'}, - {'/Applications/MindNode.app', 'zh'}, - {'/Applications/Obsidian.app', 'zh'}, - {'/Applications/wechatwebdevtools.app', 'zh'}, - {'/Applications/Warp.app', 'en'}, -- 添加这一行 - {'/Applications/WeChat.app', 'zh'}, - {'/Users/einverne/Applications/JetBrains Toolbox/IntelliJ IDEA Ultimate.app', 'zh'}, - {'/Users/einverne/Applications/JetBrains Toolbox/PyCharm Professional.app', 'zh'}, +local appName2Ime = { + { 'Finder', 'en' }, + { 'Bitwarden', 'en' }, + { 'Code', 'en' }, + { 'Dash', 'zh' }, + { 'iTerm', 'zh' }, + { 'GoldenDict', 'zh' }, + { 'GoldenDict-ng', 'zh' }, + { 'Google Chrome', 'zh' }, + { 'IntelliJ IDEA', 'en' }, + { 'KakaoTalk', 'ko' }, + { 'kitty', 'en' }, + { 'NeteaseMusic', 'zh' }, + { 'MacVim', 'en' }, + { 'Raycast', 'en' }, + { 'System Preferences', 'en' }, + { 'SmartGit', 'en' }, + { 'MindNode', 'zh' }, + { 'Obsidian', 'zh' }, + { 'Postman', 'en' }, + { 'PyCharm', 'en' }, + { 'Vivaldi', 'zh' }, + { 'wechatwebdevtools', 'zh' }, + { 'Warp', 'en' }, + { 'WeChat', 'zh' }, + { 'Whistle', 'en' }, + { 'Xcode', 'zh' }, } function updateFocusAppInputMethod() - local focusAppPath = hs.window.frontmostWindow():application():path() - log.d(focusAppPath) - -- hs.alert.show(focusAppPath) - for index, app in pairs(app2Ime) do - local appPath = app[1] + local focusAppName = hs.window.frontmostWindow():application():name() + if focusAppName == nil then + return + end + -- hs.alert.show(focusAppPath) + for index, app in pairs(appName2Ime) do + local appName = app[1] local expectedIme = app[2] - if focusAppPath == appPath then + if focusAppName == appName then if expectedIme == 'en' then en() - elseif expectedIme == 'zh' then - zh() + elseif expectedIme == 'ko' then + ko() elseif expectedIme == 'jp' then jp() - else - ko() + else + zh() end break end @@ -63,23 +74,23 @@ function updateFocusAppInputMethod() end -- helper hotkey to figure out the app path and name of current focused window -hs.hotkey.bind({'ctrl', 'cmd'}, ".", function() - hs.alert.show("App path: " - ..hs.window.focusedWindow():application():path() - .."\n" - .."App name: " - ..hs.window.focusedWindow():application():name() - .."\n" - .."IM source id: " - ..hs.keycodes.currentSourceID()) +hs.hotkey.bind({ 'ctrl', 'cmd' }, ".", function() + hs.alert.show("App path: " + .. hs.window.focusedWindow():application():path() + .. "\n" + .. "App name: " + .. hs.window.focusedWindow():application():name() + .. "\n" + .. "Bundle ID: " + .. hs.window.focusedWindow():application():bundleID() + .. "\n" + .. "IM source id: " + .. hs.keycodes.currentSourceID()) end) -- Handle cursor focus and application's screen manage. function applicationWatcher(appName, eventType, appObject) - log.i(eventType) - log.i("tet") - log.i(hs.application.watcher.activated) - if eventType == hs.application.watcher.activated then + if (eventType == hs.application.watcher.activated or eventType == hs.application.watcher.launched) then updateFocusAppInputMethod() end end diff --git a/hammerspoon/init.lua b/hammerspoon/init.lua index 4424ce0..fbc010d 100644 --- a/hammerspoon/init.lua +++ b/hammerspoon/init.lua @@ -10,8 +10,8 @@ require 'ime' local module = { - 'ime', - 'autoscript' + 'ime', + 'autoscript' } local function loadModuleByName(modName) @@ -26,24 +26,28 @@ end k = hs.hotkey.modal.new({}, "F17") -- Enter Hyper Mode when F18 (Hyper/Capslock) is pressed -pressedF18 = function() k:enter() end +pressedF18 = function() + k:enter() +end -- Leave Hyper Mode when F18 (Hyper/Capslock) is pressed, -- send ESCAPE if no other keys are pressed. -releasedF18 = function() k:exit() end +releasedF18 = function() + k:exit() +end f18 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18) -hyper = {"ctrl", "alt", "cmd", "shift"} +hyper = { "ctrl", "alt", "cmd", "shift" } -- hs.hotkey.bind(hyper, "C", function() hs.application.launchOrFocus("Google Chrome") end) function moveWindowToDisplay(d) - return function() - local displays = hs.screen.allScreens() - log.i(displays) - local win = hs.window.focusedWindow() - win:moveToScreen(displays[d], false, true) - end + return function() + local displays = hs.screen.allScreens() + log.i(displays) + local win = hs.window.focusedWindow() + win:moveToScreen(displays[d], false, true) + end end -- hs.hotkey.bind(hyper, "m", moveWindowToDisplay(1)) @@ -51,37 +55,35 @@ end -- hs.hotkey.bind(hyper, "9", moveWindowToDisplay(3)) function movieWinBetweenMonitors(d) - return function() - local win = hs.window.focusedWindow() - -- get the screen where the focused window is displayed, a.k.a current screen - local screen = win:screen() - -- compute the unitRect of the focused window relative to the current screen - -- and move the window to the next screen setting the same unitRect - -- https://www.hammerspoon.org/docs/hs.window.html#move - if d == 'next' then - win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0) - elseif d == 'previous' then - win:move(win:frame():toUnitRect(screen:frame()), screen:previous(), true, 0) - end - end + return function() + local win = hs.window.focusedWindow() + -- get the screen where the focused window is displayed, a.k.a current screen + local screen = win:screen() + -- compute the unitRect of the focused window relative to the current screen + -- and move the window to the next screen setting the same unitRect + -- https://www.hammerspoon.org/docs/hs.window.html#move + if d == 'next' then + win:move(win:frame():toUnitRect(screen:frame()), screen:next(), true, 0) + elseif d == 'previous' then + win:move(win:frame():toUnitRect(screen:frame()), screen:previous(), true, 0) + end + end end hs.hotkey.bind(hyper, 'N', movieWinBetweenMonitors('next')) hs.hotkey.bind(hyper, 'P', movieWinBetweenMonitors('previous')) - - local grid = require 'hs.grid' hs.hotkey.bind(hyper, ",", grid.show) -middle_monitor="DELL U2414H" -left_monitor="DELL P2417H" -right_monitor="DELL U2412M" +middle_monitor = "DELL U2414H" +left_monitor = "DELL P2417H" +right_monitor = "DELL U2412M" local reading_layout = { - {"Google Chrome", nil, middle_monitor, hs.layout.maximized, nil, nil}, - {"iTerm", nil, left_monitor, hs.layout.maximized, nil, nil}, - {"Miwork", nil, right_monitor, hs.layout.top50, nil, nil}, + { "Google Chrome", nil, middle_monitor, hs.layout.maximized, nil, nil }, + { "iTerm", nil, left_monitor, hs.layout.maximized, nil, nil }, + { "Miwork", nil, right_monitor, hs.layout.top50, nil, nil }, } -- hs.hotkey.bind(hyper, "1", function() @@ -93,8 +95,8 @@ local reading_layout = { -- end) local coding_layout = { - {"IntelliJ IDEA Ultimate", nil, middle_monitor, hs.layout.maximized, nil, nil}, - {"iTerm", nil, left_monitor, hs.layout.maximized, nil, nil}, + { "IntelliJ IDEA Ultimate", nil, middle_monitor, hs.layout.maximized, nil, nil }, + { "iTerm", nil, left_monitor, hs.layout.maximized, nil, nil }, } -- hs.hotkey.bind(hyper, "2", function() @@ -109,42 +111,42 @@ homeSSID = "PhRouter_5G" homeDDID1 = "EinVerne_5G" lastSSID = hs.wifi.currentNetwork() -workSSID = "MIOffice-5G" +workSSID = "XXX-5G" function selectKarabinerProfile(profile) - hs.execute("'/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli' --select-profile '" .. profile .. "'") + hs.execute("'/Library/Application Support/org.pqrs/Karabiner-Elements/bin/karabiner_cli' --select-profile '" .. profile .. "'") end function ssidChangedCallback() newSSID = hs.wifi.currentNetwork() - local devices = hs.usb.attachedDevices() + local devices = hs.usb.attachedDevices() if newSSID == homeSSID and lastSSID ~= homeSSID then -- We just joined our home WiFi network - -- hs.alert.show("Welcome home!") - hs.notify.new({title="Wifi", informativeText="Welcome home"}):send() + -- hs.alert.show("Welcome home!") + hs.notify.new({ title = "Wifi", informativeText = "Welcome home" }):send() hs.audiodevice.defaultOutputDevice():setVolume(25) - -- result = hs.network.configuration:setLocation("Home") - -- hs.alert.show(result) + -- result = hs.network.configuration:setLocation("Home") + -- hs.alert.show(result) elseif newSSID ~= homeSSID and lastSSID == homeSSID then -- We just departed our home WiFi network - -- hs.alert.show("left home!") - hs.notify.new({title="Wifi", informativeText="Left home"}):send() + -- hs.alert.show("left home!") + hs.notify.new({ title = "Wifi", informativeText = "Left home" }):send() hs.audiodevice.defaultOutputDevice():setVolume(0) - -- result = hs.network.configuration:setLocation("Automatic") - -- hs.alert.show(result) + -- result = hs.network.configuration:setLocation("Automatic") + -- hs.alert.show(result) end - if newSSID == workSSID then - -- hs.alert.show("work karabiner setup") - hs.notify.new({title="Wifi", informativeText="work karabiner setup"}):send() - selectKarabinerProfile("goku") - else - -- hs.alert.show("built-in karabiner setup") - hs.notify.new({title="Wifi", informativeText="built-in karabiner setup"}):send() - selectKarabinerProfile("goku") - end + if newSSID == workSSID then + -- hs.alert.show("work karabiner setup") + hs.notify.new({ title = "Wifi", informativeText = "work karabiner setup" }):send() + selectKarabinerProfile("goku") + else + -- hs.alert.show("built-in karabiner setup") + hs.notify.new({ title = "Wifi", informativeText = "built-in karabiner setup" }):send() + selectKarabinerProfile("goku") + end lastSSID = newSSID end @@ -156,35 +158,34 @@ networkConf = hs.network.configuration.open() location = networkConf:location() function switchNetworkLocation(location) - hs.execute('/usr/sbin/networksetup -switchtolocation ' .. location) + hs.execute('/usr/sbin/networksetup -switchtolocation ' .. location) end -hs.hotkey.bind({"cmd", "alt", "ctrl"}, "H", function() - switchNetworkLocation("Home") +hs.hotkey.bind({ "cmd", "alt", "ctrl" }, "H", function() + switchNetworkLocation("Home") end) -hs.hotkey.bind({"cmd", "alt", "ctrl"}, "W", function() - switchNetworkLocation("Automatic") +hs.hotkey.bind({ "cmd", "alt", "ctrl" }, "W", function() + switchNetworkLocation("Automatic") end) -homeDNS="192.168.2.21" -automaticLocationUUID="/Sets/5783E8CE-BA08-4BE2-9799-5F00E15E5837" -homeLocationUUID="/Sets/C55127DB-F0CD-4573-890A-6F8EB59D9AFF" - -hs.network.reachability.forAddress(homeDNS):setCallback(function(self, flags) - -- note that because having an internet connection at all will show the remote network - -- as "reachable", we instead look at whether or not our specific address is "local" instead - local networkConf = hs.network.configuration.open() - if (flags & hs.network.reachability.flags.reachable) > 0 and currentLocation == homeLocationUUID then - hs.alert.show("switch to Home network location") - networkConf:setLocation("Home") - elseif (flags & hs.network.reachability.flags.reachable) == 0 and currentLocation ~= homeLocationUUID then - -- hs.alert.show("switch back to Automatic network location") - hs.notify.new({title="", informativeText="switch back to Automatic network location"}):send() - networkConf:setLocation("Automatic") - end +homeDNS = "192.168.2.21" +automaticLocationUUID = "/Sets/5783E8CE-BA08-4BE2-9799-5F00E15E5837" +homeLocationUUID = "/Sets/C55127DB-F0CD-4573-890A-6F8EB59D9AFF" + +hs .network.reachability.forAddress(homeDNS):setCallback(function(self, flags) + -- note that because having an internet connection at all will show the remote network + -- as "reachable", we instead look at whether or not our specific address is "local" instead + local networkConf = hs.network.configuration.open() + if (flags & hs.network.reachability.flags.reachable) > 0 and currentLocation == homeLocationUUID then + hs.alert.show("switch to Home network location") + networkConf:setLocation("Home") + elseif (flags & hs.network.reachability.flags.reachable) == 0 and currentLocation ~= homeLocationUUID then + -- hs.alert.show("switch back to Automatic network location") + hs.notify.new({ title = "", informativeText = "switch back to Automatic network location" }):send() + networkConf:setLocation("Automatic") + end end):start() - hs.hotkey.alertDuration = 0 hs.hints.showTitleThresh = 0 hs.window.animationDuration = 0 @@ -193,7 +194,7 @@ hs.window.animationDuration = 0 custom_config = hs.fs.pathToAbsolute(os.getenv("HOME") .. '/.config/hammerspoon/private/config.lua') if custom_config then print("Loading custom config") - dofile( os.getenv("HOME") .. "/.config/hammerspoon/private/config.lua") + dofile(os.getenv("HOME") .. "/.config/hammerspoon/private/config.lua") privatepath = hs.fs.pathToAbsolute(hs.configdir .. '/private/config.lua') if privatepath then hs.alert("You have config in both .config/hammerspoon and .hammerspoon/private.\nThe .config/hammerspoon one will be used.") @@ -212,18 +213,16 @@ else end end - - function reloadConfig() - hs.reload() - hs.execute("/bin/launchctl kickstart -k \"gui/${UID}/homebrew.mxcl.yabai\"") + hs.reload() + hs.execute("/bin/launchctl kickstart -k \"gui/${UID}/homebrew.mxcl.yabai\"") end -hsreload_keys = {hyper, "R"} -hsreload_keys = hsreload_keys or {{"cmd", "shift", "ctrl"}, "R"} +hsreload_keys = { hyper, "R" } +hsreload_keys = hsreload_keys or { { "cmd", "shift", "ctrl" }, "R" } if string.len(hsreload_keys[2]) > 0 then hs.hotkey.bind(hsreload_keys[1], hsreload_keys[2], "Reload Configuration", reloadConfig) - hs.notify.new({title="Hammerspoon config reloaded", informativeText="Manually trigged via keyboard shortcut"}):send() + hs.notify.new({ title = "Hammerspoon config reloaded", informativeText = "Manually trigged via keyboard shortcut" }):send() end -- ModalMgr Spoon must be loaded explicitly, because this repository heavily relies upon it. @@ -240,9 +239,9 @@ if not hspoon_list then "HCalendar", --"HSaria2", "WinWin", - "WifiNotifier", - "WinRectangle", - "Caffeine", + --"WifiNotifier", + "WinRectangle", + "Caffeine", "PomodoroTimer", } end @@ -256,13 +255,13 @@ hs.hotkey.bind({}, "F12", function() local app = hs.application.get("dev.warp.Warp-Stable") if app then if not app:mainWindow() then - app:selectMenuItem({"Warp", "New Window"}) + app:selectMenuItem({ "Warp", "New Window" }) elseif app:isFrontmost() then app:hide() else app:activate() end - app:mainWindow():moveToUnit'[100, 80, 0, 0]' + app:mainWindow():moveToUnit '[100, 80, 0, 0]' else hs.application.launchOrFocus("/Applications/Warp.app") app = hs.application.get("dev.warp.Warp-Stable") @@ -273,7 +272,7 @@ end) -- Then we create/register all kinds of modal keybindings environments. ---------------------------------------------------------------------------------------------------- -- Register windowHints (Register a keybinding which is NOT modal environment with modal supervisor) -hswhints_keys = hswhints_keys or {"alt", "tab"} +hswhints_keys = hswhints_keys or { "alt", "tab" } if string.len(hswhints_keys[2]) > 0 then spoon.ModalMgr.supervisor:bind(hswhints_keys[1], hswhints_keys[2], 'Show Window Hints', function() spoon.ModalMgr:deactivateAll() @@ -285,18 +284,24 @@ end -- appM modal environment spoon.ModalMgr:new("appM") local cmodal = spoon.ModalMgr.modal_list["appM"] -cmodal:bind('', 'escape', 'Deactivate appM', function() spoon.ModalMgr:deactivate({"appM"}) end) -cmodal:bind('', 'Q', 'Deactivate appM', function() spoon.ModalMgr:deactivate({"appM"}) end) -cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() spoon.ModalMgr:toggleCheatsheet() end) +cmodal:bind('', 'escape', 'Deactivate appM', function() + spoon.ModalMgr:deactivate({ "appM" }) +end) +cmodal:bind('', 'Q', 'Deactivate appM', function() + spoon.ModalMgr:deactivate({ "appM" }) +end) +cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() + spoon.ModalMgr:toggleCheatsheet() +end) if not hsapp_list then hsapp_list = { - {key = 'f', name = 'Finder'}, - {key = 'c', name = 'Google Chrome'}, - {key = 'o', name = 'Obsidian'}, - {key = 's', name = 'Safari'}, - {key = 't', name = 'Terminal'}, - {key = 'v', id = 'com.apple.ActivityMonitor'}, - {key = 'y', id = 'com.apple.systempreferences'}, + { key = 'f', name = 'Finder' }, + { key = 'c', name = 'Google Chrome' }, + { key = 'o', name = 'Obsidian' }, + { key = 's', name = 'Safari' }, + { key = 't', name = 'Terminal' }, + { key = 'v', id = 'com.apple.ActivityMonitor' }, + { key = 'y', id = 'com.apple.systempreferences' }, } end for _, v in ipairs(hsapp_list) do @@ -305,24 +310,24 @@ for _, v in ipairs(hsapp_list) do if located_name then cmodal:bind('', v.key, located_name, function() hs.application.launchOrFocusByBundleID(v.id) - spoon.ModalMgr:deactivate({"appM"}) + spoon.ModalMgr:deactivate({ "appM" }) end) end elseif v.name then cmodal:bind('', v.key, v.name, function() hs.application.launchOrFocus(v.name) - spoon.ModalMgr:deactivate({"appM"}) + spoon.ModalMgr:deactivate({ "appM" }) end) end end -- Then we register some keybindings with modal supervisor -hsappM_keys = hsappM_keys or {"alt", "A"} +hsappM_keys = hsappM_keys or { "alt", "A" } if string.len(hsappM_keys[2]) > 0 then spoon.ModalMgr.supervisor:bind(hsappM_keys[1], hsappM_keys[2], "Enter AppM Environment", function() spoon.ModalMgr:deactivateAll() -- Show the keybindings cheatsheet once appM is activated - spoon.ModalMgr:activate({"appM"}, "#FFBD2E", true) + spoon.ModalMgr:activate({ "appM" }, "#FFBD2E", true) end) end @@ -333,11 +338,11 @@ if spoon.ClipShow then local cmodal = spoon.ModalMgr.modal_list["clipshowM"] cmodal:bind('', 'escape', 'Deactivate clipshowM', function() spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) cmodal:bind('', 'Q', 'Deactivate clipshowM', function() spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) cmodal:bind('', 'N', 'Save this Session', function() spoon.ClipShow:saveToSession() @@ -348,37 +353,37 @@ if spoon.ClipShow then cmodal:bind('', 'B', 'Open in Browser', function() spoon.ClipShow:openInBrowserWithRef() spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) cmodal:bind('', 'S', 'Search with Bing', function() spoon.ClipShow:openInBrowserWithRef("https://www.bing.com/search?q=") spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) cmodal:bind('', 'M', 'Open in MacVim', function() spoon.ClipShow:openWithCommand("/usr/local/bin/mvim") spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) cmodal:bind('', 'F', 'Save to Desktop', function() spoon.ClipShow:saveToFile() spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) cmodal:bind('', 'H', 'Search in Github', function() spoon.ClipShow:openInBrowserWithRef("https://github.com/search?q=") spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) cmodal:bind('', 'G', 'Search with Google', function() spoon.ClipShow:openInBrowserWithRef("https://www.google.com/search?q=") spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) cmodal:bind('', 'L', 'Open in Sublime Text', function() spoon.ClipShow:openWithCommand("/usr/local/bin/subl") spoon.ClipShow:toggleShow() - spoon.ModalMgr:deactivate({"clipshowM"}) + spoon.ModalMgr:deactivate({ "clipshowM" }) end) end @@ -391,9 +396,11 @@ if spoon.HSaria2 then hsaria2_secret = hsaria2_secret or "token" spoon.HSaria2:connectToHost(hsaria2_host, hsaria2_secret) - hsaria2_keys = hsaria2_keys or {"alt", "D"} + hsaria2_keys = hsaria2_keys or { "alt", "D" } if string.len(hsaria2_keys[2]) > 0 then - spoon.ModalMgr.supervisor:bind(hsaria2_keys[1], hsaria2_keys[2], 'Toggle aria2 Panel', function() spoon.HSaria2:togglePanel() end) + spoon.ModalMgr.supervisor:bind(hsaria2_keys[1], hsaria2_keys[2], 'Toggle aria2 Panel', function() + spoon.HSaria2:togglePanel() + end) end end @@ -414,35 +421,41 @@ end if spoon.CountDown then spoon.ModalMgr:new("countdownM") local cmodal = spoon.ModalMgr.modal_list["countdownM"] - cmodal:bind('', 'escape', 'Deactivate countdownM', function() spoon.ModalMgr:deactivate({"countdownM"}) end) - cmodal:bind('', 'Q', 'Deactivate countdownM', function() spoon.ModalMgr:deactivate({"countdownM"}) end) - cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() spoon.ModalMgr:toggleCheatsheet() end) + cmodal:bind('', 'escape', 'Deactivate countdownM', function() + spoon.ModalMgr:deactivate({ "countdownM" }) + end) + cmodal:bind('', 'Q', 'Deactivate countdownM', function() + spoon.ModalMgr:deactivate({ "countdownM" }) + end) + cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() + spoon.ModalMgr:toggleCheatsheet() + end) cmodal:bind('', '0', '5 Minutes Countdown', function() spoon.CountDown:startFor(5) - spoon.ModalMgr:deactivate({"countdownM"}) + spoon.ModalMgr:deactivate({ "countdownM" }) end) for i = 1, 9 do cmodal:bind('', tostring(i), string.format("%s Minutes Countdown", 10 * i), function() spoon.CountDown:startFor(10 * i) - spoon.ModalMgr:deactivate({"countdownM"}) + spoon.ModalMgr:deactivate({ "countdownM" }) end) end cmodal:bind('', 'return', '25 Minutes Countdown', function() spoon.CountDown:startFor(25) - spoon.ModalMgr:deactivate({"countdownM"}) + spoon.ModalMgr:deactivate({ "countdownM" }) end) cmodal:bind('', 'space', 'Pause/Resume CountDown', function() spoon.CountDown:pauseOrResume() - spoon.ModalMgr:deactivate({"countdownM"}) + spoon.ModalMgr:deactivate({ "countdownM" }) end) -- Register countdownM with modal supervisor - hscountdM_keys = hscountdM_keys or {"alt", "I"} + hscountdM_keys = hscountdM_keys or { "alt", "I" } if string.len(hscountdM_keys[2]) > 0 then spoon.ModalMgr.supervisor:bind(hscountdM_keys[1], hscountdM_keys[2], "Enter countdownM Environment", function() spoon.ModalMgr:deactivateAll() -- Show the keybindings cheatsheet once countdownM is activated - spoon.ModalMgr:activate({"countdownM"}, "#FF6347", true) + spoon.ModalMgr:activate({ "countdownM" }, "#FF6347", true) end) end end @@ -452,46 +465,143 @@ end if spoon.WinWin then spoon.ModalMgr:new("resizeM") local cmodal = spoon.ModalMgr.modal_list["resizeM"] - cmodal:bind('', 'escape', 'Deactivate resizeM', function() spoon.ModalMgr:deactivate({"resizeM"}) end) - cmodal:bind('', 'Q', 'Deactivate resizeM', function() spoon.ModalMgr:deactivate({"resizeM"}) end) - cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() spoon.ModalMgr:toggleCheatsheet() end) - cmodal:bind('', 'A', 'Move Leftward', function() spoon.WinWin:stepMove("left") end, nil, function() spoon.WinWin:stepMove("left") end) - cmodal:bind('', 'D', 'Move Rightward', function() spoon.WinWin:stepMove("right") end, nil, function() spoon.WinWin:stepMove("right") end) - cmodal:bind('', 'W', 'Move Upward', function() spoon.WinWin:stepMove("up") end, nil, function() spoon.WinWin:stepMove("up") end) - cmodal:bind('', 'S', 'Move Downward', function() spoon.WinWin:stepMove("down") end, nil, function() spoon.WinWin:stepMove("down") end) - cmodal:bind('', 'H', 'Lefthalf of Screen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("halfleft") end) - cmodal:bind('', 'L', 'Righthalf of Screen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("halfright") end) - cmodal:bind('', 'K', 'Uphalf of Screen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("halfup") end) - cmodal:bind('', 'J', 'Downhalf of Screen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("halfdown") end) - cmodal:bind('', 'Y', 'NorthWest Corner', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("cornerNW") end) - cmodal:bind('', 'O', 'NorthEast Corner', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("cornerNE") end) - cmodal:bind('', 'U', 'SouthWest Corner', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("cornerSW") end) - cmodal:bind('', 'I', 'SouthEast Corner', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("cornerSE") end) - cmodal:bind('', 'F', 'Fullscreen', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("fullscreen") end) - cmodal:bind('', 'C', 'Center Window', function() spoon.WinWin:stash() spoon.WinWin:moveAndResize("center") end) - cmodal:bind('', '=', 'Stretch Outward', function() spoon.WinWin:moveAndResize("expand") end, nil, function() spoon.WinWin:moveAndResize("expand") end) - cmodal:bind('', '-', 'Shrink Inward', function() spoon.WinWin:moveAndResize("shrink") end, nil, function() spoon.WinWin:moveAndResize("shrink") end) - cmodal:bind('shift', 'H', 'Move Leftward', function() spoon.WinWin:stepResize("left") end, nil, function() spoon.WinWin:stepResize("left") end) - cmodal:bind('shift', 'L', 'Move Rightward', function() spoon.WinWin:stepResize("right") end, nil, function() spoon.WinWin:stepResize("right") end) - cmodal:bind('shift', 'K', 'Move Upward', function() spoon.WinWin:stepResize("up") end, nil, function() spoon.WinWin:stepResize("up") end) - cmodal:bind('shift', 'J', 'Move Downward', function() spoon.WinWin:stepResize("down") end, nil, function() spoon.WinWin:stepResize("down") end) - cmodal:bind('', 'left', 'Move to Left Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("left") end) - cmodal:bind('', 'right', 'Move to Right Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("right") end) - cmodal:bind('', 'up', 'Move to Above Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("up") end) - cmodal:bind('', 'down', 'Move to Below Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("down") end) - cmodal:bind('', 'space', 'Move to Next Monitor', function() spoon.WinWin:stash() spoon.WinWin:moveToScreen("next") end) - cmodal:bind('', '[', 'Undo Window Manipulation', function() spoon.WinWin:undo() end) - cmodal:bind('', ']', 'Redo Window Manipulation', function() spoon.WinWin:redo() end) - cmodal:bind('', '`', 'Center Cursor', function() spoon.WinWin:centerCursor() end) + cmodal:bind('', 'escape', 'Deactivate resizeM', function() + spoon.ModalMgr:deactivate({ "resizeM" }) + end) + cmodal:bind('', 'Q', 'Deactivate resizeM', function() + spoon.ModalMgr:deactivate({ "resizeM" }) + end) + cmodal:bind('', 'tab', 'Toggle Cheatsheet', function() + spoon.ModalMgr:toggleCheatsheet() + end) + cmodal:bind('', 'A', 'Move Leftward', function() + spoon.WinWin:stepMove("left") + end, nil, function() + spoon.WinWin:stepMove("left") + end) + cmodal:bind('', 'D', 'Move Rightward', function() + spoon.WinWin:stepMove("right") + end, nil, function() + spoon.WinWin:stepMove("right") + end) + cmodal:bind('', 'W', 'Move Upward', function() + spoon.WinWin:stepMove("up") + end, nil, function() + spoon.WinWin:stepMove("up") + end) + cmodal:bind('', 'S', 'Move Downward', function() + spoon.WinWin:stepMove("down") + end, nil, function() + spoon.WinWin:stepMove("down") + end) + cmodal:bind('', 'H', 'Lefthalf of Screen', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("halfleft") + end) + cmodal:bind('', 'L', 'Righthalf of Screen', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("halfright") + end) + cmodal:bind('', 'K', 'Uphalf of Screen', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("halfup") + end) + cmodal:bind('', 'J', 'Downhalf of Screen', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("halfdown") + end) + cmodal:bind('', 'Y', 'NorthWest Corner', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("cornerNW") + end) + cmodal:bind('', 'O', 'NorthEast Corner', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("cornerNE") + end) + cmodal:bind('', 'U', 'SouthWest Corner', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("cornerSW") + end) + cmodal:bind('', 'I', 'SouthEast Corner', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("cornerSE") + end) + cmodal:bind('', 'F', 'Fullscreen', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("fullscreen") + end) + cmodal:bind('', 'C', 'Center Window', function() + spoon.WinWin:stash() + spoon.WinWin:moveAndResize("center") + end) + cmodal:bind('', '=', 'Stretch Outward', function() + spoon.WinWin:moveAndResize("expand") + end, nil, function() + spoon.WinWin:moveAndResize("expand") + end) + cmodal:bind('', '-', 'Shrink Inward', function() + spoon.WinWin:moveAndResize("shrink") + end, nil, function() + spoon.WinWin:moveAndResize("shrink") + end) + cmodal:bind('shift', 'H', 'Move Leftward', function() + spoon.WinWin:stepResize("left") + end, nil, function() + spoon.WinWin:stepResize("left") + end) + cmodal:bind('shift', 'L', 'Move Rightward', function() + spoon.WinWin:stepResize("right") + end, nil, function() + spoon.WinWin:stepResize("right") + end) + cmodal:bind('shift', 'K', 'Move Upward', function() + spoon.WinWin:stepResize("up") + end, nil, function() + spoon.WinWin:stepResize("up") + end) + cmodal:bind('shift', 'J', 'Move Downward', function() + spoon.WinWin:stepResize("down") + end, nil, function() + spoon.WinWin:stepResize("down") + end) + cmodal:bind('', 'left', 'Move to Left Monitor', function() + spoon.WinWin:stash() + spoon.WinWin:moveToScreen("left") + end) + cmodal:bind('', 'right', 'Move to Right Monitor', function() + spoon.WinWin:stash() + spoon.WinWin:moveToScreen("right") + end) + cmodal:bind('', 'up', 'Move to Above Monitor', function() + spoon.WinWin:stash() + spoon.WinWin:moveToScreen("up") + end) + cmodal:bind('', 'down', 'Move to Below Monitor', function() + spoon.WinWin:stash() + spoon.WinWin:moveToScreen("down") + end) + cmodal:bind('', 'space', 'Move to Next Monitor', function() + spoon.WinWin:stash() + spoon.WinWin:moveToScreen("next") + end) + cmodal:bind('', '[', 'Undo Window Manipulation', function() + spoon.WinWin:undo() + end) + cmodal:bind('', ']', 'Redo Window Manipulation', function() + spoon.WinWin:redo() + end) + cmodal:bind('', '`', 'Center Cursor', function() + spoon.WinWin:centerCursor() + end) -- Register resizeM with modal supervisor - hsresizeM_keys = hsresizeM_keys or {"alt", "R"} + hsresizeM_keys = hsresizeM_keys or { "alt", "R" } if string.len(hsresizeM_keys[2]) > 0 then spoon.ModalMgr.supervisor:bind(hsresizeM_keys[1], hsresizeM_keys[2], "Enter resizeM Environment", function() -- Deactivate some modal environments or not before activating a new one spoon.ModalMgr:deactivateAll() -- Show an status indicator so we know we're in some modal environment now - spoon.ModalMgr:activate({"resizeM"}, "#B22222") + spoon.ModalMgr:activate({ "resizeM" }, "#B22222") end) end end @@ -532,7 +642,7 @@ end -- Register WinRectangle if spoon.WinRectangle then - spoon.WinRectangle:bindHotkeys(spoon.WinRectangle.defaultHotkeys) + spoon.WinRectangle:bindHotkeys(spoon.WinRectangle.defaultHotkeys) end -- Register Caffeine @@ -540,13 +650,13 @@ end -- spoon.Caffeine:start() -- end -if spoon.wifiNotifier then - spoon.wifiNotifier:start() -end +--if spoon.wifiNotifier then +-- spoon.wifiNotifier:start() +--end log.d("PomodoroTimer Spoon loaded successfully") if spoon.PomodoroTimer then - hs.hotkey.bind({"cmd", "ctrl"}, "0", function() + hs.hotkey.bind({ "cmd", "ctrl" }, "0", function() log.d("PomodoroTimer hotkey pressed") spoon.PomodoroTimer:toggle() end)