Dotfiles

出自 Arch Linux 中文维基

本文或本節需要翻譯。要貢獻翻譯,請訪問簡體中文翻譯團隊

附註: 請提供模板的第一個位置參數以更詳細的指示。(在 Talk:Dotfiles# 中討論)

用戶對於程序的配置通常存儲在所謂的 點文件 (以 . 開頭的文件)中。通常的做法是用版本控制系統(如 Git )來管理點文件,以跟蹤其變化,並在不同的主機上同步。有許多管理點文件的方法。例如,直接跟蹤主目錄中的點文件;或者將其放在子文件夾中,用 shell 腳本或專用工具進行管理。除了說明如何管理你的點文件之外,本文章還包含了一個來自 Arch Linux 用戶的點文件配置庫列表。

使用 Git 跟蹤點文件[編輯 | 編輯原始碼]

The benefit of tracking dotfiles directly with Git is that it only requires Git and does not involve symlinks. The disadvantage is that host-specific configuration generally requires merging changes into multiple branches.

The simplest way to achieve this approach is to initialize a Git repository directly in your home directory and ignoring all files by default with a gitignore(5) pattern of *. This method however comes with two drawbacks: it can become confusing when you have other Git repositories in your home directory (e.g. if you forget to initialize a repository you suddenly operate on your dotfile repository) and you can no longer easily see which files in the current directory are untracked (because they are ignored).

An alternative method without these drawbacks is the "bare repository and alias method" popularized on Ask Hacker News: What do you use to manage your dotfiles?, which just takes three commands to set up:

$ git init --bare ~/.dotfiles
$ alias config='/usr/bin/git --git-dir=$HOME/.dotfiles/ --work-tree=$HOME'
$ config config status.showUntrackedFiles no

You can then manage your dotfiles with the created alias. If you are using Bash and would like bash completion for this alias, simply install bash-complete-aliasAUR, then add the alias and the following line to your ~/.bashrc.

$ complete -F _complete_alias config

Another way to get completion in bash is adding the following to your ~/.bashrc (taken from [1]):

source /usr/share/bash-completion/completions/git
__git_complete config __git_main
提示:To avoid accidentally commiting confidential information, see Git#Filtering confidential information.

特定配置[編輯 | 編輯原始碼]

A common problem with synchronizing dotfiles across various machines is host-specific configuration.

With Git this can be solved by maintaining a master branch for all shared configuration, while each individual machine has a machine-specific branch checked out. Host-specific configuration can be committed to the machine-specific branch; when shared configuration is modified in the master branch, the per-machine branches need to be rebased on top of the updated master.

In configuration scripts like shell configuration files conditional logic can be used. For example, Bash scripts (i.e. .bashrc) can apply different configuration depending on the machine name (or type, custom variable, etc.):

if [[ "$(hostname)" == "archlaptop" ]]; then
    # laptop specific commands here
else
    # desktop or server machine commands
fi

Similar can also be achieved with .Xresources.[2]

If you find rebasing Git branches too cumbersome, you may want to use a tool that supports file grouping, or if even greater flexibility is desired, a tool that does processing.

工具[編輯 | 編輯原始碼]

文件分組
如何分組配置文件。
處理
一些工具對配置文件進行處理,使其能夠根據主機情況進行定製。
名稱 語言 文件分組 處理
chezmoi chezmoi Go directory-based Go templates
dot-templater dot-templater-gitAUR Rust directory-based custom syntax
dotdrop dotdropAUR Python configuration file Jinja2
dotfiles dotfilesAUR Python No No
Dots dots-managerAUR Python directory-based custom append points
dotter dotter-rsAUR Rust configuration file Handlebars
dt-cli dt-cliAUR Rust configuration file Handlebars
GNU Stow stow Perl directory-based[3] No
Mackup mackupAUR Python automatic per application No
mir.qualia mir.qualiaAUR Python No custom blocks
rcm rcmAUR Perl directory-based (by host or tag) No

Git 的替代品[編輯 | 編輯原始碼]

如果你不喜歡 Git ,可以嘗試下列工具,它們包含一個單獨的版本控制系統(或多或少)。

名稱 語言 文件分組 處理
dotbare dotbareAUR Shell (fzf) repository-wise No
dotgit dotgitAUR Python filename-based No
homeshick homeshick-gitAUR Bash repository-wise No
homesick Ruby repository-wise No
Pearl pearl-gitAUR Python repository-wise No
vcsh vcsh Shell repository-wise No
yadm(1) yadm Python filename-based
(by class/OS/distro/hostname/user)[4]
Built-in templates/Jinja2/ESH[5]
(optional)
  1. 支持以 GPG 或 OpenSSL 對文件加密。 [6]

用戶倉庫[編輯 | 編輯原始碼]

作者 Shell WM / DE 編輯器 終端 終端復用 音頻 資源監視 郵件 IRC 文件管理 RSS 閱讀
alfunx zsh awesome vim kitty tmux ncmpcpp/mpd htop/lain thunderbird
Ambrevar Eshell EXWM Emacs Emacs (Eshell) Emacs TRAMP + dtach EMMS conky/dzen mu4e Circe
ananthu zsh bspwm neovim alacritty mpv htop, polybar neomutt weechat ranger
awal fish i3 vim st tmux i3status The Lounge
ayekat zsh karuiwm vim rxvt-unicode tmux ncmpcpp/mpd karuibar mutt irssi
bachoseven zsh dwm neovim st ncmpcpp bottom neomutt weechat lf
bamos zsh i3/xmonad vim/emacs rxvt-unicode tmux mpv/cmus conky/xmobar mutt ERC
benmezger zsh/bash i3-gaps emacs rxvt-unicode/alacritty tmux mopidy/ncmpcpp i3status-rs mu4e/neomutt/mbsync weechat
brisbin33 zsh xmonad vim rxvt-unicode screen dzen mutt irssi
BVollmerhaus fish i3-gaps kakoune kitty polybar ranger
cinelli zsh dwm vim termite-git pianobar htop mutt-kz weechat
dikiaap zsh i3-gaps neovim alacritty tmux i3blocks nnn
Earnestly zsh i3/orbment vim/emacs termite tmux mpd conky mutt weechat
ErikBjare zsh xmonad/xfce4 vim terminator tmux xfce4-panel weechat
falconindy bash i3 vim rxvt-unicode ncmpcpp conky mutt
filiparag fish bspwm vim alacritty tmux mpv, playerctl htop, polybar mail-notification pcmanfm[失效連結 2022-09-17 ⓘ]
gardenapple zsh sway neovim kitty htop aerc
graysky zsh xfce4 vim terminal ncmpcpp custom thunderbird
hugdru zsh awesome neovim rxvt-unicode tmux thunderbird weechat
insanum bash herbstluftwm vim evilvte tmux dzen mutt-kz
isti115 pwsh sway neovim alacritty tmux mpv / playerctl waybar / htop / ytop ranger
jasonwryan bash/zsh dwm vim rxvt-unicode tmux ncmpcpp custom mutt irssi
jdevlieghere zsh xmonad vim terminal tmux htop mutt weechat
jelly zsh i3 vim termite tmux ncmpcpp mutt-kz-git weechat
JonasDe[失效連結 2022-09-17 ⓘ] zsh i3 vim rxvt-unicode tmux
Jorengarenar sh/Bash i3 Vim xterm tmux[失效連結 2022-09-17 ⓘ] mpv htop aerc WeeChat ranger QuiteRSS
MarkusZoppelt zsh gnome vim terminal tmux
maximbaz zsh sway kakoune kitty waybar neomutt nnn
mehalter zsh i3-gaps neovim termite tmux cmus gotop neomutt weechat ranger
meskarune bash herbstluftwm vim rxvt-unicode screen conky weechat
neersighted fish i3 neovim alacritty tmux ncmpcpp
nimaipatel fish awesome neovim alacritty ncmpcpp
oibind fish awesome neovim st tmux htop-vim weechat lf
OK100 bash dwm vim rxvt-unicode cmus conky, dzen mutt weechat
orhun bash i3-gaps vsc alacritty i3status weechat tere
pablox-cl zsh (zplug) gnome3 neovim kitty
peterzuger zsh i3-gaps emacs rxvt-unicode screen moc htop
potamides bash awesome neovim termite tmux ncmpcpp conky,htop mutt weechat ranger
reisub0 fish qtile neovim kitty mpd conky
Scrumplex fish sway neovim kitty ncmpcpp / pipewire waybar aerc ranger
sistematico zsh/fish/bash i3-gaps vim/nano termite tmux ncmpcpp polybar mutt weechat
sitilge zsh sway neovim alacritty htop thunderbird
thecashewtrader Eshell EXWM Emacs Emacs (VTerm) Emacs Bongo htop mu4e ERC Dired Elfeed
thiagowfx bash/zsh i3 vim alacritty tmux playerctl i3status ranger
tuurep bash openbox neovim alacritty tmux polybar
vodik zsh xmonad vim termite-git tmux ncmpcpp custom mutt weechat
w0ng zsh dwm vim rxvt-unicode tmux ncmpcpp custom mutt irssi
whitelynx fish i3 neovim kitty i3pystatus
whynothugo zsh sway neovim alacritty mpv waybar, top neomutt nemo
wryonik zsh i3-gaps-rounded vim terminator cmus htop, i3blocks, gotop ranger, nautilus

參見[編輯 | 編輯原始碼]