Compare commits

...

2 Commits

Author SHA1 Message Date
Felipe Martin 83d6e3f7cf wezterm config 2024-02-08 09:15:22 +01:00
Felipe Martin a08934a1e3 hammerspoon config 2024-02-08 09:15:11 +01:00
3 changed files with 257 additions and 0 deletions

View File

@ -0,0 +1,92 @@
-- --------------------------------------------------------------------------
--
-- Implementation of a dark mode library for detecting and setting dark
-- mode in MacOS.
--
-- --------------------------------------------------------------------------
--
-- Example:
--
-- dm = require "darkmode"
-- dm.addHandler(function(dm2) print('darkmode changed:',dm2) end)
-- print('darkmode:',dm.getDarkMode())
-- dm.setDarkMode(not dm.getDarkMode())
-- print('darkmode:',dm.getDarkMode())
-- dm.setDarkMode(not dm.getDarkMode())
--
-- --------------------------------------------------------------------------
-- --------------------------------------------------------------------------
-- internal Data which should not be garbage collected
-- --------------------------------------------------------------------------
local internalData = {
darkmode = false,
watcher = nil,
handler = {}
}
-- --------------------------------------------------------------------------
-- General functions
-- --------------------------------------------------------------------------
local function getDarkModeFromSystem()
-- local _, darkmode = hs.osascript.applescript('tell application "System Events"\nreturn dark mode of appearance preferences\nend tell')
local _, darkmode = hs.osascript.javascript("Application('System Events').appearancePreferences.darkMode.get()")
return darkmode
end
local function getDarkMode()
return internalData.darkmode
end
local function setDarkMode(state)
hs.osascript.javascript(string.format("Application('System Events').appearancePreferences.darkMode.set(%s)",state))
end
local function addHandler(fn)
-- add it here...
internalData.handler[#internalData.handler+1] = fn
end
-- --------------------------------------------------------------------------
-- Internal functions
-- --------------------------------------------------------------------------
local function initialize()
internalData.darkmode = getDarkModeFromSystem()
end
local function initializeWatcher()
-- exit if already watching
if internalData.watcher ~= nil then return end
internalData.watcher = hs.distributednotifications.new(function(name, object, userInfo)
local hasDarkMode = getDarkModeFromSystem()
if hasDarkMode ~= internalData.darkmode then
internalData.darkmode = hasDarkMode
-- execute each handler with the darkmode as parameter (may change in future)
for index, fn in ipairs(internalData.handler) do
fn(hasDarkMode)
end
end
end,'AppleInterfaceThemeChangedNotification')
internalData.watcher:start()
end
-- --------------------------------------------------------------------------
-- Initialization
-- --------------------------------------------------------------------------
initialize()
initializeWatcher()
local module = {
_ = internalData,
setDarkMode = setDarkMode,
getDarkMode = getDarkMode,
addHandler = addHandler
}
return module

108
.hammerspoon/init.lua Normal file
View File

@ -0,0 +1,108 @@
local darkmode = require("Spoons/darkmode")
-- Variables
local hyperKey = {"alt", "shift", "ctrl", "cmd"}
-- termApplication = "Alacritty"
local termApplication = "WezTerm"
-- Highlight the currently focused window
hs.window.highlight.start()
-- Enable spotlight to search applications by name
hs.application.enableSpotlightForNameSearches(true)
-- Reload configuration automatically
local function reloadConfig(files)
local doReload = false
for _, file in pairs(files) do
if file:sub(-4) == ".lua" then
doReload = true
end
end
if doReload then
hs.reload()
end
end
local myWatcher = hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", reloadConfig):start()
hs.alert.show("hs.config updated")
-- Allow a scratchpad-like behavior for a certain app with a key combination
local function scratchpadAppWithCombination(modifier, key, appName)
hs.hotkey.bind(modifier, key, function()
local app = hs.application.get(appName)
if app then
space = hs.spaces.activeSpaceOnScreen(hs.screen.mainScreen())
if not app:mainWindow() then
app:selectMenuItem({appName, "New OS window"})
elseif app:isFrontmost() then
app:hide()
else
app:unhide()
hs.spaces.moveWindowToSpace(app:focusedWindow(), space)
app:activate()
end
else
hs.application.launchOrFocus(appName)
end
end)
end
-- Focus a window with a combination
LastFocusedWindow = nil
local function focusAppWithCombination(modifier, key, appName)
hs.hotkey.bind(modifier, key, function()
local app = hs.application.get(appName)
if app then
if app:focusedWindow() == hs.window.focusedWindow() then
LastFocusedWindow:focus()
LastFocusedWindow = app:mainWindow()
else
LastFocusedWindow = hs.window.focusedWindow()
-- hs.application.launchOrFocus(appName)
app:mainWindow():focus()
end
else
hs.alert.show("iTerm not running")
end
end)
end
-- Setup
scratchpadAppWithCombination({"cmd", "shift"}, "-", "Obsidian")
-- scratchpadAppWithCombination(hyperKey, "-", "Notion")
scratchpadAppWithCombination({"ctrl"}, "return", termApplication)
-- Dark mode toggles
local function toggleMattermostTheme(dark)
print('theme changed to dark:', dark)
end
darkmode.addHandler(toggleMattermostTheme)
-- Test
-- function safariMouseBack()
-- end
-- termBinds = {}
-- function enableBinds()
-- -- hs.console.printStyledtext("term focused")
-- for k, v in pairs(termBinds) do
-- v:enable()
-- end
-- end
-- function disableBinds()
-- -- hs.console.printStyledtext("term unfocused")
-- for k, v in pairs(termBinds) do
-- v:disable()
-- end
-- end
-- local wf = hs.window.filter
-- wf_safari = wf.new {'Safari'}
-- wf_safari:subscribe(wf.windowFocused, enableBinds)
-- wf_safari:subscribe(wf.windowUnfocused, disableBinds)

57
.wezterm.lua Normal file
View File

@ -0,0 +1,57 @@
-- Pull in the wezterm API
local wezterm = require 'wezterm'
-- This will hold the configuration.
local config = wezterm.config_builder()
function scheme_for_appearance(appearance)
if appearance:find 'Dark' then
return 'Catppuccin Mocha'
else
return 'Catppuccin Latte'
end
end
local act = wezterm.action
local config = wezterm.config_builder()
config.keys = {
{
key = 'E',
mods = 'CTRL|SHIFT',
action = act.PromptInputLine {
description = 'Enter new name for tab',
action = wezterm.action_callback(function(window, pane, line)
-- line will be `nil` if they hit escape without entering anything
-- An empty string if they just hit enter
-- Or the actual line of text they wrote
if line then
window:active_tab():set_title(line)
end
end),
},
},
}
wezterm.on('window-config-reloaded', function(window, pane)
local overrides = window:get_config_overrides() or {}
local appearance = window:get_appearance()
local scheme = scheme_for_appearance(appearance)
if overrides.color_scheme ~= scheme then
overrides.color_scheme = scheme
window:set_config_overrides(overrides)
end
end)
-- This is where you actually apply your config choices
-- For example, changing the color scheme:
-- config.color_scheme = 'AdventureTime'
config.font = wezterm.font 'Victor Mono'
config.window_background_opacity = 0.9
config.macos_window_background_blur = 10
config.use_fancy_tab_bar = false
config.hide_tab_bar_if_only_one_tab = true
config.window_decorations = "RESIZE"
-- and finally, return the configuration to wezterm
return config