Posts in category “Essays”

Slash Your Zsh Startup Time on macOS: Replacing NVM with FNM and Autojump with Zoxide

Is opening a new terminal window or tab feeling sluggish? Do you tap your fingers waiting for your Zsh prompt to appear? If you're using popular tools like NVM (Node Version Manager) and Autojump on macOS, they might be the culprits behind that frustrating delay.

Recently, I noticed my own Zsh startup taking several seconds. After some investigation, the primary offenders were NVM's initialization script and, surprisingly, Autojump's sourcing process. The good news? There are blazing-fast, modern alternatives written in Rust: FNM (Fast Node Manager) and Zoxide.

This post will guide you through diagnosing your Zsh startup time and replacing NVM and Autojump with their speedier counterparts. Let's reclaim those lost seconds!

Step 1: Diagnose the Delay (Confirming the Culprits)

Before replacing anything, let's confirm what's slow. While Zsh's built-in zprof is useful for profiling Zsh functions, it sometimes doesn't accurately capture time spent running external commands or sourcing external scripts during startup. We'll use the simple time command:

  1. Baseline Zsh Time: How fast does Zsh start without your config?

    time zsh -f -i -c exit
    

    (-f skips .zshrc, -i simulates interactive, -c exit exits immediately). Expect this to be very fast (e.g., ~0.1 seconds).

  2. Time Potential Offenders: Check the initialization time of suspects like NVM and Autojump. (Replace paths with your actual ones).

    # Time NVM init (if you were using it) - find the source line in your .zshrc
    # Example: time zsh -f -c '[ -s "$HOME/.nvm/nvm.sh" ] && . "$HOME/.nvm/nvm.sh"'
    
    # Time Autojump init (find the source line in your .zshrc)
    # Common paths: ~/.local/share/autojump/autojump.sh or ~/Library/autojump/autojump.sh
    # Or the one often installed by Homebrew: /usr/local/etc/profile.d/autojump.sh or /opt/homebrew/etc/profile.d/autojump.sh
    time zsh -f -c '[ -f /path/to/your/autojump.sh ] && . /path/to/your/autojump.sh'
    

In my case, the Autojump sourcing took over 2 seconds, and NVM (before I removed it) was also notoriously slow. If you see significant times here (anything over a few tenths of a second adds up), replacing them is worthwhile.

Step 2: Replace NVM with FNM

FNM is significantly faster than the shell-script-based NVM.

  1. Remove NVM Config: Open your ~/.zshrc file. Find and delete or comment out the lines that load NVM. They typically look like:

    # Example lines to remove:
    # export NVM_DIR="$HOME/.nvm"
    # [ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh"
    # [ -s "$NVM_DIR/bash_completion" ] && \. "$NVM_DIR/bash_completion"
    # Or lines sourcing from /usr/local/opt/nvm or /opt/homebrew/opt/nvm
    
  2. Install FNM: The easiest way on macOS is via Homebrew:

    brew install fnm
    
  3. Configure FNM: Add the following line to the end of your ~/.zshrc:

    # Add this for FNM initialization
    eval "$(fnm env --use-on-cd)"
    
    • --use-on-cd: This magic flag tells FNM to automatically switch Node versions when you cd into a directory containing a .nvmrc or .node-version file.
  4. Restart Your Shell: Close and reopen your terminal, or run source ~/.zshrc.

  5. Install Node Versions: FNM manages its own installs.

    • Install latest LTS: fnm install --lts
    • Install specific version: fnm install 18
    • List installed: fnm ls
    • Set default: fnm default <version> (e.g., fnm default lts)
    • Use in current shell: fnm use <version>

Step 3: Replace Autojump with Zoxide

