feat: hammerspoon notmuch indicator

This commit is contained in:
Philipp Hochkamp 2022-11-08 12:47:29 +01:00
parent cddfcc1018
commit 6658775af1
2 changed files with 49 additions and 14 deletions

View file

@ -57,8 +57,14 @@ in
]; ];
home.file.".hammerspoon/init.lua".source = home.file.".hammerspoon/init.lua".source =
let
notmuchMails = pkgs.writeScript "notmuch-get-mail-count" ''
#!/usr/bin/env zsh
printf "I%s F%s W%s" $(notmuch search tag:inbox | wc -l) $(notmuch search tag:follow-up | wc -l) $(notmuch search tag:waiting | wc -l)
'';
in
pkgs.substituteAll { pkgs.substituteAll {
src = ./hammerspoon.lua; inherit myEmacs; src = ./hammerspoon.lua; inherit myEmacs notmuchMails;
}; };
home.file.".finicky.js".source = ./finicky.js; home.file.".finicky.js".source = ./finicky.js;

View file

@ -1,4 +1,3 @@
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
-- Settings -- Settings
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
@ -255,13 +254,13 @@ end)
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
function showHideBundleId(bundleId) function showHideBundleId(bundleId)
local focusedWindow = hs.window.focusedWindow() local focusedWindow = hs.window.focusedWindow()
if focusedWindow ~= nil and focusedWindow:application():bundleID() == bundleId then -- window is focused if focusedWindow ~= nil and focusedWindow:application():bundleID() == bundleId then -- window is focused
focusedWindow:close() -- hide focusedWindow:close() -- hide
else else
hs.application.launchOrFocusByBundleID(bundleId) hs.application.launchOrFocusByBundleID(bundleId)
hs.window.focusedWindow():centerOnScreen(hs.mouse.getCurrentScreen()) hs.window.focusedWindow():centerOnScreen(hs.mouse.getCurrentScreen())
end end
end end
hs.hotkey.bind(modifiers.window, hs.keycodes.map.left, moveCurrentWindowToLeftHalf) hs.hotkey.bind(modifiers.window, hs.keycodes.map.left, moveCurrentWindowToLeftHalf)
@ -279,8 +278,12 @@ hs.hotkey.bind(modifiers.hyper, hs.keycodes.map.delete, function() hs.caffeinate
hs.hotkey.bind(modifiers.hyper, "a", function() showHideBundleId(bundleID.activityMonitor) end) hs.hotkey.bind(modifiers.hyper, "a", function() showHideBundleId(bundleID.activityMonitor) end)
hs.hotkey.bind(modifiers.hyper, "c", function() showHideBundleId(bundleID.safari) end) hs.hotkey.bind(modifiers.hyper, "c", function() showHideBundleId(bundleID.safari) end)
hs.hotkey.bind(modifiers.hyper, "f", function() showHideBundleId(bundleID.faclieThings) end) hs.hotkey.bind(modifiers.hyper, "f", function() showHideBundleId(bundleID.faclieThings) end)
hs.hotkey.bind(modifiers.hyper, "e", function() hs.task.new("@myEmacs@/bin/emacsclient", nil, function() return false end, {"-c", "-a", ""}):start() end) hs.hotkey.bind(modifiers.hyper, "e",
hs.hotkey.bind(modifiers.hyper, "i", function() hs.task.new("@myEmacs@/bin/emacsclient", nil, function() return false end, {"-a", "", "--eval", "(emacs-everywhere)"}):start() end) function() hs.task.new("@myEmacs@/bin/emacsclient", nil, function() return false end, { "-c", "-a", "" }):start() end)
hs.hotkey.bind(modifiers.hyper, "i",
function() hs.task.new("@myEmacs@/bin/emacsclient", nil, function() return false end,
{ "-a", "", "--eval", "(emacs-everywhere)" }):start()
end)
hs.hotkey.bind(modifiers.hyper, "p", function() showHideBundleId(bundleID.timeular) end) hs.hotkey.bind(modifiers.hyper, "p", function() showHideBundleId(bundleID.timeular) end)
hs.hotkey.bind(modifiers.hyper, "b", function() showHideBundleId(bundleID.bitwarden) end) hs.hotkey.bind(modifiers.hyper, "b", function() showHideBundleId(bundleID.bitwarden) end)
hs.hotkey.bind(modifiers.hyper, "t", function() showHideBundleId(bundleID.iterm) end) hs.hotkey.bind(modifiers.hyper, "t", function() showHideBundleId(bundleID.iterm) end)
@ -444,7 +447,7 @@ end)
---------------------------------------------------------------------------------------------------- ----------------------------------------------------------------------------------------------------
local function facileCaptpure() local function facileCaptpure()
ok,text = hs.dialog.textPrompt("Facilethings","Capture") ok, text = hs.dialog.textPrompt("Facilethings", "Capture")
if ok then if ok then
hs.osascript.applescript(string.format([[ hs.osascript.applescript(string.format([[
tell application "Mail" tell application "Mail"
@ -461,7 +464,33 @@ tell application "Mail"
end tell end tell
end tell end tell
]], text)) ]] , text))
end end
end end
hs.hotkey.bind(modifiers.window, "f",facileCaptpure)
hs.hotkey.bind(modifiers.window, "f", facileCaptpure)
----------------------------------------------------------------------------------------------------
-- notmuch indicator
----------------------------------------------------------------------------------------------------
local notmuchTaskRunning = false
local function refreshNotmuchMenubar()
hs.task.new("@notmuchMails@", function(exitCode, stdout, stderr)
print(stdout)
notmuchMenubar:setTitle(hs.styledtext.new(stdout))
end):start()
end
notmuchMenubar = hs.menubar.new()
notmuchMenubar:setClickCallback(function() hs.task.new("@myEmacs@/bin/emacsclient", nil, function() return false end,
{ "-a", "", "--eval", "(=notmuch)" }):start()
end)
notmuchTimer = hs.timer.doEvery(300, function()
if not notmuchTaskRunning then
notmuchTaskRunning = true
hs.task.new("/etc/profiles/per-user/ragon/bin/zsh",
function() notmuchTaskRunning = false; refreshNotmuchMenubar() end,
function() return false end, { "-c", "syncmail" }):start()
end
end)