Last active

Embed URL

HTTPS clone URL

SSH clone URL

You can clone with HTTPS or SSH.

Download Gist

My dotfile for Phoenix - (https://github.com/sdegutis/Phoenix).

View .phoenix.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342
/*
▄███████▄ ▄█ █▄ ▄██████▄ ▄████████ ███▄▄▄▄ ▄█ ▀████ ▐████▀
███ ███ ███ ███ ███ ███ ███ ███ ███▀▀▀██▄ ███ ███▌ ████▀
███ ███ ███ ███ ███ ███ ███ █▀ ███ ███ ███▌ ███ ▐███
███ ███ ▄███▄▄▄▄███▄▄ ███ ███ ▄███▄▄▄ ███ ███ ███▌ ▀███▄███▀
▀█████████▀ ▀▀███▀▀▀▀███▀ ███ ███ ▀▀███▀▀▀ ███ ███ ███▌ ████▀██▄
███ ███ ███ ███ ███ ███ █▄ ███ ███ ███ ▐███ ▀███
███ ███ ███ ███ ███ ███ ███ ███ ███ ███ ▄███ ███▄
▄████▀ ███ █▀ ▀██████▀ ██████████ ▀█ █▀ █▀ ████ ███▄
Linell Bonnette - thelinell.com / @thelinell / github.com/Linell
This is my configuration for Phoenix <https://github.com/sdegutis/Phoenix>, a
super-lightweight OS X window manager that can be configured and scripted through
Javascript.
Inital version of this config came from carlo at
<https://github.com/carlo/bash-it/blob/master/dotfiles/.phoenix.js>. Most of my changes
focus on removing things that I did not find useful and adding better support for changing
back and forth between monitors.
*/
 
/*
* Mash (and it's variants) is the key combination used to activate certain commands.
*/
var mash = [ 'cmd', 'alt', 'ctrl' ],
monitorMash = ['cmd', 'shift']
appMash = ['cmd', 'alt'],
nudgePixels = 10,
padding = 4,
previousSizes = {};
 
api.bind('left', monitorMash, leftOneMonitor);
api.bind('right', monitorMash, rightOneMonitor);
 
// ### General key configurations
//
// My space key together with `Ctrl`+`Cmd`+`Alt` is toggling any window
// between full screen and its initial size and position.
api.bind( 'space', mash, function() {
Window.focusedWindow().toggleFullscreen();
});
 
// My keypad keys together with `Ctrl`+`Cmd`+`Alt` are set up to push any
// window to either 25% or 50%. I tried to match the letters to a sort-of
// corresponding position on the screen.
api.bind( 'p', mash, function() {
Window.focusedWindow().toNE();
});
 
api.bind( 'o', mash, function() {
Window.focusedWindow().toN();
});
 
api.bind( 'i', mash, function() {
Window.focusedWindow().toNW();
});
 
api.bind( 'l', mash, function() {
Window.focusedWindow().toE();
});
 
api.bind( 'k', mash, function() {
Window.focusedWindow().toW();
});
 
api.bind( 'm', mash, function() {
Window.focusedWindow().toSE();
});
 
api.bind( ',', mash, function() {
Window.focusedWindow().toS();
});
 
api.bind( 'n', mash, function() {
Window.focusedWindow().toSW();
});
 
api.bind( ';', mash, function() {
Window.focusedWindow().toGrid( 0.25, 0, 0.5, 1 );
});
 
// The cursor keys together with `Ctrl`+`Cmd`+`Alt` make any window occupy any
// half of the screen (N, E, S, W).
api.bind( 'up', mash, function() {
Window.focusedWindow().toN();
});
 
api.bind( 'right', mash, function() {
Window.focusedWindow().toE();
});
 
api.bind( 'down', mash, function() {
Window.focusedWindow().toS();
});
 
api.bind( 'left', mash, function() {
Window.focusedWindow().toW();
});
 
// ### Application Launching Commands
api.bind( 'v', appMash, function() { switchApp('MacVim'); });
 
// Window Size/Position Manipulations {{{
// --------------------------------------------------------------------------------
 
// ### Helper methods `Window`
//
// #### Window#toGrid()
//
// This method can be used to push a window to a certain position and size on
// the screen by using four floats instead of pixel sizes. Examples:
//
// // Window position: top-left; width: 25%, height: 50%
// someWindow.toGrid( 0, 0, 0.25, 0.5 );
//
// // Window position: 30% top, 20% left; width: 50%, height: 35%
// someWindow.toGrid( 0.3, 0.2, 0.5, 0.35 );
//
// The window will be automatically focussed. Returns the window instance.
Window.prototype.toGrid = function( x, y, width, height ) {
var screen = this.screen().frameWithoutDockOrMenu(),
newFrame = {
x: Math.round( x * screen.width ) + padding + screen.x,
y: Math.round( y * screen.height ) + padding + screen.y,
width: Math.round( width * screen.width ) - ( 2 * padding ),
height: Math.round( height * screen.height ) - ( 2 * padding )
};
 
// When setting the `height` to 1, the padding isn't applied at the bottom
// end of the frame. (I guess it's a bug.) Setting the frame to a height
// less than `1` first is a workaround to counter that behaviour.
if ( height === 1 ) {
this.setFrame(
_({}).extend( newFrame, { height: screen.height - 50 })
);
}
 
this.setFrame( newFrame );
this.focusWindow();
 
return this;
};
 
// #### Window#toFullScreen()
//
// Convenience method, doing exactly what it says. Returns the window
// instance.
Window.prototype.toFullScreen = function() {
return this.toGrid( 0, 0, 1, 1 );
};
 
 
// #### Window#toN()
//
// Convenience method, pushing the window to the top half of the screen.
// Returns the window instance.
Window.prototype.toN = function() {
return this.toGrid( 0, 0, 1, 0.5 );
};
 
 
// #### Window#toNE()
//
// Convenience method, pushing the window to the top-right quarter of the
// screen. Returns the window instance.
Window.prototype.toNE = function() {
return this.toGrid( 0.5, 0, 0.5, 0.5 );
};
 
 
// #### Window#toE()
//
// Convenience method, pushing the window to the right half of the screen.
// Returns the window instance.
Window.prototype.toE = function() {
return this.toGrid( 0.5, 0, 0.5, 1 );
};
 
 
// #### Window#toSE()
//
// Convenience method, pushing the window to the bottom-right quarter of the
// screen. Returns the window instance.
Window.prototype.toSE = function() {
return this.toGrid( 0.5, 0.5, 0.5, 0.5 );
};
 
 
// #### Window#toS()
//
// Convenience method, pushing the window to the bottom half of the screen.
// Returns the window instance.
Window.prototype.toS = function() {
return this.toGrid( 0, 0.5, 1, 0.5 );
};
 
 
// #### Window#toSW()
//
// Convenience method, pushing the window to the bottom-left quarter of the
// screen. Returns the window instance.
Window.prototype.toSW = function() {
return this.toGrid( 0, 0.5, 0.5, 0.5 );
};
 
 
// #### Window#toW()
//
// Convenience method, pushing the window to the left half of the screen.
// Returns the window instance.
Window.prototype.toW = function() {
return this.toGrid( 0, 0, 0.5, 1 );
};
 
 
// #### Window#toNW()
//
// Convenience method, pushing the window to the top-left quarter of the
// screen. Returns the window instance.
Window.prototype.toNW = function() {
return this.toGrid( 0, 0, 0.5, 0.5 );
};
 
// #### Window#toggleFullscreen()
//
// Stores the window position and size, then makes the window full screen.
// Should the window be full screen already, its original position and size
// is restored. Returns the window instance.
Window.prototype.toggleFullscreen = function() {
if ( previousSizes[ this ] ) {
this.setFrame( previousSizes[ this ] );
delete previousSizes[ this ];
}
else {
previousSizes[ this ] = this.frame();
this.toFullScreen();
}
 
return this;
};
 
// ### Helper methods `App`
//
// #### App.findByTitle()
//
// Finds the window with a certain title. Expects a string, returns a window
// instance or `undefined`. If there are several windows with the same title,
// the first found instance is returned.
App.findByTitle = function( title ) {
return _( this.runningApps() ).find( function( app ) {
if ( app.title() === title ) {
app.show();
return true;
}
});
};
 
// #### App#findWindowMatchingTitle()
//
// Finds the window whose title matches a regex pattern. Expects a string
// (the pattern), returns a window instance or `undefined`. If there are
// several matching windows, the first found instance is returned.
App.prototype.findWindowMatchingTitle = function( title ) {
var regexp = new RegExp( title );
 
return _( this.visibleWindows() ).find( function( win ) {
return regexp.test( win.title() );
});
};
 
// #### App#findWindowNotMatchingTitle()
//
// Finds the window whose title doesn't match a regex pattern. Expects a
// string (the pattern), returns a window instance or `undefined`. If there
// are several matching windows, the first found instance is returned.
App.prototype.findWindowNotMatchingTitle = function( title ) {
var regexp = new RegExp( title );
 
return _( this.visibleWindows() ).find( function( win ) {
return !regexp.test( win.title() );
});
};
 
// #### App#firstWindow()
//
// Returns the first visible window of the app or `undefined`.
App.prototype.firstWindow = function() {
return this.visibleWindows()[ 0 ];
};
 
// }}}
// Move Windows Between Monitors {{{
// --------------------------------------------------------------------------------
function moveToScreen(win, screen) {
if (!screen) { return; }
 
var frame = win.frame();
var oldScreenRect = win.screen().frameWithoutDockOrMenu();
var newScreenRect = screen.frameWithoutDockOrMenu();
 
var xRatio = newScreenRect.width / oldScreenRect.width;
var yRatio = newScreenRect.height / oldScreenRect.height;
 
win.setFrame({
x: (Math.round(frame.x - oldScreenRect.x) * xRatio) + newScreenRect.x,
y: (Math.round(frame.x - oldScreenRect.y) * yRatio) + newScreenRect.y,
width: Math.round(frame.width * xRatio),
height: Math.round(frame.height * yRatio)
});
}
 
function circularLookup(array, index) {
if (index < 0) { return array[array.length + (index % array.length)]; }
return array[index % array.length];
}
 
function rotateMonitors(offset) {
var win = Window.focusedWindow();
var currentScreen = win.screen();
var screens = [currentScreen];
for (var x = currentScreen.previousScreen(); x != win.screen(); x = x.previousScreen() ) {
screens.push(x);
}
 
screens = _(screens).sortBy(function(s) { return s.frameWithoutDockOrMenu().x });
var currentIndex = _(screens).indexOf(currentScreen);
moveToScreen(win, circularLookup(screens, currentIndex + offset));
}
 
function leftOneMonitor() {
rotateMonitors(-1);
}
 
function rightOneMonitor() {
rotateMonitors(1);
}
 
// }}}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Something went wrong with that request. Please try again.