Skip to content

Commit

Permalink
optimize zshrc, npm, hammerspoon cherry
Browse files Browse the repository at this point in the history
fakeyanss committed Feb 19, 2024
1 parent f0e9275 commit a985932
Showing 7 changed files with 76 additions and 66 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
.DS_Store
private.conf
# node registry auth, authtoken will be saved in .npmrc
.npmrc
software/nvim/bin/*
lazy-lock.json
12 changes: 10 additions & 2 deletions bin/node.sh
Original file line number Diff line number Diff line change
@@ -7,6 +7,7 @@ function setup_node() {
symbol_link_npm
set_n
install_node
install_tool
log_finish "$task"
}

@@ -32,11 +33,12 @@ function set_n() {
if [ $? -ne 0 ]; then
cat >>~/.zshrc <<EOF
# node, npm
export NODE_MIRROR=https://npm.taobao.org/dist/
export PUPPETEER_SKIP_DOWNLOAD='true'
export N_PREFIX="$HOME/.n"
export N_PRESERVE_NPM=1
export PATH="$N_PREFIX/bin:$PATH"
export NPM_CONFIG_LOGLEVEL="error"
export NPM_CONFIG_STRICT_SSL="false"
export PUPPETEER_SKIP_DOWNLOAD="true"
EOF
fi
@@ -48,3 +50,9 @@ function install_node() {
n lts
log_ok
}

function install_tool() {
log_action "install npm packages"
npm install -g nrm
log_ok
}
27 changes: 13 additions & 14 deletions software/hammerspoon/Spoons/Caffeine.spoon/init.lua
Original file line number Diff line number Diff line change
@@ -6,26 +6,25 @@ obj.name = "Caffeine"
local caffeine

function toggleCaffeine()
setCaffeineMenuItem(hs.caffeinate.toggle("displayIdle"))
setCaffeineMenuItem(hs.caffeinate.toggle("displayIdle"))
end

function setCaffeineMenuItem(isIdle)
if isIdle then
caffeine = hs.menubar.new()
-- caffeine:setIcon(hs.image.imageFromPath(os.getenv("HOME") .. "/.hammerspoon/Spoons/Caffeine.spoon/caffeine-on.pdf"))
caffeine:setTitle("☕️")
caffeine:setClickCallback(toggleCaffeine)
if isIdle then
caffeine = hs.menubar.new()
-- caffeine:setIcon(hs.image.imageFromPath(os.getenv("HOME") .. "/.hammerspoon/Spoons/Caffeine.spoon/caffeine-on.pdf"))
caffeine:setTitle("☕️")
caffeine:setClickCallback(toggleCaffeine)

hs.alert.show("Caffeinated!")
else
caffeine:delete()
hs.alert.show("Decaf")
end
hs.alert.show("Caffeinated!")
else
caffeine:delete()
hs.alert.show("Decaf")
end
end

hs.hotkey.bind({"ctrl", "alt"}, "m", toggleCaffeine)
hs.hotkey.bind({ "ctrl", "alt" }, "m", toggleCaffeine)

function obj:start()
end
function obj:start() end

return obj
47 changes: 12 additions & 35 deletions software/hammerspoon/Spoons/Cherry.spoon/init.lua
Original file line number Diff line number Diff line change
@@ -16,12 +16,13 @@ obj.license = "MIT"
obj.homepage = "https://github.com/Hammerspoon/Spoons"

-- Settings
obj.title = "🍒"

-- timer duration in minutes
obj.duration = 15

-- set this to true to always show the menubar item
obj.alwaysShow = true
obj.alwaysShow = false

-- duration in seconds for alert to stay on screen
-- set to 0 to turn off alert completely
@@ -38,33 +39,6 @@ obj.notification = nil
obj.sound = nil
-- obj.sound = hs.sound.getByFile("System/Library/PrivateFrameworks/ScreenReader.framework/Versions/A/Resources/Sounds")

obj.defaultMapping = {
start = { { "cmd", "ctrl", "alt" }, "C" },
}

--- Cherry:bindHotkeys(mapping)
--- Method
--- Binds hotkeys for Cherry
---
--- Parameters:
--- * mapping - A table containing hotkey details for the following items:
--- * start - start the pomodoro timer (Default: cmd-ctrl-alt-C)
function obj:bindHotkeys(mapping)
if self.hotkey then
self.hotkey.delete()
end

if mapping and mapping["start"] then
hs.hotkey.bind(mapping["start"][1], mapping["start"][2], function()
self:start()
end)
else
hs.hotkey.bind(self.defaultMapping["start"][1], self.defaultMapping["start"][2], function()
self:start()
end)
end
end

function obj:init()
self.menu = hs.menubar.new(self.alwaysShow)
self:reset()
@@ -75,12 +49,13 @@ function obj:reset()
{
title = "Start",
fn = function()
self:start()
self:run()
end,
},
}
self.timeLeft = nil
self.menu:setMenu(items)
self.menu:setTitle("🍒")
self.menu:setTitle(obj.title)
self.timerRunning = false
if not self.alwaysShow then
self.menu:removeFromMenuBar()
@@ -90,7 +65,7 @@ end
function obj:updateTimerString()
local minutes = math.floor(self.timeLeft / 60)
local seconds = self.timeLeft - (minutes * 60)
local timerString = string.format("%02d:%02d 🍒", minutes, seconds)
local timerString = string.format("%02d:%02d %s", minutes, seconds, obj.title)
self.menu:setTitle(timerString)
end

@@ -105,7 +80,7 @@ end
--- * None
function obj:popup()
if 0 < self.alertDuration then
hs.alert.show("Done! 🍒", { textSize = self.alertTextSize }, self.alertDuration)
hs.alert.show("Done! " .. obj.title, { textSize = self.alertTextSize }, self.alertDuration)
end
if self.notification then
self.notification:send()
@@ -133,11 +108,11 @@ end
---
--- Returns:
--- * None
function obj:start(resume)
function obj:run(resume)
if not self.menu:isInMenuBar() then
self.menu:returnToMenuBar()
end
if not resume then
if (not resume) or (resume and self.timeLeft == nil) then
self.timeLeft = self.duration * 60
self:updateTimerString()
end
@@ -176,11 +151,13 @@ function obj:pause()
{
title = "Resume",
fn = function()
self:start(true)
self:run(true)
end,
},
}
self.menu:setMenu(items)
end

function obj:start() end

return obj
37 changes: 36 additions & 1 deletion software/hammerspoon/init.lua
Original file line number Diff line number Diff line change
@@ -12,7 +12,7 @@ local spoons = {
WinWin = {},
-- Clipboard = {}, -- raycast clipboard is better
-- EjectMenu = {},
TimeFlow = {},
-- TimeFlow = {},
-- Karabiner = {},
-- InputSourceSwitcher = {},
Cherry = {},
@@ -262,6 +262,41 @@ if spoon.HSaria2 then
end
end

-- Register Cherry
if spoon.Cherry then
spoon.ModalMgr:new("Cherry")
local cmodal = spoon.ModalMgr.modal_list["Cherry"]
-- using escape will make esc not working in Mac OS Monterey, and reboot can fix it
-- cmodal:bind('', 'escape', 'Deactivate resizeM', function() spoon.ModalMgr:deactivate({"resizeM"}) end)
cmodal:bind("", "Q", "Deactivate Cherry Clock", function()
spoon.ModalMgr:deactivate({ "Cherry" })
end)
cmodal:bind("", "tab", "Toggle Cheatsheet", function()
spoon.ModalMgr:toggleCheatsheet()
end)
cmodal:bind("", "S", "Start", function()
spoon.Cherry:run(true)
spoon.ModalMgr:deactivate({ "Cherry" })
end)
cmodal:bind("", "P", "Pause", function()
spoon.Cherry:pause()
spoon.ModalMgr:deactivate({ "Cherry" })
end)
cmodal:bind(" ", "space", "Stop", function()
spoon.Cherry:reset()
spoon.ModalMgr:deactivate({ "Cherry" })
end)
hscherry_keys = hscherry_keys or { "alt", "C" }
if string.len(hscherry_keys[2]) > 0 then
spoon.ModalMgr.supervisor:bind(hscherry_keys[1], hscherry_keys[2], "Cherry Clock", function()
-- Deactivate some modal environments or not before activating a new one
spoon.ModalMgr:deactivateAll()
-- Show an status indicator so we know we're in some modal environment now
spoon.ModalMgr:activate({ "Cherry" }, "#B22222")
end)
end
end

----------------------------------------------------------------------------------------------------
-- Finally we initialize ModalMgr supervisor
spoon.ModalMgr.supervisor:enter()
12 changes: 0 additions & 12 deletions software/node/.npmrc

This file was deleted.

5 changes: 3 additions & 2 deletions software/zsh/.zshrc
Original file line number Diff line number Diff line change
@@ -80,11 +80,12 @@ if (( $+commands[pyenv] )) &>/dev/null; then
fi

# node, npm
export NODE_MIRROR=https://npm.taobao.org/dist/
export PUPPETEER_SKIP_DOWNLOAD='true'
export N_PREFIX="$HOME/.n"
export N_PRESERVE_NPM=1
export PATH="$N_PREFIX/bin:$PATH"
export NPM_CONFIG_LOGLEVEL="error"
export NPM_CONFIG_STRICT_SSL="false"
export PUPPETEER_SKIP_DOWNLOAD="true"

# go
# lazyload goenv and go, export GOPATH and GOROOT

0 comments on commit a985932

Please sign in to comment.