Skip to content

Latest commit

 

History

History
267 lines (197 loc) · 19.4 KB

README.md

File metadata and controls

267 lines (197 loc) · 19.4 KB

Dev-Setup

中文版 👈

Automation scripts for setting up a basic development environment. (screenshots)

Table of Contents

Usage

Installation

Download the script file using wget / curl / git or any browser (click here to download zip). Open Terminal and run:

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

Options:

  • SET_MIRRORS (default false): set the source of package managers to open source mirrors at TUNA (@China) to speed up downloading. (see Packages for more details). If you want to bypass the prompt, run:

    # 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

Note: If you are using WSL on Windows, you need to run Windows Terminal as administrator to get the permissions to copy fonts to C:\Windows\Fonts. Otherwise, the fonts will not be installed successfully on Windows. You can download them from nerdfonts.com and install them manually. See Font Settings for more details.

After running the script, all the old configuration files involved will be backed up to the folder ${HOME}/.dotfiles/backups/<DATETIME>, and a symbolic link ${HOME}/.dotfiles/backups/latest will link to the latest one. You can compare the differences using:

# 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

There is a nice way to inspect and move changes from one version to another version of the same file using vimdiff or meld. Run:

# Inspect and move changes using vimdiff
vim -c "DirDiff ~/.dotfiles ~/.dotfiles/backups/latest/.dotfiles"

You can get vimdiff reference manual from https://vimhelp.org/diff.txt.html, or type command :help diff inside Vim.

Rollback

You can rollback to your previous dotfiles using:

# 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>"

Note: the packages installed by setup.sh (see Packages) will remain in your system.

Upgrade Packages

You can upgrade your packages just by running:

upgrade_packages

By default, upgrade_packages will not upgrade your conda environments. If you want to always keep your conda up-to-date, you can uncomment the corresponding line in ${HOME}/.dotfiles/utilities.sh. Or run the script as:

upgrade_packages; upgrade_conda

Font Settings

The login shell for the current user will be set to zsh. In order to get a wonderful and enjoyable terminal experience, please change your terminal font to a Nerd Font. You can download any nerd font you like from nerdfonts.com manually. The script will download and install DejaVu Sans Mono Nerd Font for macOS, Linux and Windows (administrator privilege is required to install fonts on Windows).

Configure your terminal to use nerd fonts:

  • For macOS and Linux users, change the terminal font setting to "Nerd Font Complete" (e.g. 'DejaVuSansM Nerd Font Book').
  • For WSL on Windows users, change the terminal font setting to "Nerd Font Complete Windows Compatible" (e.g. 'DejaVuSansMono NF').

See Font configurations for Powerlevel10k for more details.

Or use Zsh with Powerlevel10k Lean style:

chsh -s /usr/local/bin/zsh-lean   # change the login shell

which do not need additional font settings.

zsh-lean

Note: If you are using WSL on Windows, you need to run Windows Terminal as administrator to get the permissions to copy fonts to C:\Windows\Fonts. If you forgot to obtain the appropriate privileges, you can open WSL in a new terminal window with administrator privilege. Then run the following command:

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'

Customization

Make your own setup scripts. Add a new config file to the script:

  1. fork this repository;
  2. copy the contents of your config file to a temp file temp.txt;
  3. replace all identifiers of your home directory with ${HOME} in temp.txt;
  4. replace all identifiers of your user name with ${USER} in temp.txt;
  5. replace all \ with \\ in temp.txt;
  6. replace all $ with \$ in temp.txt;
  7. add the following lines to script 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> .
  1. add <CFG_FILE> and .dotfiles/<CFG_FILE> to DOTFILES in restore_dotfiles.sh.

Packages

The source of package managers (Homebrew (macOS), APT (Ubuntu), Pacman (Manjaro), CPAN, Gem, Conda and Pip) will be set to the open source mirrors at TUNA (@China).

The following packages will be setup:

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

Currently macOS only casks installed by Homebrew:

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

Screenshots

Shell:

shell

tmux:

tmux

fzf:

fzf

Vim:

vim

Live markdown preview support for Vim:

markdown