Skip to content

mac 系统工作环境

说明

工欲善其事,必先利其器。

ℹ️ 说明

  • 省事方式:可借助 Mac 迁移助理 进行快速同步
  • ✅:免费|推荐
  • ❎:收费|了解|科学

🍀 准备工作

bash
$ brew bundle dump --force --file=~/Desktop/Brewfile  # 生成 Brewfile
$ brew bundle install --file=~/Desktop/Brewfile       # 读取 Brewfile 并安装所有依赖
Brewfile
tap "oven-sh/bun"
tap "sdkman/tap"
brew "code-server", restart_service: :changed
brew "fnm"
brew "fzf"
brew "gettext"
brew "gh"
brew "git"
brew "git-extras"
brew "gping"
brew "libgpg-error"
brew "mysql", restart_service: :changed
brew "nginx", restart_service: :changed
brew "onefetch"
brew "pinentry-mac"
brew "redis"
brew "starship"
brew "syncthing", restart_service: :changed
brew "tlrc"
brew "tree"
brew "uv"
brew "zoxide"
brew "oven-sh/bun/bun"
brew "sdkman/tap/sdkman-cli"
cask "android-platform-tools"
cask "applite"
cask "arc"
cask "browserosaurus"
cask "cursor"
cask "font-fira-code-nerd-font"
cask "font-fira-mono-nerd-font"
cask "font-lxgw-wenkai"
cask "font-monaspace"
cask "font-symbols-only-nerd-font"
cask "google-chrome"
cask "hbuilderx"
cask "hyper"
cask "intellij-idea"
cask "keycastr"
cask "loop"
cask "mihomo-party"
cask "ngrok"
cask "obsidian"
cask "raycast"
cask "screen-studio"
cask "tabby"
cask "tencent-meeting"
cask "visual-studio-code"
cask "webstorm"
常用工具下载
bash
$ brew install git
$ brew install starship
$ brew install gh
$ brew install bun
$ brew install gping
$ brew install onefetch
$ brew install fzf
$ brew install zoxide
$ brew install tlrc  # 控制台命令速查表 tldr-pages
$ brew install git-extras  # 命令增强扩展工具
$ brew install lazygit
$ brew install nginx
$ brew install mysql
$ brew install code-server
$ brew install syncthing

$ brew install --cask mihomo-party
$ brew install --cask applite
$ brew install --cask google-chrome
$ brew install --cask arc
$ brew install --cask visual-studio-code
$ brew install --cask cursor
$ brew install --cask webstorm
$ brew install --cask intellij-idea
$ brew install --cask hbuilderx
$ brew install --cask hyper
$ brew install --cask tabby
$ brew install --cask raycast
$ brew install --cask obsidian
$ brew install --cask ngrok
$ brew install --cask loop
$ brew install --cask cleanshot
$ brew install --cask screen-studio
$ brew install --cask switchhosts
$ brew install --cask keycastr
$ brew install --cask browserosaurus
$ brew install --cask android-studio
$ brew install --cask android-platform-tools
$ brew install --cask picgo
$ brew install --cask vmware-fusion  # 免费虚拟机

$ brew install --cask font-fira-code-nerd-font
$ brew install --cask font-fira-mono-nerd-font
$ brew install --cask font-lxgw-wenkai
$ brew install --cask font-monaspace
$ brew install --cask font-maple-mono-nf-cn
$ brew install --cask font-symbols-only-nerd-font

✍🏻 终端配置

bash
$ touch $HOME/.zsh/plugins
$ touch $HISTFILE

$ git clone https://github.com/zdharma-continuum/fast-syntax-highlighting.git $HOME\.zsh\plugins\fast-syntax-highlighting
$ git clone https://github.com/zsh-users/zsh-autosuggestions.git $HOME\.zsh\plugins\zsh-autosuggestions
$ git clone https://github.com/zsh-users/zsh-completions.git $HOME\.zsh\plugins\zsh-completions
.zshrc 配置文件
bash
# ~/.zshrc
export ZSH=$HOME/.zsh
export ZSH_COMPDUMP=$ZSH/cache/.zcompdump-$HOST
export HISTFILE=$ZSH/.zsh_history
export HISTSIZE=5000
export SAVEHIST=5000
setopt appendhistory
setopt incappendhistory        # 实时写入,避免丢失
unsetopt sharehistory          # 禁用共享,防止竞争
setopt extended_history        # 记录时间戳
setopt hist_ignore_all_dups    # 完全去重
setopt hist_save_no_dups       # 文件去重
setopt hist_find_no_dups       # 搜索去重
setopt hist_expire_dups_first  # 优先删除重复项
setopt hist_ignore_space       # 忽略以空格开头的命令
setopt hist_reduce_blanks      # 去除多余空格
setopt hist_ignore_dups        # 忽略连续重复命令
setopt hist_verify             # 执行历史命令前先显示

# zsh plugins
source $ZSH/plugins/fast-syntax-highlighting/fast-syntax-highlighting.plugin.zsh
source $ZSH/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source $ZSH/plugins/incr/incr.plugin.zsh
fpath=($ZSH/plugins/zsh-completions/src $fpath)
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
ZSH_AUTOSUGGEST_BUFFER_MAX_SIZE=20
# plugins end

export PATH=$HOME/.npm_global/bin:$PATH  # 自定义 npm 全局包安装路径

