refractor(macOS): Better setup script for macOS

This commit is contained in:
js0ny 2025-02-11 03:22:40 +00:00
parent 1804960bfc
commit cd7b6c70f0
14 changed files with 538 additions and 311 deletions

150
bootstrap/macOS/Brewfile Normal file
View file

@ -0,0 +1,150 @@
tap "daipeihust/tap"
tap "felixkratz/formulae"
tap "homebrew/bundle"
tap "homebrew/services"
tap "koekeishiya/formulae"
tap "nikitabobko/tap"
tap "railwaycat/emacsmacport"
brew "age"
brew "aichat"
brew "bat"
brew "bottom"
brew "broot"
brew "btop"
brew "cmake"
brew "composer"
brew "coreutils"
brew "curlie"
brew "dark-mode"
brew "dos2unix"
brew "duf"
brew "dust"
brew "duti"
brew "fastfetch"
brew "fd"
brew "ffmpeg"
brew "fish"
brew "fzf"
brew "gh"
brew "ghcup"
brew "git-delta"
brew "glow"
brew "go"
brew "hugo"
brew "hyperfine"
brew "imagemagick"
brew "ipython"
brew "julia"
brew "just"
brew "lazygit"
brew "less"
brew "pkgconf"
brew "lua"
brew "librime"
brew "lsd"
brew "luajit"
brew "luarocks"
brew "macvim", link: false
brew "node"
brew "markdownlint-cli"
brew "mas"
brew "neovim"
brew "nowplaying-cli"
brew "nushell"
brew "openjdk@21"
brew "pandoc"
brew "pipx"
brew "pnpm"
brew "procs"
brew "ripgrep"
brew "ripgrep-all"
brew "rlwrap"
brew "rust"
brew "rustup"
brew "screenfetch"
brew "sd"
brew "sevenzip"
brew "speedtest-cli"
brew "starship"
brew "switchaudio-osx"
brew "tldr"
brew "tmux"
brew "tree"
brew "uv"
brew "vim"
brew "wget"
brew "wget2"
brew "yarn"
brew "yazi"
brew "zellij"
brew "zoxide"
brew "daipeihust/tap/im-select"
brew "felixkratz/formulae/borders"
brew "felixkratz/formulae/sketchybar"
brew "koekeishiya/formulae/skhd"
brew "koekeishiya/formulae/yabai"
brew "railwaycat/emacsmacport/emacs-mac"
cask "activitywatch"
cask "alacritty"
cask "alex313031-thorium"
cask "alt-tab"
cask "apparency"
cask "appcleaner"
cask "arc"
cask "betterdisplay"
cask "chatgpt"
cask "discord"
cask "dotnet-sdk"
cask "font-caskaydia-cove-nerd-font"
cask "font-iosevka-nerd-font"
cask "font-jetbrains-mono-nerd-font"
cask "font-lxgw-wenkai"
cask "font-sf-mono"
cask "font-sf-pro"
cask "google-drive"
cask "iina"
cask "iterm2"
cask "jordanbaird-ice"
cask "karabiner-elements"
cask "keka"
cask "keyguard"
cask "kitty"
cask "localsend"
cask "ltspice"
cask "macfuse"
cask "neovide"
cask "obsidian"
cask "onedrive"
cask "orbstack"
cask "powershell"
cask "protonvpn"
cask "qlcolorcode"
cask "qlimagesize"
cask "qlmarkdown"
cask "qlstephen"
cask "qlvideo"
cask "qspace-pro"
cask "quicklook-json"
cask "quicklookase"
cask "r"
cask "raycast"
cask "rider"
cask "rstudio"
cask "rustdesk"
cask "scroll-reverser"
cask "sf-symbols"
cask "sioyek"
cask "skim"
cask "squirrel"
cask "steam"
cask "suspicious-package"
cask "telegram-desktop"
cask "typora"
cask "visual-studio-code"
cask "vivaldi"
cask "warp"
cask "wezterm"
cask "zen-browser"
mas "QQ", id: 451108668
mas "SnippetsLab", id: 1006087419
mas "微信", id: 836500024

62
bootstrap/macOS/duti.zsh Normal file
View file

