Skip to content

Instantly share code, notes, and snippets.

@clickysteve
Forked from prenagha/init.lua
Last active December 9, 2022 08:18
Show Gist options
  • Save clickysteve/e13a11b8fc9c963c08b3109d95bbacc5 to your computer and use it in GitHub Desktop.
Save clickysteve/e13a11b8fc9c963c08b3109d95bbacc5 to your computer and use it in GitHub Desktop.

Revisions

  1. clickysteve revised this gist Oct 28, 2016. 1 changed file with 6 additions and 4 deletions.
    10 changes: 6 additions & 4 deletions init.lua
    Original file line number Diff line number Diff line change
    @@ -1,11 +1,13 @@
    -- My own config file to get the Hyper Key working again with my current setup.
    -- Big Hat-Tips to https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907 and https://gist.github.com/prenagha/1c28f71cb4d52b3133a4bff1b3849c3e for writing the code that I just tweaked!
    -- All credit goes to @prenagha and @ttscoff for their awesome original code that I tweaked for my own devices.
    -- Credit 1: https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907
    -- Credit 2: https://gist.github.com/prenagha/1c28f71cb4d52b3133a4bff1b3849c3e

    -- A global variable for the sub-key Hyper Mode

    k = hs.hotkey.modal.new({}, 'F17')

    -- Hyper+key for all the below are setup somewhere. Usually Keyboard Maestro or similar. Alfred doesn't handle them very well, so will set up separate bindings for individual apps below.
    -- Hyper-key for all the below are setup somewhere... Usually Keyboard Maestro or similar. Alfred doesn't handle them very well, so will set up separate bindings for individual apps below.

    hyperBindings = {'c','m','a','b','d','e','f','g','h','i','j','k','l','m','n','p','q','r','t','1','2','3','4','5','6','7','8','9','0','d','g','s','f','TAB','v','b','O','-','s'}

    @@ -23,7 +25,7 @@ launch = function(appname)
    k.triggered = true
    end

    -- Single keybinding for app launch
    -- Keybinding for specific single apps.

    singleapps = {
    {'o', '1Password 6'},
    @@ -54,7 +56,7 @@ end

    f19 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18)

    -- Reload config when any lua file in config directory changes
    -- Reload config when any lua file in config directory changes, to save having to manually reload.

    function reloadConfig(files)
    doReload = false
  2. clickysteve revised this gist Oct 28, 2016. No changes.
  3. clickysteve revised this gist Oct 28, 2016. 1 changed file with 13 additions and 4 deletions.
    17 changes: 13 additions & 4 deletions init.lua
    Original file line number Diff line number Diff line change
    @@ -1,9 +1,12 @@
    -- My own config file to get the Hyper Key working again with my current setup.
    -- Big Hat-Tips to https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907 and https://gist.github.com/prenagha/1c28f71cb4d52b3133a4bff1b3849c3e for writing the code that I just tweaked!

    -- A global variable for the sub-key Hyper Mode

    k = hs.hotkey.modal.new({}, 'F17')

    -- Hyper+key for all the below are setup somewhere
    -- The handler already exists, usually in Keyboard Maestro
    -- we just have to get the right keystroke sent
    -- Hyper+key for all the below are setup somewhere. Usually Keyboard Maestro or similar. Alfred doesn't handle them very well, so will set up separate bindings for individual apps below.

    hyperBindings = {'c','m','a','b','d','e','f','g','h','i','j','k','l','m','n','p','q','r','t','1','2','3','4','5','6','7','8','9','0','d','g','s','f','TAB','v','b','O','-','s'}

    for i,key in ipairs(hyperBindings) do
    @@ -12,14 +15,16 @@ for i,key in ipairs(hyperBindings) do
    end)
    end

    --
    -- Code to launch single apps that Alfred used to handle.
    -- Hat-Tip: https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907

    launch = function(appname)
    hs.application.launchOrFocus(appname)
    k.triggered = true
    end

    -- Single keybinding for app launch

    singleapps = {
    {'o', '1Password 6'},
    }
    @@ -29,13 +34,15 @@ for i, app in ipairs(singleapps) do
    end

    -- Enter Hyper Mode when F18 is pressed

    pressedF18 = function()
    k.triggered = false
    k:enter()
    end

    -- Leave Hyper Mode when F18 is pressed,
    -- send ESCAPE if no other keys are pressed.

    releasedF18 = function()
    k:exit()
    if not k.triggered then
    @@ -44,9 +51,11 @@ releasedF18 = function()
    end

    -- Bind the Hyper key

    f19 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18)

    -- Reload config when any lua file in config directory changes

    function reloadConfig(files)
    doReload = false
    for _,file in pairs(files) do
  4. clickysteve revised this gist Oct 28, 2016. 1 changed file with 23 additions and 28 deletions.
    51 changes: 23 additions & 28 deletions init.lua
    Original file line number Diff line number Diff line change
    @@ -1,55 +1,50 @@

    -- hattip https://github.com/lodestone/hyper-hacks
    -- hattip https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907

    -- A global variable for the sub-key Hyper Mode
    k = hs.hotkey.modal.new({}, 'F18')
    k = hs.hotkey.modal.new({}, 'F17')

    -- Hyper+key for all the below are setup somewhere
    -- The handler already exists, usually in Keyboard Maestro
    -- we just have to get the right keystroke sent
    hyperBindings = {'c','m','a','r','d','g','s','f','TAB','v','b'}
    hyperBindings = {'c','m','a','b','d','e','f','g','h','i','j','k','l','m','n','p','q','r','t','1','2','3','4','5','6','7','8','9','0','d','g','s','f','TAB','v','b','O','-','s'}

    for i,key in ipairs(hyperBindings) do
    k:bind({}, key, nil, function() hs.eventtap.keyStroke({'cmd','alt','shift','ctrl'}, key)
    k.triggered = true
    end)
    end

    -- Enter Hyper Mode when F19 (left control) is pressed
    pressedF19 = function()
    --

    launch = function(appname)
    hs.application.launchOrFocus(appname)
    k.triggered = true
    end

    -- Single keybinding for app launch
    singleapps = {
    {'o', '1Password 6'},
    }

    for i, app in ipairs(singleapps) do
    k:bind({}, app[1], function() launch(app[2]); k:exit(); end)
    end

    -- Enter Hyper Mode when F18 is pressed
    pressedF18 = function()
    k.triggered = false
    k:enter()
    end

    -- Leave Hyper Mode when F19 (left control) is pressed,
    -- Leave Hyper Mode when F18 is pressed,
    -- send ESCAPE if no other keys are pressed.
    releasedF19 = function()
    releasedF18 = function()
    k:exit()
    if not k.triggered then
    hs.eventtap.keyStroke({}, 'ESCAPE')
    end
    end

    -- Bind the Hyper key
    f19 = hs.hotkey.bind({}, 'F19', pressedF19, releasedF19)

    -- vi cursor movement commands
    movements = {
    { 'h', {}, 'LEFT'},
    { 'j', {}, 'DOWN'},
    { 'k', {}, 'UP'},
    { 'l', {}, 'RIGHT'},
    { '0', {'cmd'}, 'LEFT'}, -- beginning of line
    { '4', {'cmd'}, 'RIGHT'}, -- end of line
    { 'b', {'alt'}, 'LEFT'}, -- back word
    { 'w', {'alt'}, 'RIGHT'}, -- forward word
    }
    for i,bnd in ipairs(movements) do
    hs.hotkey.bind({'ctrl'}, bnd[1], function()
    hs.eventtap.keyStroke(bnd[2],bnd[3])
    end)
    end
    f19 = hs.hotkey.bind({}, 'F18', pressedF18, releasedF18)

    -- Reload config when any lua file in config directory changes
    function reloadConfig(files)
  5. @prenagha prenagha created this gist Sep 30, 2016.
    67 changes: 67 additions & 0 deletions init.lua
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,67 @@

    -- hattip https://github.com/lodestone/hyper-hacks
    -- hattip https://gist.github.com/ttscoff/cce98a711b5476166792d5e6f1ac5907

    -- A global variable for the sub-key Hyper Mode
    k = hs.hotkey.modal.new({}, 'F18')

    -- Hyper+key for all the below are setup somewhere
    -- The handler already exists, usually in Keyboard Maestro
    -- we just have to get the right keystroke sent
    hyperBindings = {'c','m','a','r','d','g','s','f','TAB','v','b'}

    for i,key in ipairs(hyperBindings) do
    k:bind({}, key, nil, function() hs.eventtap.keyStroke({'cmd','alt','shift','ctrl'}, key)
    k.triggered = true
    end)
    end

    -- Enter Hyper Mode when F19 (left control) is pressed
    pressedF19 = function()
    k.triggered = false
    k:enter()
    end

    -- Leave Hyper Mode when F19 (left control) is pressed,
    -- send ESCAPE if no other keys are pressed.
    releasedF19 = function()
    k:exit()
    if not k.triggered then
    hs.eventtap.keyStroke({}, 'ESCAPE')
    end
    end

    -- Bind the Hyper key
    f19 = hs.hotkey.bind({}, 'F19', pressedF19, releasedF19)

    -- vi cursor movement commands
    movements = {
    { 'h', {}, 'LEFT'},
    { 'j', {}, 'DOWN'},
    { 'k', {}, 'UP'},
    { 'l', {}, 'RIGHT'},
    { '0', {'cmd'}, 'LEFT'}, -- beginning of line
    { '4', {'cmd'}, 'RIGHT'}, -- end of line
    { 'b', {'alt'}, 'LEFT'}, -- back word
    { 'w', {'alt'}, 'RIGHT'}, -- forward word
    }
    for i,bnd in ipairs(movements) do
    hs.hotkey.bind({'ctrl'}, bnd[1], function()
    hs.eventtap.keyStroke(bnd[2],bnd[3])
    end)
    end

    -- Reload config when any lua file in config directory changes
    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
    local myWatcher = hs.pathwatcher.new(os.getenv('HOME') .. '/.hammerspoon/', reloadConfig):start()
    hs.alert.show('Config loaded')