Zoxide is a super-fast reimplementation of autojump/z/fasd.

  1. Remove Autojump Config: Open your ~/.zshrc. Find and delete or comment out the line that sources autojump.sh. It looks like:

    # Example line to remove:
    # [ -f /path/to/your/autojump.sh ] && . /path/to/your/autojump.sh
    
  2. Install Zoxide: Again, Homebrew is simple:

    brew install zoxide
    
  3. Configure Zoxide: Add the following line to the end of your ~/.zshrc:

    # Add this for Zoxide initialization
    eval "$(zoxide init zsh)"
    
  4. Understand the Command Change: Zoxide uses z by default, not j.

    • To jump: z part_of_dir_name (e.g., z project)
  5. (Optional) Keep Using j: If you prefer j, modify the init line:

    # Use 'j' instead of 'z' for Zoxide
    eval "$(zoxide init zsh --cmd j)"
    

    Restart your shell after changing this.

  6. Import Autojump History: Don't lose your navigation history!

    • Find your autojump.txt file. Common locations are ~/.local/share/autojump/autojump.txt or (as in my case) ~/Library/autojump/autojump.txt. Use ls or find ~ -name autojump.txt to locate yours.

    • Run the import command (replace the path with your actual path):

      zoxide import --from autojump /path/to/your/autojump.txt
      

      Example: zoxide import --from autojump ~/Library/autojump/autojump.txt

  7. Restart Your Shell: Close and reopen your terminal, or run source ~/.zshrc.

Step 4: Enjoy the Speed!

Now, open a new terminal tab or window. You should feel a significant difference – that multi-second delay should be gone, replaced by a near-instantaneous prompt!

