Fri, 04 Jun 2021 23:35:16 -0500
Fix up focus-to shortcuts for new hammerspoon
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
1 | hs.window.animationDuration = 0 |
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
2 | |
620 | 3 | -- aliases and partial bindings to make life easier |
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
4 | local bindKey = hs.hotkey.bind |
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
5 | local cmd = hs.fnutils.partial(bindKey, {"cmd"}) |
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
6 | local cmdShift = hs.fnutils.partial(bindKey, {"cmd", "shift"}) |
495
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
7 | local cmdCtrl = hs.fnutils.partial(bindKey, {"cmd", "ctrl"}) |
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
8 | |
907
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
9 | function focusedWindow() |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
10 | return hs.window.focusedWindow() or hs.window.desktop() |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
11 | end |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
12 | |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
13 | function focusTo(direction) |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
14 | local fn = hs.getObjectMetatable('hs.window')['focusWindow' .. direction] |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
15 | return function () |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
16 | fn(focusedWindow(), nil, nil, true) |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
17 | end |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
18 | end |
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
19 | |
620 | 20 | -- and the key bindings |
21 | cmdShift('r', hs.reload) | |
22 | ||
907
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
23 | cmd('k', focusTo('North')) |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
24 | cmd('up', focusTo('North')) |
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
25 | |
907
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
26 | cmd('j', focusTo('South')) |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
27 | cmd('down', focusTo('South')) |
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
28 | |
907
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
29 | cmd('h', focusTo('West')) |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
30 | cmd('left', focusTo('West')) |
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
31 | |
907
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
32 | cmd('l', focusTo('East')) |
df71b104b773
Fix up focus-to shortcuts for new hammerspoon
Meredith Howard <mhoward@roomag.org>
parents:
906
diff
changeset
|
33 | cmd('right', focusTo('East')) |
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
34 | |
495
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
35 | cmdShift('up', function () focusedWindow():maximize() end) |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
36 | |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
37 | cmdShift('down', function () focusedWindow():minimize() end) |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
38 | |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
39 | cmdShift('left', function () focusedWindow():moveToUnit(hs.layout.left50) end) |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
40 | cmdShift('right', function () focusedWindow():moveToUnit(hs.layout.right50) end) |
493
165f65e47a3c
Start a hammerspoon config!
Meredith Howard <mhoward@roomag.org>
parents:
diff
changeset
|
41 | |
495
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
42 | cmdCtrl('left', function () focusedWindow():moveOneScreenWest() end) |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
43 | cmdCtrl('right', function () focusedWindow():moveOneScreenEast() end) |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
44 | |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
45 | cmd('return', function () |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
46 | hs.applescript.applescript([[ |
500
efce0f59ef14
Fix terminal shortcut when iterm not running yet
Meredith Howard <mhoward@roomag.org>
parents:
495
diff
changeset
|
47 | tell application "iTerm" |
705
7520062c1461
okay -actually- get it to focus the new window
Meredith Howard <mhoward@roomag.org>
parents:
648
diff
changeset
|
48 | set newterm to index of (create window with default profile) |
7520062c1461
okay -actually- get it to focus the new window
Meredith Howard <mhoward@roomag.org>
parents:
648
diff
changeset
|
49 | tell application "System Events" to tell process "iTerm2" |
7520062c1461
okay -actually- get it to focus the new window
Meredith Howard <mhoward@roomag.org>
parents:
648
diff
changeset
|
50 | perform action "AXRaise" of window newterm |
7520062c1461
okay -actually- get it to focus the new window
Meredith Howard <mhoward@roomag.org>
parents:
648
diff
changeset
|
51 | end tell |
495
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
52 | end tell |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
53 | ]]) |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
54 | end) |
31fc84fa156c
Fill in some more hotkeys
Meredith Howard <mhoward@roomag.org>
parents:
493
diff
changeset
|
55 | |
734
294238afafac
Actually... hs.execute blocks everything
Meredith Howard <mhoward@roomag.org>
parents:
733
diff
changeset
|
56 | cmdShift('return', function () |
294238afafac
Actually... hs.execute blocks everything
Meredith Howard <mhoward@roomag.org>
parents:
733
diff
changeset
|
57 | os.execute(os.getenv('SHELL')..' -l -i -c "exec mvim"') |
294238afafac
Actually... hs.execute blocks everything
Meredith Howard <mhoward@roomag.org>
parents:
733
diff
changeset
|
58 | end) |
644
42383cfcb729
add cmd-shift-return for quick mvim windows
Meredith Howard <mhoward@roomag.org>
parents:
620
diff
changeset
|
59 | |
500
efce0f59ef14
Fix terminal shortcut when iterm not running yet
Meredith Howard <mhoward@roomag.org>
parents:
495
diff
changeset
|
60 | -- cache window frames before moving? |
efce0f59ef14
Fix terminal shortcut when iterm not running yet
Meredith Howard <mhoward@roomag.org>
parents:
495
diff
changeset
|
61 | -- save cache? |
efce0f59ef14
Fix terminal shortcut when iterm not running yet
Meredith Howard <mhoward@roomag.org>
parents:
495
diff
changeset
|
62 | -- focus by direction is a little strict |
efce0f59ef14
Fix terminal shortcut when iterm not running yet
Meredith Howard <mhoward@roomag.org>
parents:
495
diff
changeset
|
63 |