<commit_before>super = {"cmd", "ctrl", "shift", "alt"}

-- Media volume
hs.hotkey.bind(super, "-", function()
    output = hs.audiodevice.defaultOutputDevice()
    output:setVolume(output:volume() - 1)
end)

hs.hotkey.bind(super, "=", function()
    output = hs.audiodevice.defaultOutputDevice()
    output:setVolume(output:volume() + 1)
end)


-- See https://github.com/Hammerspoon/hammerspoon/issues/595
windowFilter = hs.window.filter.new():setCurrentSpace(true)

-- Window navigation
hs.hotkey.bind(super, "up", function()
    windowFilter:focusWindowNorth(nil, true)
    hs.mouse.setAbsolutePosition(hs.window.focusedWindow():frame().center)
end)

hs.hotkey.bind(super, "down", function()
    windowFilter:focusWindowSouth(nil, true)
    hs.mouse.setAbsolutePosition(hs.window.focusedWindow():frame().center)
end)

hs.hotkey.bind(super, "left", function()
    windowFilter:focusWindowWest()
    hs.mouse.setAbsolutePosition(hs.window.focusedWindow():frame().center)
end)

hs.hotkey.bind(super, "right", function()
    windowFilter:focusWindowEast(nil, true)
    hs.mouse.setAbsolutePosition(hs.window.focusedWindow():frame().center)
end)

hs.hotkey.bind(super, "\\", function()
    nextScreen = hs.window.focusedWindow():screen():next()

    wf = hs.window.filter.new()
    wf:setOverrideFilter({ allowScreens = nextScreen:id() })
    wf:setSortOrder(hs.window.filter.sortByFocusedLast)

    window = wf:getWindows()[1]
    window:focus()
    hs.mouse.setAbsolutePosition(window:frame().center)
end)

-- Window focus toggling
windowHistory = nil

function toggleWindowFocus(windowName)
    return function()
        window = hs.window.filter.new(windowName):getWindows()[1]
        if hs.window.focusedWindow() == window then
            window = windowHistory
        end

        windowHistory = hs.window.focusedWindow()
        hs.mouse.setAbsolutePosition(window:frame().center)
        window:focus()
    end
end

hs.hotkey.bind(super, "s", toggleWindowFocus("Slack"))
hs.hotkey.bind(super, "w", toggleWindowFocus("Terminal"))
hs.hotkey.bind(super, "e", toggleWindowFocus("Google Chrome"))

hs.hotkey.bind(super, "`", function()
    hs.execute("pmset displaysleepnow")
end)<commit_msg>hammerspoon: Better window management bindings<commit_after>super = {"cmd", "ctrl", "shift", "alt"}

-- See https://github.com/Hammerspoon/hammerspoon/issues/595
windowFilter = hs.window.filter.new():setCurrentSpace(true)

-- Window navigation
hs.hotkey.bind(super, "up", function()
    windowFilter:focusWindowNorth(nil, true)
    hs.mouse.setAbsolutePosition(hs.window.focusedWindow():frame().center)
end)

hs.hotkey.bind(super, "down", function()
    windowFilter:focusWindowSouth(nil, true)
    hs.mouse.setAbsolutePosition(hs.window.focusedWindow():frame().center)
end)

hs.hotkey.bind(super, "left", function()
    windowFilter:focusWindowWest()
    hs.mouse.setAbsolutePosition(hs.window.focusedWindow():frame().center)
end)

hs.hotkey.bind(super, "right", function()
    windowFilter:focusWindowEast(nil, true)
    hs.mouse.setAbsolutePosition(hs.window.focusedWindow():frame().center)
end)

hs.hotkey.bind(super, "\\", function()
    nextScreen = hs.window.focusedWindow():screen():next()

    wf = hs.window.filter.new()
    wf:setOverrideFilter({ allowScreens = nextScreen:id() })
    wf:setSortOrder(hs.window.filter.sortByFocusedLast)

    window = wf:getWindows()[1]
    window:focus()
    hs.mouse.setAbsolutePosition(window:frame().center)
end)

-- Window focus toggling
function toggleWindowFocus(windowName)
    return function()
        window = hs.window.filter.new(windowName):getWindows()[1]

        hs.mouse.setAbsolutePosition(window:frame().center)
        window:focus()
    end
end

hs.hotkey.bind(super, "s", toggleWindowFocus("Slack"))
hs.hotkey.bind(super, "d", toggleWindowFocus("Terminal"))
hs.hotkey.bind(super, "f", toggleWindowFocus("Google Chrome"))

-- Terminal sizing
hs.hotkey.bind(super, "t", function()
    window = hs.window.filter.new('Terminal'):getWindows()[1]
    size = window:size()

    size.w = size.w == 845 and 1770 or 845
    window:setSize(size)
end)

hs.hotkey.bind(super, "`", function()
    hs.execute("pmset displaysleepnow")
end)
{'fraction_non_alphanumeric': 0.15842293906810037, 'fraction_numerical': 0.005495818399044205, 'mean_word_length': 4.8545454545454545, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 2, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7305396', 'n_tokens_mistral': 1408, 'n_tokens_neox': 1328, 'n_words': 210}