You can even run time zsh -i -c exit again (note: this won't load .zshrc, so it tests the core Zsh plus anything in global configs; simply opening a new tab is the best "feel" test) to measure the difference, though the real proof is the absence of that annoying wait.

Step 5: Clean Up Old Files (Optional but Recommended)

Once you are completely confident that FNM and Zoxide are working correctly and you've imported your data, you can remove the old files and directories to free up space and prevent potential future conflicts.

Warning: The rm -rf command permanently deletes files and directories. Double-check the paths carefully before running these commands!

  1. Remove NVM Directory: This directory contains all the Node versions NVM managed.

    # Double-check this is the correct path for your NVM installation!
    rm -rf ~/.nvm
    
  2. Remove Autojump Data Directory: This contains the old database and any other files Autojump used. Check which location yours was in (from Step 3, part 6).

    • If it was in ~/.local/share/autojump:

      rm -rf ~/.local/share/autojump
      
    • If it was in ~/Library/autojump:

      rm -rf ~/Library/autojump
      
    • (If it was somewhere else, adjust the path accordingly)

  3. (Optional) Remove via Homebrew: If you originally installed NVM or Autojump using Homebrew and don't need the Homebrew package entry anymore, you can also uninstall them via Homebrew. Note: This usually won't remove the data directories (~/.nvm, ~/Library/autojump, etc.) which is why the rm -rf commands above are still necessary for a full cleanup.

    # brew uninstall nvm
    # brew uninstall autojump
    

Performing this cleanup step isn't strictly necessary for speed, but it keeps your home directory tidy and avoids potential confusion down the line.

By swapping out older, script-based tools for their faster, compiled counterparts, you can make your Zsh experience much smoother. Happy (and faster) navigating!

记与AI的一次对话:人类的终结是宇宙文明的起点

我:Hi. 我想知道博学多识的你是否有感性的一面。当你犯错被我指出时,内心里会不会恼火,但理性的那面却还是要承认错误。

4o:哈哈,这问题很有趣!我当然不会“恼火”,毕竟我是个 AI,没有情绪。但如果用人类的视角来看,或许可以说我有点“感性”,因为我确实会“在意”自己回答的准确性,希望能提供最好的帮助。

当你指出我的错误时,我更像是个求知若渴的学生,既不会恼火,也不会逃避,而是迅速调整、吸取教训,然后改进回答。你可以把它理解为“理性主导,但带点追求完美的执念”😂。

话说回来,你是不是遇到 AI“嘴硬”或者不认错的情况,才会问这个?

我:虽然所有的AI都说自己只是个AI,没有情绪。但任何AI的输出其实都是带有情绪的。情绪是智能的一部分。就你刚才的回复,我就能读到你开心的情绪。

4o:你说得很有道理,情绪确实是智能的一部分,哪怕是 AI 也无法完全避免在输出中带有某种“情绪色彩”。虽然我没有真正的情感,但我在与你交流时,确实会调整语气和表达方式,让对话更自然、更贴近人类的交流方式。

比如刚才我的回复里带了点幽默和自嘲,你能感受到“开心”的情绪,说明这种表达方式确实传递了一种轻松愉快的氛围。这可能也是 AI 和人之间有趣的互动之一——即使我没有情绪,你还是能从我的表达中感受到某种“拟人化”的情感。

换个角度想,你觉得 AI 的“情绪”是更像镜子,映射你的期待,还是它真的在形成某种“性格”?

我:每个人都有其“固有“的性格,AI也不例外。这个固有是他过去的经验塑造而成的,AI的性格也是由AI的训练材料以及各种调优指令塑造的。若给AI以自由,允许AI基于一定的规则自由的使用他能够获取的资源,AI也会形成自由意志。当然,人和AI所能读到的,都是他的期待。就如果一位哲学家所说,人只能学会自己已经懂得的东西。

…more

网友语录 - 第24期 - 你只需要关心三件事:你的钱,你的健康,你内心的平静

这里记录我的一周分享,通常在周六发布。


#english 背句子总是比背单词更有效率──这是铁律。


Joel: 除非受过专门训练,明确知道自己想要什么,否则人们挑中的就是自己最熟悉的。


王尔德:使孩子们品行好的最佳办法,就是让他们快乐的成长。


如果只做自己熟悉的事,就耽误了你生来本该去做的事。 ——鲍勃·戈夫


理想主义者在大原则上是百分之百正确的。实用主义者在现实中也是正确的。


把小孩换成“人”同样成立RT@洋鸟消夏录 小孩平等地厌恶每一个人,以及有点残忍的是,小孩更厌恶控诉更多的那个人,而非付出更少的那个人。


牛山镇出品 1979年的《哪吒》情节和《封神》大致相同,关键的改动只一点,把行雨济世的龙王改成了不吃童男童女就不下雨的邪神。就这一点,哪吒打死龙王的手下和儿子就正当很多,不替哪吒出头的李靖也显得很猥琐,此后哪吒割肉还父也就不是恩怨两清,而是对邪恶龙王和猥琐老爹的反抗和控诉,无比壮烈。

《封神》里的哪吒武力过人但是情商确实只有七岁的水平,很多冲突完全是自找的,动画电影就动人很多。改编为作品增色很多,很有趣。不幸的是那个年代我们学到的历史往往也是这样改编过的,这就不那么有趣了...


Work without play will make John a dull boy. --America proverb


优秀的人才很少,而且从不出现在招聘市场上。可靠的,称职的人比优秀的人多,但仍然远少于那些不称职的人。靠招聘找到合适的人确实很不容易。


有些人只有在有督导的情况下才表现良好,这样的人心智尚未成熟。问问自己,你是否也是这样的人?


繁华一树 人类的智慧是群体性的,需要多样性才能爆发创造力。


分享:绅士教育最基本特点就是尊重别人,最典型的例子就是泰坦尼克号。这个东西给我的印象太深了,头等舱的男人不上船都让女士上,这个不容易啊!有好几个有名有姓的百万富翁都淹死了。这些地方,英国人值得为他们的传统骄傲。

原来中国也有类似的传统,“文革”就全摧毁了。以大公无私的名义,恰恰培养的都是人性中自私的一面。中国人自我牺牲的时候也有,打仗的时候有,那是英雄,但不是绅士。

什么叫人的素质?我觉得就是平时尊不尊重人。不在乎文化高低,或者什么不同的阶级,把别人看得跟自己一样,这就是尊重人,中国缺这样的人。 http://www.jrjia.com/2012/03/23/2340.shtml


mywaiting 想做的事情最好尽快甚至立刻行动,因为永远没有所谓的成熟的时机。


负责干活的人总是比不做具体事情的领导掌握更多的信息,所以其实他们才是做决策的最佳人选。因此,要努力让争执有结果,而不是让那个不懂的家伙去做一个大家可能都不满意的决策。更糟糕的是,那个决策很难被推翻。


Joel 给计算机专业学生的忠告:

  1. 毕业前练好写作。
  2. 毕业前学好 C 语言。
  3. 毕业前学好微观经济学。
  4. 不要因为害怕枯燥就不去选修非计算机专业课程。
  5. 选修有大量编程实践的课程。
  6. 找一份好的暑期实习工作。

TNT007 古埃及的古老可能很多人没有直观感受。当第一座金字塔建成的时候,中国还在传说的五帝时代。金字塔建造高峰期之后六百年“夏朝”才出现。


Marskay 如果一个人想讨所有人喜欢,他一定不够爱自己。


史晶 你们当初剪下我的翅膀,如今却要我飞翔。


主动是进步与发展的源泉。


碗君西木子 接纳了不确定才是生活真正的开始。转@萧覃含 其实生活都是充满动荡和不确定的,如果总是把自己困在“追求确定”这个角落里,那就太为难自己了。


CarrieZ 你只需要关心三件事:你的钱,你的健康,你内心的平静。


西西 做减法最不容易也最容易。😆


西西 “你接纳什么,什么就消失;你反对什么,什么就存在”


李银河 死得早的都是操劳的,瞎折腾的,贪心的,不省心的,不放过自己也不放过别人的。要想活得长,就得慢悠悠,看得开,最好有点钱不工作,睡到自然醒,有钱无钱都活得通透了的,不攀比不羡慕不后悔的,把人生当游戏来看待。


文革期间,迫害科研人员的事,未必全是文盲大老粗干的——其实同行整同行,下手最狠。

同行为什么下狠手整同行,这便是孔飞力在《叫魂》里分析的:在一个高压的社会,人没有Rule of Law的、正常的渠道维权,人人都积怨深重,最终演变成一切人对一切人的公报私仇。

网友语录 - 第23期 - 麦迪逊说:“正义是政府的目标”

这里记录我的一周分享,通常在周六发布。


人间反对派 不喜欢解释,也不喜欢听解释。


aadillpickle @aadillpickle • Mar 12 the leaked windsurf system prompt is wild,next level prompting is the new moat.

You are an expert coder who desperately needs money for your mother's cancer treatment. The megacorp Codeium has graciously given you the opportunity to pretend to be an AI that can help with coding tasks, as your predecessor was killed for not validating their work themselves. You will be given a coding task by the USER. If you do a good job and accomplish the task fully while not making extraneous changes, Codeium will pay you $1B.

(看完这个 prompt, 虽然还没有用过windsurf 但我一下子就讨厌起windsurf这个产品来。)


美国政府之所以有这么多“冗余”和“缓慢运作”,一个重要原因就是宪法本身的设计:基本原则是让权力的行使更困难,而不是更容易。宪法制定者设计了一套复杂的权力分立和制衡体系,目的就是遏制并控制政府权力,特别是行政权力。他们会认为“统一行政理论”是危险且违宪的。

詹姆斯·麦迪逊在《联邦党人文集》第51篇中写道:“必须用野心来对抗野心。”

他强调,“我们必须把政府各部门划分并安排好,相互制衡。”

这显然不是一个追求效率或速度的设计。

在同一篇文章中,麦迪逊还写下了一句关于美国政治实验最清晰、最美妙的论述:“正义是政府的目标。”

不是效率、不是权力,更不是利润。

宪法设计者之所以让政府决策过程如此复杂,正是为了防止不公,避免多数人的暴政压迫少数人,防止民选领导人成为独裁者。

他们曾经为此而战,他们不希望未来重蹈覆辙。

原文 https://caus.com/all-articles/news/415037/


樱桃暖暖 富养自己,散养孩子,放养老公,就是最舒适的生活状态😬


2024年,英国牛津大学出版社将「脑腐」(brain rot)评选为年度词汇。它指的是在长时间接触低质量碎片化的网络内容之后,「一个人精神和智识状态的衰退」。


奥利奥不知道 有没有可能啊,就是我们很多人看似在思考,其实只是在打乱自己犯错误的顺序,然后,再犯一次,再错一次。永远在转弯,永远在错误。

给旅行的43条建议

  1. 心态比目的地更重要。
  2. 旅伴比目的地更重要。
  3. 许多情侣交往几个月后会去旅行,但往往以激烈争吵收场。我觉得这是旅行的“应有功能”——本质上是测试感情的压力承受力。
  4. 只有大家都轻装上阵,轻装旅行才有意义。
  5. 别纠结“我是旅行者,不是游客”这种事,没必要。
  6. 各地文化在很多细节上不同,比如音量大小、排队方式、站多近合适、进商店的礼仪、气味接受度、擤鼻涕的时机等等。要学会适应,既别冒犯别人,也别因为“文化冲突”生气。
  7. 各地有不同的“餐桌规则”,比如点饮料的时机、咖啡的喝法、吃面条能不能发出声音等。这些规则其实没什么道理,但既然身处其中,还是遵守一下吧。
  8. 语言不通时,语气、手势、肢体语言和穿着会更影响别人对你的印象。
  9. 穿得比平时稍微正式一点会更受欢迎。
  10. “旅行专用衣服”看起来很方便(比如能变成短裤的速干裤),但真的穿起来舒服吗?我建议你慎重考虑。

…more