mirror of
https://github.com/kogakure/dotfiles.git
synced 2026-02-04 04:35:29 +00:00
feat(nix): nix and back again
I tried Nix, but it had too many downsides so I removed it. 1. Didn't like that all files are immutable and simple config changes need a complete rebuild. 2. Setting up a new Mac didn't work as smoothly as promised. Not worth the effort. 3. It sucked a lot to always have to type in the password twice on each darwin-rebuild 4. It solves problems I never had.
This commit is contained in:
184
.hammerspoon/functions.lua
Normal file
184
.hammerspoon/functions.lua
Normal file
@@ -0,0 +1,184 @@
|
||||
----------------------
|
||||
-- Helper Functions --
|
||||
----------------------
|
||||
|
||||
-- Get list of screens and refresh that list whenever screens are plugged or unplugged:
|
||||
local screens = hs.screen.allScreens()
|
||||
local screenwatcher = hs.screen.watcher.new(function()
|
||||
screens = hs.screen.allScreens()
|
||||
end)
|
||||
screenwatcher:start()
|
||||
|
||||
-- Move a window a number of pixels in x and y
|
||||
function Nudge(xpos, ypos)
|
||||
local win = hs.window.focusedWindow()
|
||||
local f = win:frame()
|
||||
f.x = f.x + xpos
|
||||
f.y = f.y + ypos
|
||||
win:setFrame(f)
|
||||
end
|
||||
|
||||
-- Resize a window by moving the bottom
|
||||
function Yank(xpixels, ypixels)
|
||||
local win = hs.window.focusedWindow()
|
||||
local f = win:frame()
|
||||
|
||||
f.w = f.w + xpixels
|
||||
f.h = f.h + ypixels
|
||||
win:setFrame(f)
|
||||
end
|
||||
|
||||
-- Resize window for chunk of screen.
|
||||
-- For x and y: use 0 to expand fully in that dimension, 0.5 to expand halfway
|
||||
-- For w and h: use 1 for full, 0.5 for half
|
||||
function Push(x, y, w, h)
|
||||
local win = hs.window.focusedWindow()
|
||||
local f = win:frame()
|
||||
local screen = win:screen()
|
||||
local max = screen:frame()
|
||||
|
||||
f.x = max.x + (max.w * x)
|
||||
f.y = max.y + (max.h * y)
|
||||
f.w = max.w * w
|
||||
f.h = max.h * h
|
||||
win:setFrame(f)
|
||||
end
|
||||
|
||||
-- Move to monitor x. Checks to make sure monitor exists, if not moves to last monitor that exists
|
||||
function MoveToMonitor(x)
|
||||
local win = hs.window.focusedWindow()
|
||||
local newScreen = nil
|
||||
while not newScreen do
|
||||
newScreen = screens[x]
|
||||
x = x - 1
|
||||
end
|
||||
|
||||
win:moveToScreen(newScreen)
|
||||
end
|
||||
|
||||
-- Move to next screen
|
||||
local function moveToNextScreen(win)
|
||||
win = win or window.focusedWindow()
|
||||
win:moveToScreen(win:screen():next())
|
||||
end
|
||||
|
||||
-- Move to previous screen
|
||||
local function moveToPreviousScreen(win)
|
||||
win = win or window.focusedWindow()
|
||||
win:moveToScreen(win:screen():previous())
|
||||
end
|
||||
|
||||
-- This places a red circle around the mouse pointer
|
||||
local mouseCircle = nil
|
||||
local mouseCircleTimer = nil
|
||||
|
||||
function MouseHighlight()
|
||||
-- Delete an existing highlight if it exists
|
||||
if mouseCircle then
|
||||
mouseCircle:delete()
|
||||
if mouseCircleTimer then
|
||||
mouseCircleTimer:stop()
|
||||
end
|
||||
end
|
||||
-- Get the current co-ordinates of the mouse pointer
|
||||
Mousepoint = hs.mouse.get()
|
||||
-- Prepare a big red circle around the mouse pointer
|
||||
mouseCircle = hs.drawing.circle(hs.geometry.rect(Mousepoint.x - 40, Mousepoint.y - 40, 80, 80))
|
||||
mouseCircle:setStrokeColor({ ["red"] = 1, ["blue"] = 0, ["green"] = 0, ["alpha"] = 1 })
|
||||
mouseCircle:setFill(false)
|
||||
mouseCircle:setStrokeWidth(5)
|
||||
mouseCircle:show()
|
||||
|
||||
-- Set a timer to delete the circle after 3 seconds
|
||||
mouseCircleTimer = hs.timer.doAfter(2, function()
|
||||
mouseCircle:delete()
|
||||
end)
|
||||
end
|
||||
|
||||
-- Get all valid windows
|
||||
function GetAllValidWindows()
|
||||
local allWindows = hs.window.allWindows()
|
||||
local windows = {}
|
||||
local index = 1
|
||||
for i = 1, #allWindows do
|
||||
local w = allWindows[i]
|
||||
if w:screen() then
|
||||
windows[index] = w
|
||||
index = index + 1
|
||||
end
|
||||
end
|
||||
return windows
|
||||
end
|
||||
|
||||
-- Launch application or toggle it
|
||||
function launchToggleApplication(applicationName)
|
||||
local app = hs.application.find(applicationName)
|
||||
|
||||
if app then
|
||||
local appWindows = app:visibleWindows()
|
||||
|
||||
if #appWindows > 0 then
|
||||
local focusedWindow = app:focusedWindow()
|
||||
|
||||
if focusedWindow then
|
||||
if app:isHidden() then
|
||||
app:unhide()
|
||||
else
|
||||
HideApplicationWithAppleScript(app)
|
||||
end
|
||||
else
|
||||
ShowApplicationWithAppleScript(app)
|
||||
end
|
||||
else
|
||||
app:activate()
|
||||
end
|
||||
else
|
||||
hs.application.launchOrFocus(applicationName)
|
||||
end
|
||||
end
|
||||
|
||||
-- Hide application with AppleScript
|
||||
function HideApplicationWithAppleScript(app)
|
||||
local appName = app:name()
|
||||
local hideScript = [[
|
||||
tell application "Finder"
|
||||
set visible of process "%s" to false
|
||||
end tell
|
||||
]]
|
||||
local formattedScript = string.format(hideScript, appName)
|
||||
hs.osascript.applescript(formattedScript)
|
||||
end
|
||||
|
||||
-- Show application with AppleScript
|
||||
function ShowApplicationWithAppleScript(app)
|
||||
local appName = app:name()
|
||||
local showScript = [[
|
||||
tell application "Finder"
|
||||
set visible of process "%s" to true
|
||||
end tell
|
||||
]]
|
||||
local formattedScript = string.format(showScript, appName)
|
||||
hs.osascript.applescript(formattedScript)
|
||||
end
|
||||
|
||||
function Yabai(commands)
|
||||
for _, cmd in ipairs(commands) do
|
||||
os.execute("/opt/homebrew/bin/yabai -m " .. cmd)
|
||||
end
|
||||
end
|
||||
|
||||
-- Auto Reload Config
|
||||
function ReloadConfig(files)
|
||||
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
|
||||
|
||||
hs.pathwatcher.new(os.getenv("HOME") .. "/.hammerspoon/", ReloadConfig):start()
|
||||
hs.alert.show("Hammerspoon")
|
||||
Reference in New Issue
Block a user