lkw123

lkw123

Yet Another Salted Fish
github
x
email
telegram

My MacOS development environment configuration

System Settings#

Dock auto-hide acceleration

# Set the dock animation time to 0.5 seconds
defaults write com.apple.dock autohide-time-modifier -float 0.5 && killall Dock

# Set the shortest dock response time
defaults write com.apple.dock autohide-delay -int 0 && killall Dock

# Restore the default dock animation time
defaults delete com.apple.dock autohide-time-modifier && killall Dock

# Restore the default dock response time
defaults delete com.apple.Dock autohide-delay && killall Dock

Launchpad custom rows and columns

# Set the number of columns
defaults write com.apple.dock springboard-columns -int 7

# Set the number of rows
defaults write com.apple.dock springboard-rows -int 6

# Restart Dock to take effect
killall Dock

# Restore the default number of columns and rows
defaults write com.apple.dock springboard-rows Default
defaults write com.apple.dock springboard-columns Default

# Restart Dock to take effect
killall Dock

Common Software Installation#

fastfetch-screenshot

Command Line Tools#

Use Homebrew to manage system packages, prioritizing packages provided by Homebrew when installing command line tools.

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Recommended tools:

PreferDescriptionReplace
ezaA modern, maintained replacement for ls.ls
zoxideA smarter cd command, supports all major shells.cd
htopAn interactive process viewer.top
ripgrepripgrep recursively searches directories for a regex pattern while respecting your gitignore.grep
ncduNcdu (NCurses Disk Usage) is a disk usage analyzer with an ncurses interface.du
batA cat(1) clone with wings.cat
fdA simple, fast and user-friendly alternative to 'find'.find
procsA modern replacement for ps written in Rust.ps
fzfA general-purpose command-line fuzzy finder written in Go.find
fzf-tabReplace zsh's default completion selection menu with fzf.find
tokeiA program that displays statistics about your code.cloc
tldrCollaborative cheatsheets for console commands.man
thefuckMagnificent app which corrects your previous console command.-
lazygitA simple terminal UI for git commands.git
lazydockerA simple terminal UI for both docker and docker-compose.docker
fastfetchLike neofetch, but much faster because written mostly in C.neofetch
deltaA syntax-highlighting pager for git, diff, and grep output.diff

Terminal Tool Fzf#

In a daily shell environment, you can improve efficiency by using Fzf + Ripgrep + Bat + Vim to manage files and their contents conveniently.

  • File Query:

    Use the pf (preview file) alias to quickly preview and select files. Invoke Fzf for interactive fuzzy searching, and use Bat in the right window to achieve syntax highlighting, previewing the first 500 lines of the selected file. You can page up and down using Shift+Up and Shift+Down to enhance efficiency.

    alias pf='fzf --preview='\''bat --color=always --style=header,grid --line-range \
          :500 {}'\'' --bind shift-up:preview-page-up,shift-down:preview-page-down'
    

    As shown in the image below:

    pf_screenshot

  • Content Query:

    Use the rfv (ripgrep-fzf-vim) function for full-text content search and open results in Vim. The search results will be displayed in real-time in the Fzf window, and relevant content of the file will be previewed using Bat. Bind the Enter key and Ctrl+O key to open search results in Vim for further editing.

    rfv() (
      RELOAD='reload:rg --column --color=always --smart-case {q} || :'
      OPENER='if [[ $FZF_SELECT_COUNT -eq 0 ]]; then
                vim {1} +{2}     # No selection. Open the current line in Vim.
              else
                vim +cw -q {+f}  # Build quickfix list for the selected items.
              fi'
      fzf --disabled --ansi --multi \
          --bind "start:$RELOAD" --bind "change:$RELOAD" \
          --bind "enter:become:$OPENER" \
          --bind "ctrl-o:execute:$OPENER" \
          --delimiter : \
          --preview 'bat --style=header,grid --color=always --line-range :500 --highlight-line {2} {1} \
          --preview-window '~4,+{2}+4/3,<80(up)' \
          --query "$*"
    )
    

    As shown in the image below:

    rfv_screenshot

You can add the above content to the ~/.zshrc file to build a more efficient command line workflow.

Zsh Configuration#

The commonly used Oh My Zsh feels a bit bloated for me, so I choose to use zinit to manage plugins.

Thus, the ~/.zshrc can be divided into several modules, each defining different functional configurations:

During the installation of zinit, it will automatically take over ~/.zshrc and add its related configurations as follows:

### Added by Zinit's installer
if [[ ! -f $HOME/.local/share/zinit/zinit.git/zinit.zsh ]]; then
    print -P "%F{33} %F{220}Installing %F{33}ZDHARMA-CONTINUUM%F{220} Initiative Plugin Manager (%F{33}zdharma-continuum/zinit%F{220})…%f"
    command mkdir -p "$HOME/.local/share/zinit" && command chmod g-rwX "$HOME/.local/share/zinit"
    command git clone https://github.com/zdharma-continuum/zinit "$HOME/.local/share/zinit/zinit.git" && \
        print -P "%F{33} %F{34}Installation successful.%f%b" || \
        print -P "%F{160} The clone has failed.%f%b"
fi

source "$HOME/.local/share/zinit/zinit.git/zinit.zsh"
autoload -Uz _zinit
(( ${+_comps} )) && _comps[zinit]=_zinit

# Load a few important annexes, without Turbo
# (this is currently required for annexes)
zinit light-mode for \
    zdharma-continuum/zinit-annex-as-monitor \
    zdharma-continuum/zinit-annex-bin-gem-node \
    zdharma-continuum/zinit-annex-patch-dl \
    zdharma-continuum/zinit-annex-rust

### End of Zinit's installer chunk

Load Environment Variables#

# Load Environment Variables
export PATH="/Users/lkw123/Library/Python/3.9/bin:$HOME/.cargo/bin:$PATH"
export BAT_THEME="Monokai Extended Origin"
export STARSHIP_CONFIG="/Users/lkw123/.config/starship/starship.toml"
export GPG_TTY=$(tty)

Three Basic Plugins#

# Add in zsh plugins
zinit light zdharma-continuum/fast-syntax-highlighting
zinit light zsh-users/zsh-completions
zinit light zsh-users/zsh-autosuggestions

# Load completions
autoload -Uz compinit && compinit

# Completion styling
zstyle ':completion:*' matcher-list 'm:{a-z}={A-Za-z}'
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
zstyle ':completion:*' menu no

Introduce fzf-tab#

It is worth noting that, according to the fzf-tab README's section on compatibility-with-other-plugins, the introduction of fzf-tab should be placed at the end of the configuration file to avoid conflicts with the zsh-completions plugin.

# fzf-tab init and styling
zinit light Aloxaf/fzf-tab
zstyle ':fzf-tab:complete:cd:*' fzf-preview 'eza --icons -1 --color=always $realpath'
zstyle ':fzf-tab:complete:__zoxide_z:*' fzf-preview 'eza --icons -1 --color=always $realpath'
zstyle ':fzf-tab:complete:z:*' fzf-preview 'eza --icons -1 --color=always $realpath'

With the above configuration, you can quickly preview the file structure of the target directory when using cd:

fzf-tab-screenshot

Define Aliases#

# Aliases
alias ls="eza"
alias ll="eza --time-style=default --icons --git -l"
alias la="eza --time-style=long-iso --icons --group --git --binary -la"
alias tree="eza --tree --icons"
alias cls="clear"
alias cat="bat"
alias v="nvim"

shell-screenshot

History#

# History
HISTSIZE=5000
HISTFILE=~/.zsh_history
SAVEHIST=$HISTSIZE
HISTDUP=erase
setopt appendhistory
setopt hist_ignore_space
setopt hist_ignore_all_dups
setopt hist_save_no_dups
setopt hist_ignore_dups
setopt hist_find_no_dups

Shell Integration#

  • starship: A cross-platform shell prompt based on Rust, lightweight, fast, and customizable, using the Tokyo Night preset;
  • thefuck: Quickly corrects mistyped commands, somewhat less useful in practice than expected;
  • zoxide: Quickly jump to commonly used working directories;
  • fnm: Node.js version management tool.
# Shell integrations
eval "$(starship init zsh)"
eval "$(thefuck --alias)"
eval "$(fzf --zsh)"
eval "$(zoxide init zsh)"
eval "$(fnm env --use-on-cd)"

Finally, a simple test of Zsh's startup time:

  1. Use a straightforward method to observe the startup speed of zsh:

     for i in $(seq 10); do
      /usr/bin/time zsh -lic exit
    done
    
        0.16 real         0.10 user         0.04 sys
        0.13 real         0.09 user         0.03 sys
        0.13 real         0.09 user         0.03 sys
        0.13 real         0.09 user         0.03 sys
        0.13 real         0.09 user         0.03 sys
        0.14 real         0.10 user         0.03 sys
        0.14 real         0.09 user         0.03 sys
        0.13 real         0.09 user         0.03 sys
        0.13 real         0.09 user         0.03 sys
        0.13 real         0.09 user         0.03 sys
    
  2. Use zsh-bench for a more comprehensive benchmark of zsh's startup time:

     ./zsh-bench
    ==> benchmarking login shell of user lkw123 ...
    creates_tty=0
    has_compsys=1
    has_syntax_highlighting=1
    has_autosuggestions=1
    has_git_prompt=1
    first_prompt_lag_ms=199.405
    first_command_lag_ms=202.526
    command_lag_ms=59.470
    input_lag_ms=4.480
    exit_time_ms=136.965
    

It's indeed quite good :)

Development Tools#

GUI Tools#

Use Homebrew Cask for management.

$ brew list
==> Formulae
...
==> Casks
1password                       iina                    plex
alacritty                       jellyfin                sabnzbd
applite                         loop                    transmit
daisydisk                       lulu                    tuxera-ntfs
downie                          netnewswire             typora
font-jetbrains-mono-nerd-font   notion                  zed
font-lxgw-wenkai                orbstack
handbrake                       pictureview

Development Environment#

  • Python: uv -> An extremely fast Python package installer and resolver, written in Rust
  • Node: fnm -> Fast and simple Node.js version manager, built in Rust
  • Java: jenv -> Java enVironment Manager
  • Go: gvm -> Go Version Manager
  • Rust: rustup -> The Rust toolchain installer

Tmux Configuration#

Thanks to Bilibili UP master Patrico for sharing the configuration process in the video Configure tmux with me. My Tmux configuration is mostly copied from there:

# List of plugins
set -g @plugin 'tmux-plugins/tpm'
set -g @plugin 'tmux-plugins/tmux-sensible'
set -g @plugin 'christoomey/vim-tmux-navigator'
set -g @plugin 'tmux-plugins/tmux-yank'

# catppuccin theme
set -g @plugin "catppuccin/tmux"
set -g @catppuccin_flavour "mocha"

# Initialize TMUX plugin manager (keep this line at the very bottom of tmux.conf)
run '~/.tmux/plugins/tpm/tpm'

# non-plugin options
set -g default-terminal "tmux-256color"
set -g base-index 1
set -g pane-base-index 1
set -g renumber-windows on
set -g mouse on

# visual mode
set-window-option -g mode-keys vi
bind-key -T copy-mode-vi v send-keys -X begin-selection
bind-key -T copy-mode-vi C-v send-keys -X rectangle-toggle
bind-key -T copy-mode-vi y send-keys -X copy-selection-and-cancel

# keymaps
unbind C-b
set -g prefix C-Space

MacOS Software One-Click Update#

Preparation#

  • Install brew-cask-upgrade:
    brew tap buo/cask-upgrade
    
  • Verify if brew-cask-upgrade is installed successfully:
    brew tap | grep buo/cask-upgrade
    
  • Install mas, a command line tool for managing applications from the Mac App Store:
    brew install mas
    

Update Software#

Upgrade all installed software:

brew update && brew upgrade && brew cu --all --yes --cleanup \
&& mas upgrade && brew cleanup
  1. brew update: Updates Homebrew itself and its related software source information to ensure accurate Index information;

  2. brew upgrade: Upgrades all installed Homebrew packages to the latest version;

  3. brew cu --all --yes --cleanup: Automatically upgrades all updatable Homebrew cask packages to the latest version and cleans up old versions after completion;

  • -all: Include apps that auto-update in the upgrade.
  • -yes: Update all outdated apps; answer yes to updating packages.
  • -cleanup: Cleans up cached downloads and tracker symlinks after updating.
  1. mas upgrade: One-click updates applications installed from the Mac App Store;

  2. brew cleanup: Cleans up temporary files and caches generated during the installation of Homebrew packages to free up disk space.

Sample execution results are as follows:

mac-upgrade

This can be set as a scheduled task to periodically execute, keeping the software on the Mac up to date.


Some of my dotfiles are hosted in the GitHub repository synthpop123/dotfiles for backup purposes.

Loading...
Ownership of this post data is guaranteed by blockchain and smart contracts to the creator alone.