@ -0,0 +1,62 @@
# Set default apps (duti)
# The id of the app can be found by running
# `osascript -e 'id of app "AppName"'`
brew install --formula duti
echo "[INFO] Setting Default Apps"
# Markdown -> Typora
duti -s abnerworks.Typora .md all
duti -s abnerworks.Typora .markdown all
# PDF -> Sioyek
duti -s info.sioyek.sioyek .pdf all
# Raw Text -> Neovide
duti -s com.neovide.neovide .txt all
# Archive -> Keka
duti -s com.aone.keka .zip all
duti -s com.aone.keka .rar all
duti -s com.aone.keka .7z all
duti -s com.aone.keka .tar all
# Source Code Light -> Neovim
duti -s com.neovide.neovide .gitignore all
duti -s com.neovide.neovide .vimrc all
duti -s com.neovide.neovide .vim all
duti -s com.neovide.neovide .lua all
duti -s com.neovide.neovide .py all
duti -s com.neovide.neovide .jl all
duti -s com.neovide.neovide .sh all
duti -s com.neovide.neovide .c all
# Source Code DOTNET -> VSCode
duti -s com.microsoft.VSCode .cs all
duti -s com.microsoft.VSCode .fs all
duti -s com.microsoft.VSCode .fsx all
duti -s com.microsoft.VSCode .csx all
duti -s com.microsoft.VSCode .ps1 all
# Source Code Web -> VSCode
duti -s com.microsoft.VSCode .js all
duti -s com.microsoft.VSCode .ts all
duti -s com.microsoft.VSCode .jsx all
duti -s com.microsoft.VSCode .tsx all
duti -s com.microsoft.VSCode .css all
duti -s com.microsoft.VSCode .scss all
duti -s com.microsoft.VSCode .sass all
duti -s com.microsoft.VSCode .vue all
# Source Code Config -> Neovim
duti -s com.neovide.neovide .json all
duti -s com.neovide.neovide .yaml all
duti -s com.neovide.neovide .yml all
duti -s com.neovide.neovide .toml all
duti -s com.neovide.neovide .ini all
duti -s com.neovide.neovide .cfg all
duti -s com.neovide.neovide .conf all
duti -s com.neovide.neovide .kdl all
duti -s com.neovide.neovide .xml all
# Source Code Jupyter -> VSCode
duti -s com.microsoft.VSCode .ipynb all
# Source Code DotNet Project -> Rider
duti -s com.jetbrains.rider .sln all
duti -s com.jetbrains.rider .csproj all
duti -s com.jetbrains.rider .fsproj all
# Video -> IINA
duti -s com.colliderli.iina .mp4 all
duti -s com.colliderli.iina .mkv all
mkdir -p $DOTFILES/powershell_private

88
bootstrap/macOS/main.zsh Normal file
View file

@ -0,0 +1,88 @@
#! /bin/zsh
echo "Running the setup script"
# VARIABLES
export DOTFILES="${DOTFILES:-$HOME/.dotfiles}"
# Xcode Command Line Tools
echo "[INFO] Installing Xcode Command Line Tools"
echo "[ACTION] Request Human Takeover"
xcode-select --install
# Press any key to continue (if Xcode Command Line Tools are installed)
read -n 1 -s -r -p "Press any key to continue when xcode CLI tools are installed"
# System Preferences
# Installation Sources
echo "[INFO] Setting Installation Sources"
echo "[ACTION] Request Human Takeover"
echo "In macOS Sequoia, setup manually (System preferences -> Security & Privacy -> General -> Allow apps downloaded from: Anywhere)"
# sudo spctl --master-disable
# In Mac OS Sequoia, the command above is not working
# Should be set up manually (System Preferences -> Security & Privacy -> General -> Allow apps downloaded from: Anywhere)
echo "[INFO] Installing Homebrew"
echo "[ACTION] Request Human Input"
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
read -n 1 -s -r -p "Press any key to continue when xcode CLI tools are installed"
echo "[INFO] Cloning Dotfiles"
git clone https://github.com/js0ny/dotfiles.git $DOTFILES
echo "[INFO] Setting up system properties"
source $DOTFILES/bootstrap/macOS/plist.zsh
echo "[INFO] Installing Homebrew Packages"
# Load Brewfile
eval "$(/opt/homebrew/bin/brew shellenv)"
brew bundle --file=$DOTFILES/bootstrap/macOS/Brewfile
# Setting Default Apps
source $DOTFILES/bootstrap/macOS/duti.zsh
# Setting up Dotfiles
source $DOTFILES/bootstrap/macOS/symlinks.zsh
source $DOTFILES/bootstrap/components/zsh.sh
source $DOTFILES/tools/zsh/global.zshenv
source $DOTFILES/tools/zsh/zshenv
source $DOTFILES/tools/zsh/zshrc
# Rime
echo "[INFO] Installing Rime"
git clone --depth 1 https://github.com/js0ny/Rime.git ~/Library/Rime
cd ~/Library/Rime
just set_remote
just clone_plum
echo "[INFO] Installing Doom Emacs"
source $DOTFILES/bootstrap/components/emacs.sh
echo "[INFO] Installing Color Scheme (Catppuccin Mocha)"
fish $DOTFILES/bootstrap/temp/mocha_port.fish
# Misc
dotnet tool install --global dotnet-repl
pnpm install -g typescript
pnpm install -g tsx
echo "Done!"

37
bootstrap/macOS/plist.zsh Normal file
View file

@ -0,0 +1,37 @@
## Finder
echo "[INFO] Setting Finder Preferences"
defaults write com.apple.finder QuitMenuItem -bool true # Quit with CMD+Q
defaults write com.apple.finder ShowPathbar -bool true # Show Path Bar
defaults write com.apple.finder ShowStatusBar -bool true # Show Status Bar
defaults write NSGlobalDomain AppleShowAllExtensions -bool true # Show All File Extensions
defaults write com.apple.finder AppleShowAllFiles -bool true # Show Hidden Files
defaults write com.apple.finder _FXSortFoldersFirst -bool true
defaults write com.apple.finder FinderSpawnTab -bool true
# Don't show External Hard Drives on Desktop
defaults write com.apple.finder ShowExternalHardDrivesOnDesktop -bool false
defaults write com.apple.finder ShowHardDrivesOnDesktop -bool false
defaults write com.apple.finder ShowMountedServersOnDesktop -bool false
defaults write com.apple.finder ShowRemovableMediaOnDesktop -bool false
# No DS_Store on Network
defaults write com.apple.desktopservices DSDontWriteNetworkStores -bool true
# Keyboard
# Disable Accent Menu
defaults write NSGlobalDomain ApplePressAndHoldEnabled -boolean false
killall Finder
killall Dock
## Dock
echo "[INFO] Setting Dock Preferences"
defaults write com.apple.dock persistent-apps -array
defaults write com.apple.dock persistent-others -array
defaults write com.apple.dock autohide -bool true # Autohide Dock
defaults write com.apple.dock autohide-time-modifier -float 0.5
defaults write com.apple.dock autohide-delay -float 0 # Immediately Autohide Dock
defaults write com.apple.dock show-recents -bool false # Hide Recent Applications
killall Dock
## Trackpad
echo "[INFO] Setting Trackpad Preferences"
defaults write com.apple.AppleMultitouchTrackpad TrackpadThreeFingerDrag -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad TrackpadThreeFingerDrag -bool true
defaults write com.apple.AppleMultitouchTrackpad Clicking -bool true
defaults write com.apple.driver.AppleBluetoothMultitouch.trackpad Clicking -bool true
defaults write -g NSWindowShouldDragOnGesture -bool true

View file

@ -0,0 +1,30 @@
set -e # Exit immediately if a command exits with a non-zero status
# 声明为关联数组
typeset -A linkDots
# 从通用配置文件加载
source "$DOTFILES/bootstrap/components/symlinks.sh"
echo "[INFO] DOTFILES = $DOTFILES"
echo "[ACTION] Press any key to proceed"
read -n 1
echo "[INFO] Setting up symbolic links"
# 使用 zsh 的关联数组语法
for src in ${(k)linkDots}; do
dest="${linkDots[$src]}"
echo "Linking $src to $dest"
# if [ -d "$src" ]; then
# test -d $dest && mv $dest $dest.bak
# mkdir -p $dest
# ln -sf $src $dest
# elif [ -f "$src" ]; then
# dest_parent=$(dirname $dest)
# test -d $dest_parent || mkdir -p $dest_parent
# ln -sf $src $dest
# else
# echo "[ERROR] $src does not exist"
# fi
done