Skip to content

Instantly share code, notes, and snippets.

@truebit
Forked from programus/alacritty.yml
Last active April 9, 2024 12:30
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save truebit/31396bb2f48c75285d724c9e9e037bcd to your computer and use it in GitHub Desktop.
Save truebit/31396bb2f48c75285d724c9e9e037bcd to your computer and use it in GitHub Desktop.
pull down from top alacritty (like iTerm2)
window:
# Window dimensions (changes require restart)
#
# Number of lines/columns (not pixels) in the terminal. The number of columns
# must be at least `2`, while using a value of `0` for columns and lines will
# fall back to the window manager's recommended size.
dimensions:
columns: 500
lines: 30
# Window position (changes require restart)
#
# Specified in number of pixels.
# If the position is not set, the window manager will handle the placement.
position:
x: 0
y: 0
# Window padding (changes require restart)
#
# Blank space added around the window in pixels. This padding is scaled
# by DPI and the specified value is always added at both opposing sides.
#padding:
# x: 0
# y: 0
# Spread additional padding evenly around the terminal content.
#dynamic_padding: false
# Window decorations
#
# Values for `decorations`:
# - full: Borders and title bar
# - none: Neither borders nor title bar
#
# Values for `decorations` (macOS only):
# - transparent: Title bar, transparent background and title bar buttons
# - buttonless: Title bar, transparent background and no title bar buttons
decorations: none
key_bindings:
- { key: Return, mods: Command, action: ToggleSimpleFullscreen }
local spaces = require("hs.spaces") -- https://github.com/asmagill/hs._asm.spaces
-- Switch alacritty
hs.hotkey.bind({'command'}, 'escape', function ()
local BUNDLE_ID = 'org.alacritty' -- more accurate to avoid mismatching on browser titles
function moveWindow(alacritty, space, mainScreen)
-- move to main space
local win = nil
while win == nil do
win = alacritty:mainWindow()
end
print("win="..tostring(win))
print("space="..tostring(space))
print("screen="..tostring(win:screen()))
print("mainScr="..tostring(mainScreen))
if win:isFullScreen() then
hs.eventtap.keyStroke('cmd', 'return', 0, alacritty)
end
winFrame = win:frame()
scrFrame = mainScreen:fullFrame()
winFrame.w = scrFrame.w
winFrame.y = scrFrame.y
winFrame.x = scrFrame.x
print("winFrame="..tostring(winFrame))
win:setFrame(winFrame, 0)
print("win:frame=" .. tostring(win:frame()))
spaces.moveWindowToSpace(win, space)
if win:isFullScreen() then
hs.eventtap.keyStroke('cmd', 'return', 0, alacritty)
end
win:focus()
end
local alacritty = hs.application.get(BUNDLE_ID)
if alacritty ~= nil and alacritty:isFrontmost() then
alacritty:hide()
else
local space = spaces.activeSpaceOnScreen()
local mainScreen = hs.screen.mainScreen()
if alacritty == nil and hs.application.launchOrFocusByBundleID(BUNDLE_ID) then
local appWatcher = nil
print('create app watcher')
appWatcher = hs.application.watcher.new(function(name, event, app)
print('name='..name)
print('event='..event)
if event == hs.application.watcher.launched and app:bundleID() == BUNDLE_ID then
app:hide()
moveWindow(app, space, mainScreen)
print("stop watcher")
appWatcher:stop()
end
end)
print('start watcher')
appWatcher:start()
end
if alacritty ~= nil then
moveWindow(alacritty, space, mainScreen)
end
end
end)
@truebit
Copy link
Author

truebit commented Oct 19, 2023

  • supports latest Hammerspoon Version 0.9.100(6815) with built-in hs.spaces modules;
  • replace application locating method from 'app name' to 'bundle id', as hs.application.find function would also return true when browser titles containing "alacritty" word

@sksundram
Copy link

What key combinations should I press to enable quake mode?

@truebit
Copy link
Author

truebit commented Feb 16, 2024

What key combinations should I press to enable quake mode?

This snippet is only tested and intended for Mac OS X, not Linux.

@sksundram
Copy link

What key combinations should I press to enable quake mode?

This snippet is only tested and intended for Mac OS X, not Linux.

I am talking about macOS. What's the key combination?

@zjr
Copy link

zjr commented Feb 23, 2024

@sksundram the key combination is command + escape, you can find it on the fourth line hs.hotkey.bind({'command'}, 'escape', function ().

@zjr
Copy link

zjr commented Feb 23, 2024

@truebit do you happen know how I could get this to come out of the right side rather than the top? I'm digging into Hammerspoon's docs but there's a lot to go through and it's all new to me, so a point in the right direction would be very appreciated.

@zjr
Copy link

zjr commented Feb 23, 2024

After remembering that Spaces are Workspaces/Desktop this was much less confusing :-) I needed to be looking at setFrame.

In case anyone interested comes across this, I did this:

    local screen = win:screen();
    local max = screen:frame();

    winFrame.x = max.x + (max.w / 3 * 2)
    winFrame.y = max.y
    winFrame.w = max.w / 3
    winFrame.h = max.h

    print("winFrame="..tostring(winFrame))
    win:setFrame(winFrame, 0)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment