Skip to content

Latest commit

 

History

History
executable file
·
483 lines (428 loc) · 20.2 KB

README.md

File metadata and controls

executable file
·
483 lines (428 loc) · 20.2 KB

Dotfiles & Scripts

A set of bash, zsh, tmux, powershell, wsl, nodejs, msys2 configuration and script files.

These scripts only tested on my pc, laptop & cloud host and may not cover all cases, and may contain errors, use at your own RISK!

Personal use only, make sure do a full test before using them in Production Environment!

Best practice: make a system backup or prepare a live cd before running these scripts!

Linux Distros what I daily use are Manjaro KDE Plasma, Debian, Centos Stream, WSL2 on Windows 11.

Features

Linux

  • Zsh as default shell
  • Oh My Zsh to managing Zsh configuration
  • ys theme for Zsh without Graphical Environment
  • Oh My Posh theme for Zsh with Desktop Environment(KDE, GNOME, XFCE, WSL...)
  • ZSH theme change script
  • Zsh plugins
  • Terminal Multiplexers: autostart Zellij/Tmux/Screen session on remote system when logging in via SSH
  • Package managers with pacman-style command syntax
  • Unix commands
  • Helper functions
    • public: color echo, version compare...
    • system: cron jobs, systemd services, snapper snapshots...
    • osinfo: OS type, architecture, release, package manager, icon, virtualized...
    • network: ipv4, ipv6, url, web service...
    • proxy: get & set proxy
    • git: clone, update git repos
      • Git_Clone_Update clone or update a git repo:
        Git_Clone_Update "username/repository" "$HOME/repository" # default host `https://github.com/`
        Git_Clone_Update "https://gitlab.com/username/repository" "$HOME/repository" # full repo url
        Git_Clone_Update "[email protected]:username/repository.git" "$HOME/repository"
      • Git_Clone_Update_Branch clone or update a git repo only specified branch:
        Git_Clone_Update_Branch "https://github.com/username/repository" "$HOME/repository" # auto get default branch
        Git_Clone_Update_Branch "username/repository" "$HOME/repository" "https://github.com" "dev" # dev branch
      • Git_Update_Repo_in_SubDir update all git repos in subdirectories
        Git_Update_Repo_in_SubDir "$ZSH/custom" # update all ZSH plugins & themes
    • docker: docker mirrors, pull multiple images...
    • installer: functions to install apps
    • versions: version manager functions for goup, mise, asdf...
    • web
    • misc
  • Scripts & functions to install apps
    • Auto resolve download URL that match running platform, especially for apps release on Github
    • Speed up downloads with axel, if fails use curl instead
    • Automatically extract executable, man, Zsh completions files from compressed files and install to corresponding directories(/usr/local/bin, /usr/share/man, /usr/local/share/zsh/site-functions)
    installPrebuiltBinary rclone "rclone/rclone" # github releases
    installPrebuiltBinary nnn "jarun/nnn" "nnn-nerd-.*\.tar\.gz" # github releases
    installPrebuiltBinary earthly "earthly/earthly" "earthly-*" # github releases
    installPrebuiltBinary "https://dev.yorhel.nl/ncdu" "/download/ncdu-[^<>:;,?\"*|/]+\.tar\.gz" "ncdu-.*\.tar\.gz" # full URL
    • Install app using brew, cargo, go...
    installBuildBinary sd sd cargo
    installBuildBinary fvm fvm brew
    installBuildBinary protoc-gen-go protoc-gen-go go "google.golang.org/protobuf/cmd/protoc-gen-go@latest"
  • Git configs
  • Update apps that installed by app store or version managers
  • alias for docker: alias | grep '^docker'
  • Auto setting environment variables for apps
    • Snap
    • Homebrew
    • PHP
    • Java
    • Go
    • Flutter
    • Rust
    • Python/pip
    • nvm
    • nvs
    • Ruby
    • krew
    • Oracle Instant Client
    • ...
  • Debian distro upgrade
  • CentOS Stream distro upgrade
  • Custom environment variables in ~/.dotfiles.env.local
    • Auto setting proxy if exists, use 127.0.0.1:7890 by default
      GLOBAL_PROXY_IP="127.0.0.1"
      GLOBAL_PROXY_SOCKS_PROTOCOL="socks5"
      GLOBAL_PROXY_SOCKS_PORT="7890"
      GLOBAL_PROXY_MIXED_PORT="7890"
      NO_PROXY_LIST=(
          "127.0.0.1"
          "::1"
          "localhost"
          ".corp"
          ".internal"
          ".local"
          ".localdomain"
      )
    • git clone options
      GIT_CLONE_DEFAULT_OPTION="-c core.autocrlf=false -c core.filemode=false"
    • installer options
      INSTALLER_CHECK_CURL_OPTION="-fsL --connect-timeout 5"
      INSTALLER_DOWNLOAD_CURL_OPTION="-fSL --connect-timeout 5"
      INSTALLER_DOWNLOAD_AXEL_OPTION="--num-connections=5 --timeout=30 --alternate"
    • Github clone & download mirror
      GITHUB_HUB_URL="https://github.com"
      GITHUB_DOWNLOAD_URL="https://github.com"
      GITHUB_RAW_URL="https://raw.githubusercontent.com"
      GITHUB_API_TOKEN=""
    • mirrors
      USE_MIRROR_WHEN_BLOCKED="true"
      
      # Debian
      MIRROR_PACKAGE_MANAGER_APT="mirror.sjtu.edu.cn"
      
      # Archlinux
      MIRROR_ARCHLINUX_CN="https://mirrors.sjtug.sjtu.edu.cn"
      
      # CentOS Stream
      MIRROR_CENTOS_STREAM="https://mirrors.aliyun.com/centos-stream"
      
      # Rockylinux
      MIRROR_ROCKYLINUX="https://mirrors.aliyun.com/rockylinux"
      MIRROR_EPEL_RELEASE="https://mirrors.aliyun.com"
      
      # homebrew
      HOMEBREW_BREW_GIT_REMOTE="https://mirrors.ustc.edu.cn/brew.git"
      HOMEBREW_CORE_GIT_REMOTE="https://mirrors.ustc.edu.cn/homebrew-core.git"
      HOMEBREW_BOTTLE_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles"
      HOMEBREW_API_DOMAIN="https://mirrors.ustc.edu.cn/homebrew-bottles/api"
      
      # flatpak
      MIRROR_FLATPAK_URL="https://mirror.sjtu.edu.cn/flathub"
      
      # go
      GOUP_GO_HOST="golang.google.cn"
      MIRROR_GO_PROXY="https://goproxy.cn,direct"
      # MIRROR_GO_PROXY="https://goproxy.io,direct"
      # MIRROR_GO_PROXY="https://mirrors.aliyun.com/goproxy/,direct"
      # MIRROR_GO_PROXY="https://proxy.golang.org,direct"
      MIRROR_GO_SUMDB="sum.golang.google.cn"
      # MIRROR_GO_SUMDB="gosum.io+ce6e7565+AY5qEHUk/qmHc5btzW45JVoENfazw8LielDsaI+lEbq6"
      # MIRROR_GO_PRIVATE="*.corp.example.com"
      
      # flutter
      PUB_HOSTED_URL="https://pub.flutter-io.cn"
      FLUTTER_STORAGE_BASE_URL="https://storage.flutter-io.cn"
      # PUB_HOSTED_URL="https://mirror.sjtu.edu.cn/dart-pub"
      # FLUTTER_STORAGE_BASE_URL="https://mirror.sjtu.edu.cn"
      
      # rust
      RUSTUP_DIST_SERVER="https://rsproxy.cn"
      RUSTUP_UPDATE_ROOT="https://rsproxy.cn/rustup"
      MIRROR_RUST_CARGO="rsproxy-sparse"
      # RUSTUP_DIST_SERVER="https://mirror.sjtu.edu.cn/rust-static"
      # RUSTUP_UPDATE_ROOT="https://mirror.sjtu.edu.cn/rust-static/rustup"
      # MIRROR_RUST_CARGO="sjtu"
      
      # nodejs
      MIRROR_NODEJS_REGISTRY="https://registry.npmmirror.com"
      
      MIRROR_NODEJS_DISTURL="https://npmmirror.com/dist"
      MIRROR_NODEJS_SASS_BINARY_SITE="https://npmmirror.com/mirrors/node-sass"
      MIRROR_NODEJS_ELECTRON_MIRROR="https://npmmirror.com/mirrors/electron/"
      # MIRROR_NODEJS_PUPPETEER_DOWNLOAD_HOST="https://npmmirror.com/mirrors"
      MIRROR_NODEJS_PUPPETEER_DOWNLOAD_BASE_URL="https://cdn.npmmirror.com/binaries/chrome-for-testing"
      MIRROR_NODEJS_CHROMEDRIVER_CDNURL="https://npmmirror.com/mirrors/chromedriver"
      MIRROR_NODEJS_OPERADRIVER_CDNURL="https://npmmirror.com/mirrors/operadriver"
      MIRROR_NODEJS_PHANTOMJS_CDNURL="https://npmmirror.com/mirrors/phantomjs"
      MIRROR_NODEJS_SELENIUM_CDNURL="https://npmmirror.com/mirrors/selenium"
      MIRROR_NODEJS_NODE_INSPECTOR_CDNURL="https://npmmirror.com/mirrors/node-inspector"
      
      # nvm
      NVM_NODEJS_ORG_MIRROR="https://npmmirror.com/mirrors/node"
      NVM_LOAD_NVMRC_IN_CURRENT_DIRECTORY=false
      
      # nvs
      NVS_NODEJS_ORG_MIRROR="https://npmmirror.com/mirrors/node"
      
      # python/pip
      PYTHON_PIP_CONFIG="$HOME/.pip/pip.conf"
      MIRROR_PYTHON_PIP_URL="https://mirrors.sustech.edu.cn/pypi/web/simple"
      MIRROR_PYTHON_PIP_EXTRA=""
      
      # anaconda
      MIRROR_PYTHON_CONDA="https://mirror.sjtu.edu.cn"
      # MIRROR_PYTHON_CONDA="https://mirror.sjtu.edu.cn"
      # MIRROR_PYTHON_CONDA="https://mirrors.tuna.tsinghua.edu.cn"
      
      # ruby
      RUBY_BUILD_MIRROR_URL="https://cache.ruby-china.com"
      RUBY_GEM_SOURCE_MIRROR="https://gems.ruby-china.com/"
      
      # lyx
      MIRROR_LYX_BASE="https://mirrors.tuna.tsinghua.edu.cn/lyx/"
    • Install and/or update Apps
      # Apps always install and update
      AppAlwaysInstallList=("asdf" "mise" "as-tree" "bat" "broot" "croc" "dasel" "duf" "dust" "erdtree" "eza" "fd" "git-delta" "lazygit" "lnav" "magic-wormhole" "navi" "nnn" "tealdeer" "yq" "zoxide")
      # Apps only install and update on WSL or Desktop environment
      AppWSLDesktopList=("bottom" "btop" "choose" "curlie" "distrobox" "dog" "fq" "fx" "git-lfs" "gotty" "httpie" "httpie-go" "httpstat" "hyperfine" "lsd" "nali" "ncdu" "nu" "onefetch" "ohmyposh" "poetry" "procs" "pup" "rclone" "re-txt" "restic" "sd" "tig" "usql" "viu" "wrk" "xh")
      # Apps only update when installed
      AppUpdateOnlyList=("frp" "goproxy" "he3" "safe-rm" "mihomo" "mieru" "mita" "subconverter" "sing-box" "flutter")

Manjaro

macOS (Same as Linux, but not fully tested)

Windows

Android

  • Use npmmirror.com for npm packages if the world blocked
  • pnpm to install npm packages
  • nvm to manager node versions
  • nvs to manager node versions
  • npm-check-updates to update npm packages
  • A simple file server
  • scripts for openwrt (test purpose)
  • Script for k8s (test purpose)
  • Set font-family by html.lang
    • Noto fonts for SC/TC/HK/JP/KR locale
    • emoji for Emoji
  • Add spaces between CJK characters and Latin letters
  • Remove hidden obfuscated characters
  • Code block pretty
  • Element inspector to Screenshot
  • Element inspector to Markdown

Install on Linux

1. Use the installed distro package manager to install curl and git

sudo pacman -S curl git
sudo apt-get install curl git
sudo dnf install curl git
...

2. Clone to $HOME/.dotfiles

source <(curl -fsSL --connect-timeout 5 --max-time 15 https://git.io/JPSue)

or

curl -fsSL --connect-timeout 5 --max-time 15 https://git.io/JPSue | bash "$HOME/.dotfiles"

3. Install Zsh & Oh My Zsh

${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/zsh/zsh_installer.sh

4. Set Zsh as your login shell

chsh -s $(which zsh)

5. Install/update packages & init Zsh shell

${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/zsh/zsh_upgrade_all_packages.sh && ${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/zsh/zsh_init.sh

Update

source <(curl -fsSL --connect-timeout 5 --max-time 15 https://git.io/JPSue) && ${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/zsh/zsh_upgrade_all_packages.sh

Upgrading npm dependencies

  1. Use npm outdated to discover dependencies that are out of date.
  2. Use npm update to perform safe dependency upgrades.
  3. Use npm install <packagename>@latest to upgrade to the latest major version of a package.

npm-check

  1. Use npm install -g npm-check to install the npm-check package globally.
  2. Use npm-check -u -y to upgrade all dependencies to their latest major versions.

Install on Windows Powershell

Install Windows Terminal if running Windows 10

Windows 11 has built-in Windows Terminal

Install Powershell

Open Powershell as Administrator

Download powershell scripts to ~\Documents\PowerShell\Scripts via pwsh_script_download.ps1

curl -fsSL -o "~\pwsh_script_download.ps1" "https://git.io/JPS2j" && ~\pwsh_script_download.ps1

Init Powershell

~\Documents\PowerShell\Scripts\Powershell_init.ps1

Use scoop to batch install apps & fonts

Edit file ~\Documents\PowerShell\Scripts\scoop_install_apps.ps1 to define the apps & fonts you want to install:

  • $Apps - List of apps to install
  • $sudoApps - List of apps to install with administrative privileges
  • $sudoFonts - List of fonts to install with administrative privileges
~\Documents\PowerShell\Scripts\scoop_install_apps.ps1

Install on WSL(Windows Subsystem for Linux)

  • Install WSL distro
wsl --list --online
wsl --install -d Debian # or distro which your favor
wsl --update
  • Open WSL distro
  • Follow the guide in Install on Linux

commitizen

${MY_SHELL_SCRIPTS:-$HOME/.dotfiles}/commitizen-relax_installer.sh

License

MIT