# fnm
eval "$(fnm env --use-on-cd)"
# fnm end

# fzf
source <(fzf --zsh)
# fzf end

# zoxide
eval "$(zoxide init zsh --cmd cd)"
function cdl() {
    local dir
    dir="$(zoxide query -l | fzf --reverse --height 40% \
        --preview 'ls -l {}' \
        --preview-window=right:60%)" && cd "${dir}"
}
function cdd() {
    local dir
    dir="$(find . -type d 2>/dev/null | fzf --reverse --height 40% \
        --preview 'ls -l {}' \
        --preview-window=right:60%)" && cd "${dir}"
}
# zoxide end

# starship
eval "$(starship init zsh)"
export STARSHIP_CONFIG=$HOME/.config/starship/starship.toml
function set_win_title(){
    echo -ne "\033]0; $(basename "$USER") \007"
}
starship_precmd_user_func="set_win_title"
precmd_functions+=(set_win_title)
# starship end

# sdkman sdk 版本管理工具
export SDKMAN_DIR=$(brew --prefix sdkman-cli)/libexec
[[ -s "${SDKMAN_DIR}/bin/sdkman-init.sh" ]] && source "${SDKMAN_DIR}/bin/sdkman-init.sh"
# sdkman end

# uv python 版本管理工具
eval "$(uv generate-shell-completion zsh)"
eval "$(uvx --generate-shell-completion zsh)"
# uv end

# alias
alias ping="gping"
alias of="onefetch"
alias nio="ni --prefer-offline"
alias s="nr start"
alias d="nr dev"
alias b="nr build"
alias cls="clear"
alias gp='git push'
alias gl='git pull'
alias grt='cd "$(git rev-parse --show-toplevel)"'
alias gc='git branch | fzf | xargs git checkout' # 搜索 git 分支并切换
alias t='tldr' # tldr 命令
# alias end

# 添加清理历史记录的函数
function history_clean() {
    # 创建临时文件
    local tmp=$(mktemp)

    # 使用 tail -r 反向读取历史文件,然后用 awk 处理
    cat $HISTFILE | tail -r | awk '
    {
        if (index($0, ";") > 0) {
            # 命令部分是分号后面的内容
            cmd = substr($0, index($0, ";") + 1);
            if (!seen[cmd]++) {
                # 第一次遇到这个命令(因为文件是反向读取的,所以是最新的)
                result[++count] = $0;
            }
        } else {
            # 处理没有分号的行(可能是没有时间戳的记录)
            if (!seen[$0]++) {
                result[++count] = $0;
            }
        }
    } END {
        # 恢复原来的顺序
        for (i = count; i > 0; i--) {
            print result[i];
        }
    }' > $tmp

    # 确保处理成功后再替换原文件
    if [ -s "$tmp" ]; then
        mv $tmp $HISTFILE
        echo "历史记录已去重,保留了最新的命令记录"
    else
        echo "处理出错,历史记录未修改"
        rm $tmp
    fi
}
  • ✅️ Hyper - 是一款跨平台的终端软件
    • awesome-hyper
    • 配置文件位置:~/Library/Application Support/Hyper/.hyper.js
    • fontFamily: 'FiraCode Nerd Font, Input Mono, monospace'
bash
$ hyper install hyper-dracula
$ hyper install hyperborder
$ hyper install hyperpower
  • Starship - 轻量、迅速、客制化的高颜值终端
bash
$ brew install starship
$ cd .config && mkdir starship && cd starship && type null>starship.toml
starship.toml 配置文件
bash
command_timeout = 10000

# 在提示符之间插入空行
add_newline = true

# 将提示符中的 '❯' 替换为 '➜'
[character]
success_symbol = '[➜](bold green)'

# 禁用 'package' 组件,将其隐藏
[package]
disabled = true

[localip]
ssh_only = false
format = '[$localipv4](bold green) '
disabled = true

[cmd_duration]
min_time = 500
format = 'underwent [$duration](bold yellow)'
disabled = true

💻️ 开发环境

bash
# 设置本地默认分支 main
$ git config --global init.defaultBranch main

# 设置文件大小写敏感
$ git config --global core.ignorecase false

# 忽略目录安全限制
$ git config --global --add safe.directory "*"
  • fnm - 快速简单的 Node.js 版本管理器
bash
# fnm 支持多项目单独切换版本
$ brew install fnm
$ echo 'eval "$(fnm env --use-on-cd)"' >> ~/.zshrc
$ source ~/.zshrc

$ fnm ls
$ fnm ls-remote
$ fnm ls-remote | grep v20
$ fnm install --lts
$ fnm install --latest
$ fnm install 16.14.2
$ fnm install 14.16.0
$ fnm default X
$ fnm use X
$ fnm env

# 项目写入 node 版本
$ node --version > .node-version
  • ✅ 自定义 npm 全局包安装位置
bash
$ mkdir -p ~/.npm_global
$ npm config set prefix ~/.npm_global

# 设置环境变量
echo "# 自定义 npm 全局包安装路径" >> ~/.zshrc
echo "export PATH=~/.npm_global/bin:$PATH" >> ~/.zshrc
echo "# end" >> ~/.zshrc
$ source ~/.zshrc

$ npm i -g @antfu/ni

💻️ 办公工具

♻️ 资源平台