Created
January 28, 2013 15:22
-
-
Save jewel12/4656355 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//********************************** | |
// ヘルパー | |
//********************************** | |
var resize = function (width, height, anchor) { | |
if (typeof anchor === 'undefined') anchor = 'top-left'; | |
return slate.operation('resize', { | |
'width' : width, | |
'height' : height, | |
'anchor' : anchor | |
}); | |
}; | |
var nudge = function (x, y) { | |
return slate.operation('nudge', { | |
'x' : x, | |
'y' : y | |
}); | |
}; | |
var focus = function (app_name) { | |
return slate.operation('focus', {'app' : app_name}); | |
}; | |
var chain = function(actions) { | |
return slate.operation('chain', {'operations' : actions}); | |
}; | |
var half_push = function(direction) { | |
return slate.operation('push', { | |
'direction' : direction, | |
'style' : 'bar-resize:screenSizeX/2' | |
}); | |
}; | |
var half_top = function(direction) { | |
return slate.operation('corner', { | |
'direction' : 'top-'+direction, | |
'width' : 'screenSizeX/2', | |
'height' : 'screenSizeY/2' | |
}); | |
}; | |
var half_bottom = function(direction) { | |
return slate.operation('corner', { | |
'direction' : 'bottom-'+direction, | |
'width' : 'screenSizeX/2', | |
'height' : 'screenSizeY/2' | |
}); | |
}; | |
//********************************** | |
// 基本設定 | |
//********************************** | |
S.configAll({ | |
defaultToCurrentScreen:true, | |
nudgePercentOf:'screenSize', | |
resizePercentOf:'screenSize' | |
}); | |
//********************************** | |
// キーバインドの設定 | |
//********************************** | |
var key_binds = {}; | |
// top-left を基準にリサイズ | |
var pre_top_left = 'alt'; | |
key_binds['right:'+pre_top_left] = resize('+10%', '+0'); | |
key_binds['left:'+pre_top_left] = resize('-10%', '+0'); | |
key_binds['up:'+pre_top_left] = resize('+0', '-10%'); | |
key_binds['down:'+pre_top_left] = resize('+0', '+10%'); | |
// bottom-right を基準にリサイズ | |
var pre_bottom_right = 'ctrl,alt'; | |
key_binds['right:'+pre_bottom_right] = resize('-10%', '+0', 'bottom-right'); | |
key_binds['left:'+pre_bottom_right] = resize('+10%', '+0', 'bottom-right'); | |
key_binds['up:'+pre_bottom_right] = resize('+0', '+10%', 'bottom-right'); | |
key_binds['down:'+pre_bottom_right] = resize('+0', '-10%', 'bottom-right'); | |
// Reload | |
key_binds['r:ctrl,shift'] = slate.operation('relaunch'); | |
// 全画面化 | |
var pre_fullscreen = 'ctrl,alt,shift'; | |
key_binds['up:'+pre_fullscreen] = slate.operation('corner', { | |
'direction' : 'top-left', | |
'width' : 'screenSizeX', | |
'height' : 'screenSizeY' | |
}); | |
// ctrl-alt-shift-right を押す度に右半分に配置、右上、右下とウィンドウが配置される | |
var half_actions = function(direction){ return [half_push(direction), half_top(direction), half_bottom(direction)]; }; | |
var pre_half = 'ctrl,alt,shift'; | |
key_binds['left:'+pre_half] = chain(half_actions('left'));; | |
key_binds['right:'+pre_half] = chain(half_actions('right'));; | |
// ウィンドウの移動 | |
var pre_nudge = 'shift,alt'; | |
key_binds['right:'+pre_nudge] = nudge('+5%', '+0'); | |
key_binds['left:'+pre_nudge] = nudge('-5%', '+0'); | |
key_binds['up:'+pre_nudge] = nudge('+0%', '-10%'); | |
key_binds['down:'+pre_nudge] = nudge('+0%', '+10%'); | |
// Undo | |
key_binds['`:alt'] = slate.operation('undo'); | |
// Forcus | |
key_binds['1:alt'] = focus('Google Chrome'); | |
key_binds['2:alt'] = focus('iTerm'); | |
key_binds['3:alt'] = focus('Emacs'); | |
key_binds['4:alt'] = focus('Skype'); | |
key_binds['5:alt'] = focus('Things'); | |
S.bindAll(key_binds); | |
// フォーカスしているアプリを終了 | |
S.bind('c:alt,shift', function(win) { | |
var pid = win.app().pid(); | |
slate.log('Kill process ' + pid); | |
win.doOperation( | |
slate.operation('shell', { | |
'command' : '/bin/kill '+ pid | |
}) | |
); | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment