基本开发环境自动化设置脚本。(屏幕截图)
使用 wget / curl / git 或浏览器(点此下载 zip)下载本脚本。打开 终端
运行如下命令:
via wget
# Download and run via wget
/bin/bash -c "$(wget -O - https://github.com/XuehaiPan/Dev-Setup/raw/HEAD/setup.sh)"
via curl
# Download and run via curl
/bin/bash -c "$(curl -fL https://github.com/XuehaiPan/Dev-Setup/raw/HEAD/setup.sh)"
via git or browser
# Download via git
git clone --depth=1 https://github.com/XuehaiPan/Dev-Setup.git
# Run the script file
cd Dev-Setup
/bin/bash setup.sh
选项:
-
SET_MIRRORS
(默认值false
):将软件包管理器的源设置为开源镜像 TUNA (@China) 以加速下载(更多信息请参见 软件包列表)。如果你想跳过询问步骤,请运行:# Bypass the prompt SET_MIRRORS=true bash setup.sh # set mirrors to TUNA (@China) (recommended for users in China) SET_MIRRORS=false bash setup.sh # do not modify mirror settings
注:如果你使用的是 Windows 上的 WSL (Windows Subsystem for Linux),你需要以 管理员权限 运行 Windows Terminal,用以获得权限将字体文件拷贝至文件夹 C:\Windows\Fonts
,否则将无法在 Windows 上正确安装字体文件。你可以从 nerdfonts.com 下载字体并手动安装,更多信息请参见 字体设置。
脚本执行结束后,所有被涉及的旧配置文件会被备份至文件夹 ${HOME}/.dotfiles/backups/<DATETIME>
,并将会有一个软链接 ${HOME}/.dotfiles/backups/latest
链接至最新的备份文件夹。你可以使用如下命令比较文件变更:
# Compare the differences
colordiff -uEB ~/.dotfiles/backups/latest ~/.dotfiles
colordiff -uEB ~/.dotfiles/backups/latest/.dotfiles ~/.dotfiles
# Ignore miscellaneous directories
colordiff -uEB -x 'backups' -x '.dotfiles' ~/.dotfiles/backups/latest ~/.dotfiles
colordiff -uEB -x 'backups' ~/.dotfiles/backups/latest/.dotfiles ~/.dotfiles
使用 vimdiff
或 meld
可以更方便地查看和比较文件以及在不同版本间拷贝修改。执行:
# Inspect and move changes using vimdiff
vim -c "DirDiff ~/.dotfiles ~/.dotfiles/backups/latest/.dotfiles"
你可以从 https://vimhelp.org/diff.txt.html 获得 vimdiff
的支持文档,或者在 Vim 中执行 :help diff
查看帮助。
你可以运行如下命令回滚旧设置:
# Rollback to the latest backup in "${HOME}/.dotfiles/backups/latest"
bash restore_dotfiles.sh
# Rollback to a specific version
bash restore_dotfiles.sh "${HOME}/.dotfiles/backups/<DATETIME>"
注:由脚本 setup.sh
安装的软件包将保留在你的系统之中。(更多信息请参见 软件包列表)
你可以运行如下命令更新软件包:
upgrade_packages
在默认设置下,命令 upgrade_packages
不会更新 conda 环境。如果你想总是更新所有 conda 环境,可以解注释 ${HOME}/.dotfiles/utilities.sh
中对应的行。或执行以下命令:
upgrade_packages; upgrade_conda
当前用户的默认 Shell 将被设置为 zsh
。为了获得更好的终端体验,请将你的终端字体设置为 Nerd Font。你可以从 nerdfonts.com 手动下载你喜欢的字体。本脚本将为 macOS、Linux 和 Windows 用户自动下载安装 DejaVu Sans Mono Nerd Font
。(Windows 下安装字体需要 管理员权限)
将的终端字体设置为 nerd font:
- 对 macOS 和 Linux 用户,将的终端字体设置为 "Nerd Font Complete"(例如
'DejaVuSansMono Nerd Font Book'
)。 - 对在 Windows 上使用 WSL 的用户,将的终端字体设置为 "Nerd Font Complete Windows Compatible"(例如
'DejaVuSansMono NF'
)。
查看 Font configurations for Powerlevel10k 获取更多信息。
或者使用 Zsh with Powerlevel10k Lean style:
chsh -s /usr/local/bin/zsh-lean # change the login shell
该设置无需做额外的字体配置。
注:如果你使用的是 Windows 上的 WSL (Windows Subsystem for Linux),你需要以 管理员权限 运行 Windows Terminal,用以获得权限将字体文件拷贝至文件夹 C:\Windows\Fonts
。如果你运行脚本时忘记使用管理员权限,你可以重新使用管理员权限打开一个新的终端窗口,并运行如下命令:
find -L ~/.local/share/fonts -not -empty -type f -name '*.tt[fc]' -print0 | xargs -0 -I '{}' bash -c \
'file="{}"
font=${file##*/}
echo "Installing \"${font}\" to \"/mnt/c/Windows/Fonts\""
cp -f "${file}" /mnt/c/Windows/Fonts
/mnt/c/Windows/System32/reg.exe add "HKLM\\SOFTWARE\\Microsoft\\Windows NT\\CurrentVersion\\Fonts" \
/v "${font%.tt[fc]} (TrueType)" /t REG_SZ /d "${font}" /f'
打造你自己的自动化设置脚本。向脚本中添加新设置:
- fork 本仓库;
- 拷贝新的配置文件的内容至一个临时文件
temp.txt
; - 将
temp.txt
中的所有的用户文件夹符号~
替换为${HOME}
; - 将
temp.txt
中的所有的当前用户的用户名替换为${USER}
; - 将
temp.txt
中的所有\
替换为\\
; - 将
temp.txt
中的所有$
替换为\$
; - 在脚本
setup_<OS_NAME>.sh
中添加如下若干行:
cd "${HOME}" # this line has already been added at the top of the script
# Replace <CFG_FILE> with the config file's name
backup_dotfiles <CFG_FILE> .dotfiles/<CFG_FILE>
cat >.dotfiles/<CFG_FILE> <<EOF
# Paste the contents in the temp file `temp.txt` here
EOF
ln -sf .dotfiles/<CFG_FILE> .
- 将项目
<CFG_FILE>
和.dotfiles/<CFG_FILE>
添加至脚本restore_dotfiles.sh
中的DOTFILES
列表中。
软件包管理器(Homebrew (macOS)、APT (Ubuntu)、Pacman (Manjaro)、CPAN、Gem、Conda 和 Pip)的源将被设置为 TUNA (@China) 开源镜像。
本脚本将会安装和配置如下软件包:
Package | macOS | Ubuntu Linux | Manjaro Linux |
---|---|---|---|
Mirrors at TUNA (@China) | ✔ | ✔ | ✔ |
Homebrew | ✔ | ✔ | ✔ |
bash | ✔ | ✔ | ✔ |
bash-completion | ✔ | ✔ | ✔ |
zsh & oh-my-zsh | ✔ | ✔ | ✔ |
powerlevel10k | ✔ | ✔ | ✔ |
zsh-syntax-highlighting | ✔ | ✔ | ✔ |
zsh-autosuggestions | ✔ | ✔ | ✔ |
zsh-completions | ✔ | ✔ | ✔ |
colorls | ✔ | ✔ | ✔ |
git & git-lfs | ✔ | ✔ | ✔ |
vim & vim-plug | ✔ | ✔ | ✔ |
tmux & oh-my-tmux | ✔ | ✔ | ✔ |
reattach-to-user-namespace / xclip | ✔ | ✔ | ✔ |
fzf | ✔ | ✔ | ✔ |
ranger | ✔ | ✔ | ✔ |
fd | ✔ | ✔ | ✔ |
bat | ✔ | ✔ | ✔ |
highlight | ✔ | ✔ | ✔ |
ripgrep | ✔ | ✔ | ✔ |
wget | ✔ | ✔ | ✔ |
curl | ✔ | ✔ | ✔ |
openssh | ✔ | ✔ | ✔ |
ruby & rubygems | ✔ | ✔ | ✔ |
perl & cpan | ✔ | ✔ | ✔ |
htop | ✔ | ✔ | ✔ |
net-tools | ✔ | ✔ | ✔ |
atool | ✔ | ✔ | ✔ |
tree | ✔ | ✔ | ✔ |
git-extras | ✔ | ✔ | ✔ |
diffutils | ✔ | ✔ | ✔ |
colordiff | ✔ | ✔ | ✔ |
diff-so-fancy | ✔ | ✔ | ✔ |
jq | ✔ | ✔ | ✔ |
shfmt | ✔ | ✔ | ✔ |
shellcheck | ✔ | ✔ | ✔ |
Miniconda3 | ✔ | ✔ | ✔ |
mamba | ✔ | ✔ | ✔ |
gcc | ✔ | ✔ | ✔ |
gdb | ✔ | ✔ | ✔ |
clang & llvm | ✔ | ✔ | ✔ |
lldb | ✔ | ✔ | ✔ |
make | ✔ | ✔ | ✔ |
cmake | ✔ | ✔ | ✔ |
automake | ✔ | ✔ | ✔ |
autoconf | ✔ | ✔ | ✔ |
DejaVu Sans Mono Nerd Font | ✔ | ✔ | ✔ |
Cascadia Code Font | ✔ | ✔ | ✔ |
Menlo Font | ✔ | ✔ | ✔ |
Microsoft YaHei Mono Font | ✔ | ✔ | ✔ |
仅在 macOS 上由 Homebrew 安装的 App:
Package | Description | macOS | Ubuntu / Manjaro Linux |
---|---|---|---|
iTerm2 | A terminal emulator for macOS that does amazing things | ✔ | ✘ |
Google Chrome | A fast, secure, and free web browser built for the modern web | ✔ | ✘ |
Keka | The macOS file archiver | ✔ | ✘ |
IINA | The modern media player for macOS | ✔ | ✘ |
Typora | A truly minimal markdown editor | ✔ | ✘ |
Visual Studio Code | A lightweight but powerful source code editor | ✔ | ✘ |
XQuartz | An open-source effort to develop a version of the X.Org X Window System that runs on macOS | ✔ | ✘ |
Shell:
tmux:
fzf:
Vim:
实时 Vim Markdown 预览支持: