mirror of
https://github.com/nmasur/dotfiles
synced 2025-07-05 19:40:14 +00:00
Merge branch 'experimental'
This commit is contained in:
23
modules/darwin/alacritty.nix
Normal file
23
modules/darwin/alacritty.nix
Normal file
@ -0,0 +1,23 @@
|
||||
{ config, pkgs, lib, ... }: {
|
||||
|
||||
# MacOS-specific settings for Alacritty
|
||||
home-manager.users.${config.user} = {
|
||||
programs.alacritty.settings = {
|
||||
font.size = lib.mkForce 20.0;
|
||||
shell.program = "${pkgs.fish}/bin/fish";
|
||||
key_bindings = [
|
||||
{
|
||||
key = "F";
|
||||
mods = "Super";
|
||||
action = "ToggleSimpleFullscreen";
|
||||
}
|
||||
{
|
||||
key = "L";
|
||||
mods = "Super";
|
||||
chars = "\\x1F";
|
||||
}
|
||||
];
|
||||
};
|
||||
};
|
||||
|
||||
}
|
15
modules/darwin/default.nix
Normal file
15
modules/darwin/default.nix
Normal file
@ -0,0 +1,15 @@
|
||||
{ ... }: {
|
||||
|
||||
imports = [
|
||||
./alacritty.nix
|
||||
./dotfiles.nix
|
||||
./fonts.nix
|
||||
./hammerspoon.nix
|
||||
./homebrew.nix
|
||||
./system.nix
|
||||
./tmux.nix
|
||||
./user.nix
|
||||
./utilities.nix
|
||||
];
|
||||
|
||||
}
|
28
modules/darwin/dotfiles.nix
Normal file
28
modules/darwin/dotfiles.nix
Normal file
@ -0,0 +1,28 @@
|
||||
{ config, ... }: {
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
programs.fish = {
|
||||
shellAbbrs = {
|
||||
nr = lib.mkForce "rebuild-darwin";
|
||||
nro = lib.mkForce "rebuild-darwin offline";
|
||||
};
|
||||
functions = {
|
||||
rebuild-darwin = {
|
||||
body = ''
|
||||
if test "$argv[1]" = "offline"
|
||||
set option "--option substitute false"
|
||||
end
|
||||
pushd ${config.dotfilesPath}
|
||||
git add --all
|
||||
popd
|
||||
commandline -r "darwin-rebuild switch $option --flake ${config.dotfilesPath}#macbook"
|
||||
commandline -f execute
|
||||
'';
|
||||
};
|
||||
};
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
14
modules/darwin/fonts.nix
Normal file
14
modules/darwin/fonts.nix
Normal file
@ -0,0 +1,14 @@
|
||||
{ config, pkgs, ... }: {
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
home.packages = with pkgs;
|
||||
[ (nerdfonts.override { fonts = [ "FiraCode" ]; }) ];
|
||||
|
||||
programs.alacritty.settings = {
|
||||
font.normal.family = "FiraCode Nerd Font Mono";
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
15
modules/darwin/hammerspoon.nix
Normal file
15
modules/darwin/hammerspoon.nix
Normal file
@ -0,0 +1,15 @@
|
||||
{ config, ... }: {
|
||||
|
||||
# Hammerspoon - MacOS custom automation scripting
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
xdg.configFile.hammerspoon = { source = ./hammerspoon; };
|
||||
};
|
||||
|
||||
homebrew.casks = [ "hammerspoon" ];
|
||||
|
||||
system.activationScripts.hammerspoon.text = ''
|
||||
defaults write org.hammerspoon.Hammerspoon MJConfigFile "~/.config/hammerspoon/init.lua"
|
||||
'';
|
||||
|
||||
}
|
120
modules/darwin/hammerspoon/Spoons/ControlEscape.spoon/init.lua
Normal file
120
modules/darwin/hammerspoon/Spoons/ControlEscape.spoon/init.lua
Normal file
@ -0,0 +1,120 @@
|
||||
--- === ControlEscape ===
|
||||
---
|
||||
--- Adapted very loosely from https://github.com/jasonrudolph/ControlEscape.spoon
|
||||
--- Removed timing/delay; always send Escape as well as Control
|
||||
---
|
||||
--- Make the `control` key more useful: If the `control` key is tapped, treat it
|
||||
--- as the `escape` key. If the `control` key is held down and used in
|
||||
--- combination with another key, then provide the normal `control` key
|
||||
--- behavior.
|
||||
|
||||
local obj={}
|
||||
obj.__index = obj
|
||||
|
||||
-- Metadata
|
||||
obj.name = 'ControlEscape'
|
||||
obj.version = '0.1'
|
||||
obj.author = 'Jason Rudolph <jason@jasonrudolph.com>'
|
||||
obj.homepage = 'https://github.com/jasonrudolph/ControlEscape.spoon'
|
||||
obj.license = 'MIT - https://opensource.org/licenses/MIT'
|
||||
|
||||
function obj:init()
|
||||
self.movements = 0
|
||||
self.sendEscape = false
|
||||
self.lastModifiers = {}
|
||||
|
||||
-- Create an eventtap to run each time the modifier keys change (i.e., each
|
||||
-- time a key like control, shift, option, or command is pressed or released)
|
||||
self.controlTap = hs.eventtap.new({hs.eventtap.event.types.flagsChanged},
|
||||
function(event)
|
||||
local newModifiers = event:getFlags()
|
||||
|
||||
-- If this change to the modifier keys does not involve a *change* to the
|
||||
-- up/down state of the `control` key (i.e., it was up before and it's
|
||||
-- still up, or it was down before and it's still down), then don't take
|
||||
-- any action.
|
||||
if self.lastModifiers['ctrl'] == newModifiers['ctrl'] then
|
||||
return false
|
||||
end
|
||||
|
||||
-- Control was not down but is now
|
||||
if not self.lastModifiers['ctrl'] then
|
||||
|
||||
-- Only prepare to send escape if no other modifier keys are in use
|
||||
self.lastModifiers = newModifiers
|
||||
if (not self.lastModifiers['cmd'] and not self.lastModifiers['alt']) then
|
||||
self.sendEscape = true
|
||||
self.movements = 0
|
||||
end
|
||||
|
||||
-- Control was down and is up, hasn't been blocked by another key, and
|
||||
-- isn't above the movement threshold
|
||||
elseif (self.sendEscape == true and not newModifiers['ctrl'] and self.movements < 30) then
|
||||
|
||||
self.lastModifiers = newModifiers
|
||||
|
||||
-- Allow for shift-escape
|
||||
if newModifiers['shift'] then
|
||||
hs.eventtap.keyStroke({'shift'}, 'escape', 0)
|
||||
else
|
||||
hs.eventtap.keyStroke(newModifiers, 'escape', 0)
|
||||
end
|
||||
self.sendEscape = false
|
||||
self.movements = 0
|
||||
self.numberOfCharacters = 0
|
||||
|
||||
-- Control was down and is up, but isn't ready to send escape
|
||||
else
|
||||
self.lastModifiers = newModifiers
|
||||
|
||||
end
|
||||
end
|
||||
)
|
||||
|
||||
-- If any other key is pressed, don't send escape
|
||||
self.asModifier = hs.eventtap.new({hs.eventtap.event.types.keyDown},
|
||||
function(event)
|
||||
self.sendEscape = false
|
||||
end
|
||||
)
|
||||
|
||||
-- If mouse is moving significantly, don't send escape
|
||||
self.scrolling = hs.eventtap.new({hs.eventtap.event.types.gesture},
|
||||
function(event)
|
||||
local touches = event:getTouches()
|
||||
local i, v = next(touches, nil)
|
||||
while i do
|
||||
if v["phase"] == "moved" then
|
||||
-- Increment the movement counter
|
||||
self.movements = self.movements + 1
|
||||
end
|
||||
i, v = next(touches, i) -- get next index
|
||||
end
|
||||
end
|
||||
)
|
||||
end
|
||||
|
||||
--- ControlEscape:start()
|
||||
--- Method
|
||||
--- Start sending `escape` when `control` is pressed and released in isolation
|
||||
function obj:start()
|
||||
self.controlTap:start()
|
||||
self.asModifier:start()
|
||||
self.scrolling:start()
|
||||
end
|
||||
|
||||
--- ControlEscape:stop()
|
||||
--- Method
|
||||
--- Stop sending `escape` when `control` is pressed and released in isolation
|
||||
function obj:stop()
|
||||
-- Stop monitoring keystrokes
|
||||
self.controlTap:stop()
|
||||
self.asModifier:stop()
|
||||
self.scrolling:stop()
|
||||
|
||||
-- Reset state
|
||||
self.sendEscape = false
|
||||
self.lastModifiers = {}
|
||||
end
|
||||
|
||||
return obj
|
@ -0,0 +1,298 @@
|
||||
/* Credit: https://gist.github.com/lancethomps/a5ac103f334b171f70ce2ff983220b4f */
|
||||
|
||||
function run(input, parameters) {
|
||||
|
||||
const appNames = [];
|
||||
const skipAppNames = [];
|
||||
const verbose = true;
|
||||
|
||||
const scriptName = "close_notifications_applescript";
|
||||
|
||||
const CLEAR_ALL_ACTION = "Clear All";
|
||||
const CLEAR_ALL_ACTION_TOP = "Clear";
|
||||
const CLOSE_ACTION = "Close";
|
||||
|
||||
const notNull = (val) => {
|
||||
return val !== null && val !== undefined;
|
||||
};
|
||||
|
||||
const isNull = (val) => {
|
||||
return !notNull(val);
|
||||
};
|
||||
|
||||
const notNullOrEmpty = (val) => {
|
||||
return notNull(val) && val.length > 0;
|
||||
};
|
||||
|
||||
const isNullOrEmpty = (val) => {
|
||||
return !notNullOrEmpty(val);
|
||||
};
|
||||
|
||||
const isError = (maybeErr) => {
|
||||
return notNull(maybeErr) && (maybeErr instanceof Error || maybeErr.message);
|
||||
};
|
||||
|
||||
const systemVersion = () => {
|
||||
return Application("Finder").version().split(".").map(val => parseInt(val));
|
||||
};
|
||||
|
||||
const systemVersionGreaterThanOrEqualTo = (vers) => {
|
||||
return systemVersion()[0] >= vers;
|
||||
};
|
||||
|
||||
const isBigSurOrGreater = () => {
|
||||
return systemVersionGreaterThanOrEqualTo(11);
|
||||
};
|
||||
|
||||
const V11_OR_GREATER = isBigSurOrGreater();
|
||||
const APP_NAME_MATCHER_ROLE = V11_OR_GREATER ? "AXStaticText" : "AXImage";
|
||||
const hasAppNames = notNullOrEmpty(appNames);
|
||||
const hasSkipAppNames = notNullOrEmpty(skipAppNames);
|
||||
const hasAppNameFilters = hasAppNames || hasSkipAppNames;
|
||||
const appNameForLog = hasAppNames ? ` [${appNames.join(",")}]` : "";
|
||||
|
||||
const logs = [];
|
||||
const log = (message, ...optionalParams) => {
|
||||
let message_with_prefix = `${new Date().toISOString().replace("Z", "").replace("T", " ")} [${scriptName}]${appNameForLog} ${message}`;
|
||||
console.log(message_with_prefix, optionalParams);
|
||||
logs.push(message_with_prefix);
|
||||
};
|
||||
|
||||
const logError = (message, ...optionalParams) => {
|
||||
if (isError(message)) {
|
||||
let err = message;
|
||||
message = `${err}${err.stack ? (" " + err.stack) : ""}`;
|
||||
}
|
||||
log(`ERROR ${message}`, optionalParams);
|
||||
};
|
||||
|
||||
const logErrorVerbose = (message, ...optionalParams) => {
|
||||
if (verbose) {
|
||||
logError(message, optionalParams);
|
||||
}
|
||||
};
|
||||
|
||||
const logVerbose = (message) => {
|
||||
if (verbose) {
|
||||
log(message);
|
||||
}
|
||||
};
|
||||
|
||||
const getLogLines = () => {
|
||||
return logs.join("\n");
|
||||
};
|
||||
|
||||
const getSystemEvents = () => {
|
||||
let systemEvents = Application("System Events");
|
||||
systemEvents.includeStandardAdditions = true;
|
||||
return systemEvents;
|
||||
};
|
||||
|
||||
const getNotificationCenter = () => {
|
||||
try {
|
||||
return getSystemEvents().processes.byName("NotificationCenter");
|
||||
} catch (err) {
|
||||
logError("Could not get NotificationCenter");
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
const getNotificationCenterGroups = (retryOnError = false) => {
|
||||
try {
|
||||
let notificationCenter = getNotificationCenter();
|
||||
if (notificationCenter.windows.length <= 0) {
|
||||
return [];
|
||||
}
|
||||
if (!V11_OR_GREATER) {
|
||||
return notificationCenter.windows();
|
||||
}
|
||||
return notificationCenter.windows[0].uiElements[0].uiElements[0].uiElements();
|
||||
} catch (err) {
|
||||
logError("Could not get NotificationCenter groups");
|
||||
if (retryOnError) {
|
||||
logError(err);
|
||||
log("Retrying getNotificationCenterGroups...");
|
||||
return getNotificationCenterGroups(false);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
const isClearButton = (description, name) => {
|
||||
return description === "button" && name === CLEAR_ALL_ACTION_TOP;
|
||||
};
|
||||
|
||||
const matchesAnyAppNames = (value, checkValues) => {
|
||||
if (isNullOrEmpty(checkValues)) {
|
||||
return false;
|
||||
}
|
||||
let lowerAppName = value.toLowerCase();
|
||||
for (let checkValue of checkValues) {
|
||||
if (lowerAppName === checkValue.toLowerCase()) {
|
||||
return true;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const matchesAppName = (role, value) => {
|
||||
if (role !== APP_NAME_MATCHER_ROLE) {
|
||||
return false;
|
||||
}
|
||||
if (hasAppNames) {
|
||||
return matchesAnyAppNames(value, appNames);
|
||||
}
|
||||
return !matchesAnyAppNames(value, skipAppNames);
|
||||
};
|
||||
|
||||
const notificationGroupMatches = (group) => {
|
||||
try {
|
||||
let description = group.description();
|
||||
if (V11_OR_GREATER && isClearButton(description, group.name())) {
|
||||
return true;
|
||||
}
|
||||
if (V11_OR_GREATER && description !== "group") {
|
||||
return false;
|
||||
}
|
||||
if (!V11_OR_GREATER) {
|
||||
let matchedAppName = !hasAppNameFilters;
|
||||
if (!matchedAppName) {
|
||||
for (let elem of group.uiElements()) {
|
||||
if (matchesAppName(elem.role(), elem.description())) {
|
||||
matchedAppName = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (matchedAppName) {
|
||||
return notNull(findCloseActionV10(group, -1));
|
||||
}
|
||||
return false;
|
||||
}
|
||||
if (!hasAppNameFilters) {
|
||||
return true;
|
||||
}
|
||||
let firstElem = group.uiElements[0];
|
||||
return matchesAppName(firstElem.role(), firstElem.value());
|
||||
} catch (err) {
|
||||
logErrorVerbose(`Caught error while checking window, window is probably closed: ${err}`);
|
||||
logErrorVerbose(err);
|
||||
}
|
||||
return false;
|
||||
};
|
||||
|
||||
const findCloseActionV10 = (group, closedCount) => {
|
||||
try {
|
||||
for (let elem of group.uiElements()) {
|
||||
if (elem.role() === "AXButton" && elem.title() === CLOSE_ACTION) {
|
||||
return elem.actions["AXPress"];
|
||||
}
|
||||
}
|
||||
} catch (err) {
|
||||
logErrorVerbose(`(group_${closedCount}) Caught error while searching for close action, window is probably closed: ${err}`);
|
||||
logErrorVerbose(err);
|
||||
return null;
|
||||
}
|
||||
log("No close action found for notification");
|
||||
return null;
|
||||
};
|
||||
|
||||
const findCloseAction = (group, closedCount) => {
|
||||
try {
|
||||
if (!V11_OR_GREATER) {
|
||||
return findCloseActionV10(group, closedCount);
|
||||
}
|
||||
let checkForPress = isClearButton(group.description(), group.name());
|
||||
let clearAllAction;
|
||||
let closeAction;
|
||||
for (let action of group.actions()) {
|
||||
let description = action.description();
|
||||
if (description === CLEAR_ALL_ACTION) {
|
||||
clearAllAction = action;
|
||||
break;
|
||||
} else if (description === CLOSE_ACTION) {
|
||||
closeAction = action;
|
||||
} else if (checkForPress && description === "press") {
|
||||
clearAllAction = action;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (notNull(clearAllAction)) {
|
||||
return clearAllAction;
|
||||
} else if (notNull(closeAction)) {
|
||||
return closeAction;
|
||||
}
|
||||
} catch (err) {
|
||||
logErrorVerbose(`(group_${closedCount}) Caught error while searching for close action, window is probably closed: ${err}`);
|
||||
logErrorVerbose(err);
|
||||
return null;
|
||||
}
|
||||
log("No close action found for notification");
|
||||
return null;
|
||||
};
|
||||
|
||||
const closeNextGroup = (groups, closedCount) => {
|
||||
try {
|
||||
for (let group of groups) {
|
||||
if (notificationGroupMatches(group)) {
|
||||
let closeAction = findCloseAction(group, closedCount);
|
||||
|
||||
if (notNull(closeAction)) {
|
||||
try {
|
||||
closeAction.perform();
|
||||
return [true, 1];
|
||||
} catch (err) {
|
||||
logErrorVerbose(`(group_${closedCount}) Caught error while performing close action, window is probably closed: ${err}`);
|
||||
logErrorVerbose(err);
|
||||
}
|
||||
}
|
||||
return [true, 0];
|
||||
}
|
||||
}
|
||||
return false;
|
||||
} catch (err) {
|
||||
logError("Could not run closeNextGroup");
|
||||
throw err;
|
||||
}
|
||||
};
|
||||
|
||||
try {
|
||||
let groupsCount = getNotificationCenterGroups(true).filter(group => notificationGroupMatches(group)).length;
|
||||
|
||||
if (groupsCount > 0) {
|
||||
logVerbose(`Closing ${groupsCount}${appNameForLog} notification group${(groupsCount > 1 ? "s" : "")}`);
|
||||
|
||||
let startTime = new Date().getTime();
|
||||
let closedCount = 0;
|
||||
let maybeMore = true;
|
||||
let maxAttempts = 2;
|
||||
let attempts = 1;
|
||||
while (maybeMore && ((new Date().getTime() - startTime) <= (1000 * 30))) {
|
||||
try {
|
||||
let closeResult = closeNextGroup(getNotificationCenterGroups(), closedCount);
|
||||
maybeMore = closeResult[0];
|
||||
if (maybeMore) {
|
||||
closedCount = closedCount + closeResult[1];
|
||||
}
|
||||
} catch (innerErr) {
|
||||
if (maybeMore && closedCount === 0 && attempts < maxAttempts) {
|
||||
log(`Caught an error before anything closed, trying ${maxAttempts - attempts} more time(s).`)
|
||||
attempts++;
|
||||
} else {
|
||||
throw innerErr;
|
||||
}
|
||||
}
|
||||
}
|
||||
} else {
|
||||
throw Error(`No${appNameForLog} notifications found...`);
|
||||
}
|
||||
} catch (err) {
|
||||
logError(err);
|
||||
logError(err.message);
|
||||
getLogLines();
|
||||
throw err;
|
||||
}
|
||||
|
||||
return getLogLines();
|
||||
}
|
@ -0,0 +1,17 @@
|
||||
--- === Dismiss Alerts ===
|
||||
|
||||
local obj = {}
|
||||
obj.__index = obj
|
||||
|
||||
-- Metadata
|
||||
obj.name = "DismissAlerts"
|
||||
obj.version = "0.1"
|
||||
obj.license = "MIT - https://opensource.org/licenses/MIT"
|
||||
|
||||
function obj:init()
|
||||
hs.hotkey.bind({ "cmd", "alt", "ctrl" }, "k", function()
|
||||
hs.osascript.javascriptFromFile("Spoons/DismissAlerts.spoon/close_notifications_applescript.js")
|
||||
end)
|
||||
end
|
||||
|
||||
return obj
|
110
modules/darwin/hammerspoon/Spoons/Launcher.spoon/init.lua
Normal file
110
modules/darwin/hammerspoon/Spoons/Launcher.spoon/init.lua
Normal file
@ -0,0 +1,110 @@
|
||||
--- === Launcher ===
|
||||
|
||||
local obj = {}
|
||||
obj.__index = obj
|
||||
|
||||
-- Metadata
|
||||
obj.name = "Launcher"
|
||||
obj.version = "0.1"
|
||||
obj.license = "MIT - https://opensource.org/licenses/MIT"
|
||||
|
||||
function drawSwitcher()
|
||||
-- Drawing
|
||||
width = hs.screen.mainScreen():fullFrame().w
|
||||
switcherWidth = 500
|
||||
canv = hs.canvas.new({
|
||||
x = width / 2 - switcherWidth / 2,
|
||||
y = 1,
|
||||
h = 3,
|
||||
w = switcherWidth,
|
||||
})
|
||||
canv[#canv + 1] = {
|
||||
action = "build",
|
||||
type = "rectangle",
|
||||
}
|
||||
canv[#canv + 1] = {
|
||||
type = "rectangle",
|
||||
fillColor = { alpha = 1, red = 0.8, green = 0.6, blue = 0.3 },
|
||||
action = "fill",
|
||||
}
|
||||
return canv:show()
|
||||
end
|
||||
|
||||
function obj:init()
|
||||
-- Begin launcher mode
|
||||
if self.launcher == nil then
|
||||
self.launcher = hs.hotkey.modal.new("ctrl", "space")
|
||||
end
|
||||
|
||||
-- Behaviors on enter
|
||||
function self.launcher:entered()
|
||||
-- hs.alert("Entered mode")
|
||||
self.canv = drawSwitcher()
|
||||
end
|
||||
-- Behaviors on exit
|
||||
function self.launcher:exited()
|
||||
-- hs.alert("Exited mode")
|
||||
self.canv:hide()
|
||||
end
|
||||
|
||||
-- Use escape to exit launcher mode
|
||||
self.launcher:bind("", "escape", function()
|
||||
self.launcher:exit()
|
||||
end)
|
||||
|
||||
-- Launcher shortcuts
|
||||
self.launcher:bind("ctrl", "space", function() end)
|
||||
self.launcher:bind("", "space", function()
|
||||
hs.hints.windowHints()
|
||||
self.launcher:exit()
|
||||
end)
|
||||
self.launcher:bind("", "return", function()
|
||||
self:switch("Alacritty.app")
|
||||
end)
|
||||
self.launcher:bind("", "C", function()
|
||||
self:switch("Calendar.app")
|
||||
end)
|
||||
self.launcher:bind("", "D", function()
|
||||
self:switch("Discord.app")
|
||||
end)
|
||||
self.launcher:bind("", "E", function()
|
||||
self:switch("Mail.app")
|
||||
end)
|
||||
self.launcher:bind("", "U", function()
|
||||
self:switch("Music.app")
|
||||
end)
|
||||
self.launcher:bind("", "F", function()
|
||||
self:switch("Firefox.app")
|
||||
end)
|
||||
self.launcher:bind("", "H", function()
|
||||
self:switch("Hammerspoon.app")
|
||||
end)
|
||||
self.launcher:bind("", "G", function()
|
||||
self:switch("Mimestream.app")
|
||||
end)
|
||||
self.launcher:bind("", "M", function()
|
||||
self:switch("Messages.app")
|
||||
end)
|
||||
self.launcher:bind("", "O", function()
|
||||
self:switch("Obsidian.app")
|
||||
end)
|
||||
self.launcher:bind("", "P", function()
|
||||
self:switch("System Preferences.app")
|
||||
end)
|
||||
self.launcher:bind("", "R", function()
|
||||
hs.reload()
|
||||
end)
|
||||
self.launcher:bind("", "S", function()
|
||||
self:switch("Slack.app")
|
||||
end)
|
||||
self.launcher:bind("", "Z", function()
|
||||
self:switch("zoom.us.app")
|
||||
end)
|
||||
end
|
||||
|
||||
function obj:switch(app)
|
||||
hs.application.launchOrFocus(app)
|
||||
self.launcher:exit()
|
||||
end
|
||||
|
||||
return obj
|
40
modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/init.lua
Normal file
40
modules/darwin/hammerspoon/Spoons/MoveWindow.spoon/init.lua
Normal file
@ -0,0 +1,40 @@
|
||||
--- === Move Window ===
|
||||
|
||||
local obj = {}
|
||||
obj.__index = obj
|
||||
|
||||
-- Metadata
|
||||
obj.name = "MoveWindow"
|
||||
obj.version = "0.1"
|
||||
obj.license = "MIT - https://opensource.org/licenses/MIT"
|
||||
|
||||
function obj:init()
|
||||
-- bind hotkey
|
||||
hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "n", function()
|
||||
-- get the focused window
|
||||
local win = hs.window.focusedWindow()
|
||||
-- get the screen where the focused window is displayed, a.k.a. current screen
|
||||
local screen = win:screen()
|
||||
-- local nextScreen = screen:next()
|
||||
-- compute the unitRect of the focused window relative to the current screen
|
||||
-- and move the window to the next screen setting the same unitRect
|
||||
win:moveToScreen(screen:next(), true, true, 0)
|
||||
end)
|
||||
|
||||
hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "b", function()
|
||||
local win = hs.window.focusedWindow()
|
||||
local screen = win:screen()
|
||||
win:moveToScreen(screen:previous(), true, true, 0)
|
||||
end)
|
||||
|
||||
hs.hotkey.bind({ "alt", "ctrl", "cmd" }, "m", function()
|
||||
-- get the focused window
|
||||
local win = hs.window.focusedWindow()
|
||||
-- maximize if possible
|
||||
for i = 1, 8 do
|
||||
win:maximize()
|
||||
end
|
||||
end)
|
||||
end
|
||||
|
||||
return obj
|
4
modules/darwin/hammerspoon/init.lua
Normal file
4
modules/darwin/hammerspoon/init.lua
Normal file
@ -0,0 +1,4 @@
|
||||
hs.loadSpoon("ControlEscape"):start() -- Load Hammerspoon bits from https://github.com/jasonrudolph/ControlEscape.spoon
|
||||
hs.loadSpoon("Launcher"):init()
|
||||
hs.loadSpoon("DismissAlerts"):init()
|
||||
hs.loadSpoon("MoveWindow"):init()
|
51
modules/darwin/homebrew.nix
Normal file
51
modules/darwin/homebrew.nix
Normal file
@ -0,0 +1,51 @@
|
||||
{ config, ... }: {
|
||||
|
||||
# Homebrew - Mac-specific packages that aren't in Nix
|
||||
# Requires Homebrew to be installed (works if you rebuild twice)
|
||||
|
||||
homebrew = {
|
||||
enable = true;
|
||||
autoUpdate = false; # Don't update during rebuild
|
||||
cleanup = "zap"; # Uninstall all programs not declared
|
||||
taps = [
|
||||
"homebrew/cask" # Required for casks
|
||||
"homebrew/cask-drivers" # Used for Logitech G-Hub
|
||||
];
|
||||
brews = [
|
||||
"trash" # Delete files and folders to trash instead of rm
|
||||
];
|
||||
casks = [
|
||||
"firefox" # Firefox packaging on Nix is broken for MacOS
|
||||
"1password" # 1Password packaging on Nix is broken for MacOS
|
||||
"scroll-reverser" # Different scroll style for mouse vs. trackpad
|
||||
"meetingbar" # Show meetings in menu bar
|
||||
"gitify" # Git notifications in menu bar
|
||||
"logitech-g-hub" # Mouse and keyboard management
|
||||
"mimestream" # Gmail client
|
||||
"obsidian" # Obsidian packaging on Nix is not available for MacOS
|
||||
];
|
||||
global.brewfile = true; # Run brew bundle from anywhere
|
||||
global.noLock = true; # Don't save lockfile (since running from anywhere)
|
||||
};
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
home.activation = {
|
||||
|
||||
# Always install homebrew if it doesn't exist
|
||||
installHomeBrew =
|
||||
config.home-manager.users.${config.user}.lib.dag.entryAfter
|
||||
[ "writeBoundary" ] ''
|
||||
if ! xcode-select --version 2>/dev/null; then
|
||||
$DRY_RUN_CMD xcode-select --install
|
||||
fi
|
||||
if ! /usr/local/bin/brew --version 2>/dev/null; then
|
||||
$DRY_RUN_CMD /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
|
||||
fi
|
||||
'';
|
||||
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
8
modules/darwin/networking.nix
Normal file
8
modules/darwin/networking.nix
Normal file
@ -0,0 +1,8 @@
|
||||
{ ... }: {
|
||||
|
||||
networking = {
|
||||
computerName = "MacBook"; # Host name
|
||||
hostName = "MacBook";
|
||||
};
|
||||
|
||||
}
|
175
modules/darwin/system.nix
Normal file
175
modules/darwin/system.nix
Normal file
@ -0,0 +1,175 @@
|
||||
{ ... }: {
|
||||
|
||||
services.nix-daemon.enable = true;
|
||||
|
||||
system = {
|
||||
|
||||
keyboard = {
|
||||
remapCapsLockToControl = true;
|
||||
enableKeyMapping = true; # Allows for skhd
|
||||
};
|
||||
|
||||
defaults = {
|
||||
NSGlobalDomain = {
|
||||
|
||||
# Set to dark mode
|
||||
AppleInterfaceStyle = "Dark";
|
||||
|
||||
# Don't change from dark to light automatically
|
||||
# AppleInterfaceSwitchesAutomatically = false;
|
||||
|
||||
# Enable full keyboard access for all controls (e.g. enable Tab in modal dialogs)
|
||||
AppleKeyboardUIMode = 3;
|
||||
|
||||
# Automatically show and hide the menu bar
|
||||
_HIHideMenuBar = true;
|
||||
|
||||
# Expand save panel by default
|
||||
NSNavPanelExpandedStateForSaveMode = true;
|
||||
|
||||
# Expand print panel by default
|
||||
PMPrintingExpandedStateForPrint = true;
|
||||
|
||||
# Replace press-and-hold with key repeat
|
||||
ApplePressAndHoldEnabled = false;
|
||||
|
||||
# Set a fast key repeat rate
|
||||
KeyRepeat = 2;
|
||||
|
||||
# Shorten delay before key repeat begins
|
||||
InitialKeyRepeat = 12;
|
||||
|
||||
# Save to local disk by default, not iCloud
|
||||
NSDocumentSaveNewDocumentsToCloud = false;
|
||||
|
||||
# Disable autocorrect capitalization
|
||||
NSAutomaticCapitalizationEnabled = false;
|
||||
|
||||
# Disable autocorrect smart dashes
|
||||
NSAutomaticDashSubstitutionEnabled = false;
|
||||
|
||||
# Disable autocorrect adding periods
|
||||
NSAutomaticPeriodSubstitutionEnabled = false;
|
||||
|
||||
# Disable autocorrect smart quotation marks
|
||||
NSAutomaticQuoteSubstitutionEnabled = false;
|
||||
|
||||
# Disable autocorrect spellcheck
|
||||
NSAutomaticSpellingCorrectionEnabled = false;
|
||||
};
|
||||
|
||||
dock = {
|
||||
# Automatically show and hide the dock
|
||||
autohide = true;
|
||||
|
||||
# Add translucency in dock for hidden applications
|
||||
showhidden = true;
|
||||
|
||||
# Enable spring loading on all dock items
|
||||
enable-spring-load-actions-on-all-items = true;
|
||||
|
||||
# Highlight hover effect in dock stack grid view
|
||||
mouse-over-hilite-stack = true;
|
||||
|
||||
mineffect = "genie";
|
||||
orientation = "bottom";
|
||||
show-recents = false;
|
||||
tilesize = 44;
|
||||
};
|
||||
|
||||
finder = {
|
||||
|
||||
# Default Finder window set to column view
|
||||
FXPreferredViewStyle = "clmv";
|
||||
|
||||
# Finder search in current folder by default
|
||||
FXDefaultSearchScope = "SCcf";
|
||||
|
||||
# Disable warning when changing file extension
|
||||
FXEnableExtensionChangeWarning = false;
|
||||
|
||||
# Allow quitting of Finder application
|
||||
QuitMenuItem = true;
|
||||
|
||||
};
|
||||
|
||||
# Disable "Are you sure you want to open" dialog
|
||||
LaunchServices.LSQuarantine = false;
|
||||
|
||||
# Disable trackpad tap to click
|
||||
trackpad.Clicking = false;
|
||||
|
||||
# universalaccess = {
|
||||
|
||||
# # Zoom in with Control + Scroll Wheel
|
||||
# closeViewScrollWheelToggle = true;
|
||||
# closeViewZoomFollowsFocus = true;
|
||||
# };
|
||||
|
||||
# Where to save screenshots
|
||||
screencapture.location = "~/Downloads";
|
||||
|
||||
};
|
||||
|
||||
# Settings that don't have an option in nix-darwin
|
||||
activationScripts.postActivation.text = ''
|
||||
echo "Disable disk image verification"
|
||||
defaults write com.apple.frameworks.diskimages skip-verify -bool true
|
||||
defaults write com.apple.frameworks.diskimages skip-verify-locked -bool true
|
||||
defaults write com.apple.frameworks.diskimages skip-verify-remote -bool true
|
||||
|
||||
echo "Avoid creating .DS_Store files on network volumes"
|
||||
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
|
||||
|
||||
echo "Disable the warning before emptying the Trash"
|
||||
defaults write com.apple.finder WarnOnEmptyTrash -bool false
|
||||
|
||||
echo "Require password immediately after sleep or screen saver begins"
|
||||
defaults write com.apple.screensaver askForPassword -int 1
|
||||
defaults write com.apple.screensaver askForPasswordDelay -int 0
|
||||
|
||||
echo "Show the ~/Library folder"
|
||||
chflags nohidden ~/Library
|
||||
|
||||
echo "Enable dock magnification"
|
||||
defaults write com.apple.dock magnification -bool true
|
||||
|
||||
echo "Set dock magnification size"
|
||||
defaults write com.apple.dock largesize -int 48
|
||||
|
||||
echo "Choose and order dock icons"
|
||||
__dock_item() {
|
||||
printf '%s%s%s%s%s' \
|
||||
'<dict><key>tile-data</key><dict><key>file-data</key><dict>' \
|
||||
'<key>_CFURLString</key><string>' \
|
||||
"$1" \
|
||||
'</string><key>_CFURLStringType</key><integer>0</integer>' \
|
||||
'</dict></dict></dict>'
|
||||
}
|
||||
|
||||
defaults write com.apple.dock persistent-apps -array \
|
||||
"$(__dock_item /Applications/1Password.app)" \
|
||||
"$(__dock_item /Applications/Slack.app)" \
|
||||
"$(__dock_item /System/Applications/Calendar.app)" \
|
||||
"$(__dock_item /Applications/Firefox.app)" \
|
||||
"$(__dock_item /System/Applications/Messages.app)" \
|
||||
"$(__dock_item /System/Applications/Mail.app)" \
|
||||
"$(__dock_item /Applications/Mimestream.app)" \
|
||||
"$(__dock_item /Applications/zoom.us.app)" \
|
||||
"$(__dock_item /Applications/Obsidian.app)" \
|
||||
"$(__dock_item /Applications/Alacritty.app)" \
|
||||
"$(__dock_item /System/Applications/System\ Preferences.app)"
|
||||
|
||||
echo "Allow apps from anywhere"
|
||||
SPCTL=$(spctl --status)
|
||||
if ! [ "$SPCTL" = "assessments disabled" ]
|
||||
then
|
||||
sudo spctl --master-disable
|
||||
fi
|
||||
|
||||
echo "Show the ~/Library folder"
|
||||
chflags nohidden ~/Library
|
||||
'';
|
||||
};
|
||||
|
||||
}
|
125
modules/darwin/tmux.nix
Normal file
125
modules/darwin/tmux.nix
Normal file
@ -0,0 +1,125 @@
|
||||
{ config, pkgs, ... }: {
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
programs.tmux = {
|
||||
enable = true;
|
||||
baseIndex = 1; # Start windows and panes at 1
|
||||
escapeTime = 0; # Wait time after escape is input
|
||||
historyLimit = 100000;
|
||||
keyMode = "vi";
|
||||
newSession = true; # Automatically spawn new session
|
||||
plugins = [ ];
|
||||
resizeAmount = 10;
|
||||
shell = "${pkgs.fish}/bin/fish";
|
||||
terminal = "screen-256color";
|
||||
extraConfig = ''
|
||||
# Horizontal and vertical splits
|
||||
bind \\ split-window -h -c '#{pane_current_path}'
|
||||
bind - split-window -v -c '#{pane_current_path}'
|
||||
|
||||
# Move between panes with vi keys
|
||||
bind h select-pane -L
|
||||
bind j select-pane -D
|
||||
bind K select-pane -U
|
||||
bind l select-pane -R
|
||||
|
||||
# Split out pane
|
||||
bind b break-pane
|
||||
|
||||
# Synchronize panes
|
||||
bind S set-window-option synchronize-panes
|
||||
|
||||
# Copy mode works as Vim
|
||||
bind Escape copy-mode
|
||||
bind k copy-mode
|
||||
bind C-[ copy-mode
|
||||
|
||||
# Use v to trigger selection
|
||||
bind-key -T copy-mode-vi v send-keys -X begin-selection
|
||||
|
||||
# Use y to yank current selection
|
||||
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel
|
||||
|
||||
# Enable mouse mode
|
||||
set -g mouse on
|
||||
|
||||
# Status bar
|
||||
set -g status-interval 60 # Seconds between refreshes
|
||||
set -g renumber-windows on
|
||||
set-option -g status-position bottom
|
||||
|
||||
## COLORSCHEME: gruvbox dark
|
||||
set-option -g status "on"
|
||||
|
||||
# Default statusbar color
|
||||
set-option -g status-style bg=colour237,fg=colour223 # bg=bg1, fg=fg1
|
||||
|
||||
# Default window title colors
|
||||
set-window-option -g window-status-style bg=colour214,fg=colour237 # bg=yellow, fg=bg1
|
||||
|
||||
# Default window with an activity alert
|
||||
set-window-option -g window-status-activity-style bg=colour237,fg=colour248 # bg=bg1, fg=fg3
|
||||
|
||||
# Active window title colors
|
||||
set-window-option -g window-status-current-style bg=red,fg=colour237 # fg=bg1
|
||||
|
||||
# Pane border
|
||||
set-option -g pane-active-border-style fg=colour250 #fg2
|
||||
set-option -g pane-border-style fg=colour237 #bg1
|
||||
|
||||
# Message infos
|
||||
set-option -g message-style bg=colour239,fg=colour223 # bg=bg2, fg=fg1
|
||||
|
||||
# Writing commands inactive
|
||||
set-option -g message-command-style bg=colour239,fg=colour223 # bg=fg3, fg=bg1
|
||||
|
||||
# Pane number display
|
||||
set-option -g display-panes-active-colour colour250 #fg2
|
||||
set-option -g display-panes-colour colour237 #bg1
|
||||
|
||||
# Clock
|
||||
set-window-option -g clock-mode-colour colour109 #blue
|
||||
|
||||
# Bell
|
||||
set-window-option -g window-status-bell-style bg=colour167,fg=colour235 # bg=red, fg=bg
|
||||
|
||||
# Theme settings mixed with colors (unfortunately, but there is no cleaner way)
|
||||
set-option -g status-justify "left"
|
||||
set-option -g status-left-style none
|
||||
set-option -g status-left-length "80"
|
||||
set-option -g status-right-style none
|
||||
set-option -g status-right-length "80"
|
||||
set-window-option -g window-status-separator ""
|
||||
|
||||
set-option -g status-left "#[fg=colour248, bg=colour241] #S #[fg=colour241, bg=colour237, nobold, noitalics, nounderscore]"
|
||||
set-option -g status-right "#[fg=colour239, bg=colour237, nobold, nounderscore, noitalics]#[fg=colour246,bg=colour239] %Y-%m-%d %H:%M #[fg=colour248, bg=colour239, nobold, noitalics, nounderscore]"
|
||||
|
||||
set-window-option -g window-status-current-format "#[fg=colour237, bg=colour214, nobold, noitalics, nounderscore]#[fg=colour239, bg=colour214] #I #[fg=colour239, bg=colour214, bold] #W #[fg=colour214, bg=colour237, nobold, noitalics, nounderscore]"
|
||||
set-window-option -g window-status-format "#[fg=colour237,bg=colour239,noitalics]#[fg=colour223,bg=colour239] #I #[fg=colour223, bg=colour239] #W #[fg=colour239, bg=colour237, noitalics]"
|
||||
'';
|
||||
};
|
||||
|
||||
programs.alacritty.settings = {
|
||||
shell.args = [
|
||||
"--login"
|
||||
"--init-command"
|
||||
"tmux attach-session -t noah || tmux new-session -s noah"
|
||||
];
|
||||
key_bindings = [
|
||||
{
|
||||
key = "H";
|
||||
mods = "Super|Shift";
|
||||
chars = "\\x02p"; # Previous tmux window
|
||||
}
|
||||
{
|
||||
key = "L";
|
||||
mods = "Super|Shift";
|
||||
chars = "\\x02n"; # Next tmux window
|
||||
}
|
||||
];
|
||||
};
|
||||
|
||||
};
|
||||
|
||||
}
|
8
modules/darwin/user.nix
Normal file
8
modules/darwin/user.nix
Normal file
@ -0,0 +1,8 @@
|
||||
{ config, pkgs, lib, ... }: {
|
||||
|
||||
users.users."${config.user}" = { # macOS user
|
||||
home = config.homePath;
|
||||
shell = pkgs.zsh; # Default shell
|
||||
};
|
||||
|
||||
}
|
21
modules/darwin/utilities.nix
Normal file
21
modules/darwin/utilities.nix
Normal file
@ -0,0 +1,21 @@
|
||||
{ config, pkgs, ... }: {
|
||||
|
||||
home-manager.users.${config.user} = {
|
||||
|
||||
home.packages = with pkgs; [
|
||||
visidata # CSV inspector
|
||||
dos2unix # Convert Windows text files
|
||||
inetutils # Includes telnet
|
||||
youtube-dl # Convert web videos
|
||||
pandoc # Convert text documents
|
||||
mpd # TUI slideshows
|
||||
awscli2
|
||||
awslogs
|
||||
kubectl
|
||||
k9s
|
||||
noti # Create notifications programmatically
|
||||
];
|
||||
|
||||
};
|
||||
|
||||
}
|
Reference in New Issue
Block a user