Clloz's Blog

Back

个人工作流搭建 个人工作流搭建

前言#

经过一段时间的整理,我最终形成了一套比较稳定的开发环境方案:

  • 主力开发机:MacBook Pro M1 Max
  • 家庭服务器:Ubuntu 24.04(NUC)
  • 代码托管:Gitea
  • 配置管理:Git + Stow
  • 编辑器:Neovim(LazyVim)
  • 终端:Ghostty + tmux
  • Python:pyenv + uv
  • 版本管理:Gitea

整个方案的目标是:

  1. Mac 作为主力开发环境
  2. Ubuntu 作为 Linux 学习与实验环境
  3. 所有配置可快速迁移与重建
  4. 新机器半小时内恢复工作环境

整体架构#

Mac
├── Homebrew
├── aerospace
├── Ghostty(zsh + zinit + starship)
├── Neovim
└── Git





SSH (Ubuntu)





Ubuntu Server
├── Homebrew
├── zsh + init + starship
├── tmux
├── Neovim
├── Docker
├── Gitea
text

终端配置#

之前的终端使用的是 iterm2 + oh-my-zsh + p10k,感觉配置比较重,并且有点卡。 在进行一番比较之后选择了 ghostty + zinit + starship 的配置

zinit 管理插件 starship prompt atuin 历史记录 zoxide 目录跳转 eza 代替 ls bat 代替 cat git-delta 设置为默认 delta fzf

ubuntu 大多数软件都是通过 apt 安装,但是部分软件官方的版本落后太多,还是通过 homebrew 安装, 包括 autin, starship, zoxide, eza, lazygit, neovim

# mac
# homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# ghostty
brew install ghostty
# zinit
bash -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)"
# starship
brew install starship
# other
brew install autin zoxide eza bat git-delta fzf

# ubuntu
# homebrew
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
# zinit
bash -c "$(curl -fsSL https://raw.githubusercontent.com/zdharma-continuum/zinit/HEAD/scripts/install.sh)"
bash

Dotfiles 管理#

所有配置统一放入 Git 仓库: 我的 dotfiles repo

dotfiles
├── git
├── zsh
├── tmux
├── config
│   └── .config
│       ├── ghostty
│       ├── lazygit
│       └── starship.toml
└── README.md
text

使用 GNU Stow 管理:

# mac
brew install stow
# ubuntu
sudo apt install stow
bash

部署:

cd ~/dotfiles

stow git
stow zsh
stow tmux
stow ghostty
stow config
bash

优点:

  • 不需要软链接脚本
  • 配置结构清晰
  • 可跨平台复用

Git 与 Gitea#

Gitea 部署#

目录:

/srv/gitea
├── docker-compose.yml
├── gitea
└── git
text

Docker 容器:

docker ps
bash
gitea/gitea:latest
text

访问:

http://gitea.home:3001
text

Hosts 配置#

Mac:

192.168.xx.xx gitea.home
text

Ubuntu:

127.0.0.1 localhost gitea.home
text

这样:

git clone git@gitea.home:clloz/project.git
bash

在两台机器都能工作。


开发模式#

推荐:

Mac
    ↓ push

Gitea
    ↓ pull

Ubuntu
text

即:

Mac:

git push
bash

Ubuntu:

git pull
bash

保持两个独立工作副本。


SSH 与 tmux#

SSH 自动进入 tmux#

配置:

if [[ -o login ]] &&
   [[ -n "$SSH_CONNECTION" ]] &&
   [[ -z "$TMUX" ]] &&
   [[ -t 1 ]] &&
   command -v tmux >/dev/null 2>&1; then

    if tmux has-session -t main 2>/dev/null; then
        exec tmux attach-session -t main
    else
        exec tmux new-session -s main
    fi
fi
zsh

效果:

ssh homeserver
bash

自动进入:

tmux session: main
text

tmux 常用配置#

前缀:

Ctrl-a
text

分屏:

|   水平分屏
-   垂直分屏
text

固定比例:

bind | split-window -h -l 20%
bind - split-window -v -l 25%
plaintext

兼容 tmux 3.4 与 3.6。


Neovim#

安装#

采用官方 Release:

curl -LO https://github.com/neovim/neovim/releases/latest/download/nvim-linux-x86_64.tar.gz
bash

安装到:

/opt/nvim
text

加入 PATH。

不使用 Ubuntu 仓库版本。


LazyVim#

配置目录:

~/.config/nvim
text

直接纳入 dotfiles。


OSC52 剪贴板#

解决:

Mac
SSH
Ubuntu
Neovim
text

系统剪贴板同步问题。

配置:

local is_ssh =
  vim.env.SSH_TTY ~= nil or
  vim.env.SSH_CONNECTION ~= nil

if is_ssh then
  vim.g.clipboard = {
    name = "OSC 52",
    copy = {
      ["+"] = require("vim.ui.clipboard.osc52").copy("+"),
      ["*"] = require("vim.ui.clipboard.osc52").copy("*"),
    },
    paste = {
      ["+"] = require("vim.ui.clipboard.osc52").paste("+"),
      ["*"] = require("vim.ui.clipboard.osc52").paste("*"),
    },
  }

  vim.opt.clipboard = "unnamedplus"
end
lua

效果:

yy
vim

直接进入 Mac 系统剪贴板。


Python#

系统 Python#

安装:

sudo apt install \
  python3 \
  python3-pip \
  python3-venv
bash

作用:

  • Mason
  • 系统工具
  • Ubuntu 软件

不用于项目开发。


pyenv#

安装:

git clone https://github.com/pyenv/pyenv.git ~/.pyenv
bash

更新:

cd ~/.pyenv
git pull
bash

uv#

安装:

curl -LsSf https://astral.sh/uv/install.sh | sh
bash

更新:

uv self update
bash

Python 工作流#

统一:

pyenv install 3.12.8

uv init

uv add requests

uv sync
bash

不再使用:

virtualenv
pipenv
poetry
text

Docker#

安装来源:

Docker 官方 apt 仓库
text

已安装:

docker-ce
docker-ce-cli
containerd.io
docker-buildx-plugin
docker-compose-plugin
text

查看:

docker info
bash

数据目录:

/var/lib/docker
text

更新 Docker#

sudo apt update
sudo apt upgrade
bash

或者:

sudo apt install --only-upgrade \
  docker-ce \
  docker-ce-cli \
  containerd.io
bash

Ubuntu 学习环境#

Ubuntu 主要用于:

  • CSAPP
  • Linux
  • GDB
  • ELF
  • 系统编程
  • 网络编程

安装:

sudo apt install \
  build-essential \
  clang \
  gdb \
  cmake \
  valgrind \
  strace \
  ltrace \
  binutils \
  elfutils \
  flex \
  bison
bash

Mac 与 Ubuntu 分工#

最终形成:

Mac#

Rust
WASM
Python
WebGPU
前端开发
AI工具
text

Ubuntu#

Gitea
Docker
CSAPP
Linux
系统编程
服务部署
text

遵循原则:

非 Linux 专属开发在 Mac 完成; Linux、CSAPP、系统编程在 Ubuntu 完成。

这样既能利用 Mac 的优秀开发体验,也能保留真实 Linux 环境用于学习和实验。

个人工作流搭建
https://clloz.com/blog/ubuntu-env-build
Author Clloz
Published at May 30, 2026
Comment seems to stuck. Try to refresh?✨