Skip to content

Automation scripts for setting up a basic development environment.

License

Notifications You must be signed in to change notification settings

XuehaiPan/Dev-Setup

Repository files navigation

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