feat(zsh): Finished reorganise zsh with a same entry point for all platforms

This commit is contained in:
js0ny 2024-11-30 01:29:47 +00:00
parent bd5ca49c3e
commit 2b21b63a13
22 changed files with 503 additions and 369 deletions

0
platforms/linux/.gitkeep Normal file
View file

View file

@ -1,33 +0,0 @@
# pip
alias pip=pip3
alias python=python3
python -m pip install --upgrade pip
pip config set global.index-url https://pypi.tuna.tsinghua.edu.cn/simple
# npm
npm config set registry https://registry.npmmirror.com
# Homebrew
# 手动设置
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
# 注:自 brew 4.0 起,大部分 Homebrew 用户无需设置 homebrew/core 和 homebrew/cask 镜像,只需设置 HOMEBREW_API_DOMAIN 即可。
# 如果需要使用 Homebrew 的开发命令 (如 `brew cat <formula>`),则仍然需要设置 homebrew/core 和 homebrew/cask 镜像。
# 请按需执行如下两行命令:
brew tap --custom-remote --force-auto-update homebrew/core https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git
brew tap --custom-remote --force-auto-update homebrew/cask https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask.git
# 除 homebrew/core 和 homebrew/cask 仓库外的 tap 仓库仍然需要设置镜像
brew tap --custom-remote --force-auto-update homebrew/cask-fonts https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-fonts.git
brew tap --custom-remote --force-auto-update homebrew/cask-versions https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-cask-versions.git
brew tap --custom-remote --force-auto-update homebrew/command-not-found https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-command-not-found.git
brew tap --custom-remote --force-auto-update homebrew/services https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-services.git
brew update
# 或使用下面的几行命令自动设置
export HOMEBREW_CORE_GIT_REMOTE="https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git"
for tap in core cask{,-fonts,-versions} command-not-found services; do
brew tap --custom-remote --force-auto-update "homebrew/${tap}" "https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-${tap}.git"
done
brew update

View file

@ -1,22 +1,15 @@
# $XDG_CONFIG_HOME/zsh/.zshrc
# ln -s $DOTFILES/mac/.zshrc $XDG_CONFIG_HOME/zsh/.zshrc
### Variables ###
# $DOTFILES/platforms/mac/zshrc
# Sourced by user's zshrc if is macOS 在用户的 zshrc 中被引用macOS 特定配置
# Entry point in $DOTFILES/tools/zsh/common.zshrc (入口点)
export DOTFILES="$HOME/.dotfiles"
# Homebrew Path
export PATH=/opt/homebrew/bin:/opt/homebrew/sbin:$PATH
for file in $DOTFILES/zsh/*.zsh; do
source $file
done
export ARCHFLAGS="-arch arm64"
### Navigation ###
# Absolute navigation
alias doku="cd ~/doku && ls"
alias docs="cd ~/Documents"
alias dt="cd ~/Desktop"
alias down="cd ~/Downloads"
alias one="cd ~/OneDrive"
alias gdrive="cd ~/Google\ Drive"
# macOS #
alias xclip="pbcopy"
alias clip="pbcopy"
alias paste="pbpaste"
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
@ -33,16 +26,3 @@ fi
unset __conda_setup
# <<< conda initialize <<<
# >>> juliaup initialize >>>
# !! Contents within this block are managed by juliaup !!
path=('$HOME/.juliaup/bin' $path)
export PATH
# <<< juliaup initialize <<<
# macOS #
alias xclip="pbcopy"
alias clip="pbcopy"

View file

@ -1,83 +0,0 @@
# $XDG_CONFIG_HOME/zsh/.zshrc
# ln -s $DOTFILES/wsl/.zshrc $XDG_CONFIG_HOME/zsh/.zshrc
### Variables ###
export IS_WSL=true
export DOTFILES="$HOME/.dotfiles"
for file in $DOTFILES/zsh/*.zsh; do
source $file
done
source $DOTFILES/wsl/winterop.zsh
source $ZDOTDIR/.zprivate.zsh
export ARCHFLAGS="-arch x86_64"
# Absolute navigation
alias src="cd ~/Source && ls"
alias dotfiles="cd $DOTFILES && ls"
### WSL Options ###
# WSL open
open() {
local target=$1
if command -v explorer.exe > /dev/null; then
explorer.exe "$target"
else
command open "$target"
fi
}
# WSL Neovide
gvi() {
local target=$1
if command -v neovide.exe > /dev/null; then
neovide.exe "$target"
else
if command -v neovide > /dev/null; then
neovide "$target"
else
echo "neovide is not installed"
fi
fi
}
### Misc ###
export PATH=/opt/bin:$PATH
# Conda #
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('/home/js0ny/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "/home/js0ny/miniconda3/etc/profile.d/conda.sh" ]; then
. "/home/js0ny/miniconda3/etc/profile.d/conda.sh"
else
export PATH="/home/js0ny/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<
if [ -f /usr/share/doc/pkgfile/command-not-found.sh ]; then
source /usr/share/doc/pkgfile/command-not-found.sh
fi
# vcpkg
export VCPKG_ROOT=~/vcpkg
# Package Manager
alias pac="sudo pacman"
alias paci="sudo pacman -S"
alias pacr="sudo pacman -R"
alias pacu="sudo pacman -Syu"

View file

@ -1,3 +1,10 @@
# $DOTFILES/platforms/wsl/winterop.zsh
# Sourced by $DOTFILES/platforms/wsl/zshrc 在 $DOTFILES/platforms/wsl/zshrc 中被引用
# Defines the interop commands between WSL and Windows
export FILE_EXPLORER="dopus.exe" # Directory Opus
alias clip="clip.exe"
alias xclip="clip.exe"
alias paste='pwsh.exe -NoProfile -Command "Get-Clipboard"'
@ -13,3 +20,14 @@ alias diskpart="diskpart.exe"
alias winget="winget.exe"
alias pastew='pwsh.exe -NoProfile -Command "Get-Clipboard"'
alias ollama="ollama.exe"
# WSL open
open() {
local target=$1
if command -v "$FILE_EXPLORER" > /dev/null; then
"$FILE_EXPLORER" "$target"
else
command open "$target"
fi
}

31
platforms/wsl/zshrc Normal file
View file

@ -0,0 +1,31 @@
# $DOTFILES/platforms//zshrc
# Sourced by user's zshrc if is WSL 在用户的 zshrc 中被引用WSL 特定配置
# Entry point in $DOTFILES/tools/zsh/common.zshrc (入口点)
# TODO: Test on WSL
### Variables ###
export IS_WSL=true
export ARCHFLAGS="-arch x86_64"
source $DOTFILES/wsl/winterop.zsh
### Misc ###
export PATH=/opt/bin:$PATH
# Conda #
# >>> conda initialize >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$('$HOME/miniconda3/bin/conda' 'shell.zsh' 'hook' 2> /dev/null)"
if [ $? -eq 0 ]; then
eval "$__conda_setup"
else
if [ -f "$HOME/miniconda3/etc/profile.d/conda.sh" ]; then
. "$HOME/miniconda3/etc/profile.d/conda.sh"
else
export PATH="$HOME/miniconda3/bin:$PATH"
fi
fi
unset __conda_setup
# <<< conda initialize <<<

40
scripts/update.zsh Normal file
View file

@ -0,0 +1,40 @@
# $DOTFILES/scripts/update.zsh
# call by `update` alias defined in tools/zsh/alias.zsh
# 使用别名 `update` 引用,别名定义于 tools/zsh/alias.zsh
# Plugins #
# Auto `git pull` on $ZDOTDIR/plugins
for plugin in $ZDOTDIR/plugins/*; do
if [ -d "$plugin" ]; then
cd $plugin
git pull --quiet --no-edit
fi
done
# Update package managers #
# Homebrew, macOS
if command -v brew > /dev/null; then
brew update
brew upgrade
fi
# Arch
if command -v pacman > /dev/null; then
sudo pacman -Syu
fi
# Debian
if command -v apt > /dev/null; then
sudo apt update
sudo apt upgrade
fi
# Fedora
if command -v dnf > /dev/null; then
sudo dnf update
fi
# WSL
if command -v winget.exe > /dev/null; then
winget.exe upgrade
fi

View file

@ -1,20 +0,0 @@
# ~/.zshenv
# ln -s $DOTFILES/zsh/.zshenv $ZDOTDIR/.zshenv
# This file is sourced by all zsh sessions upon startup.
# Use XDG Base Directory Specification
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
# Disable shell sessions on macOS when using default terminal
SHELL_SESSIONS_DISABLE=1
# Zsh
export ZDOTDIR="${XDG_CONFIG_HOME}/zsh"
# Also put in /etc/zsh/zshenv
# or /etc/zshenv in macOS
# sudo cp $DOTFILES/zsh/.zshenv /etc/zsh/zshenv
# sudo cp $DOTFILES/zsh/.zshenv /etc/zshenv

View file

@ -1,50 +0,0 @@
# PowerShell Equivalent #
alias ni=touch
alias cls=clear
alias ii=open
# Dev #
alias g++='g++ -std=c++2b' # Set the default C++ standard to C++20
alias gcc='gcc -std=c99' # Set the default C standard to C99
alias cl='clang -std=c99'
alias clpp='clang++ -std=c++2b'
alias python=python3 # Set the default Python version to Python 3
alias py=python # Alias for Python
alias pip=pip3 # Alias for pip
# alias bashcfg="nvim ~/.bashrc"
alias zshcfg="nvim $ZDOTDIR/.zshrc"
alias shcfg=zshcfg
alias reload="source $ZDOTDIR/.zshrc"
alias nvimrc="nvim $XDG_CONFIG_HOME/nvim/"
alias ohmyzsh="code ~/.oh-my-zsh"
alias pulldots="cd $DOTFILES && git pull"
# Conda #
alias pyact="conda activate"
alias pydact="conda deactivate"
alias pylsenv="conda env list"
alias pymkenv="conda create --name"
# Editors #
alias v=nvim
alias c=code
# lsd #
alias ls='lsd -a'
alias l='lsd -lah'
# Misc #
alias cf=cfiles
# Functions #
mkcd() {
mkdir -p $1 && cd $1
}
cdls(){
cd $1 && ls
}
tc(){
touch $1 && code $1
}
tv(){
touch $1 && nvim $1
}

33
tools/zsh/common.zshrc Normal file
View file

@ -0,0 +1,33 @@
# $DOTFILES/zsh/common.zshrc
# This is the entry point for all zsh configuration files
# 这是所有zsh配置文件的入口点
# Location: $ZDOTDIR/.zshrc (default: $HOME/.zshrc)
# Linking:
# ln -sf $DOTFILES/tools/zsh/common.zshrc $ZDOTDIR/.zshrc
export DOTFILES=$HOME/.dotfiles
case "$(uname)" in
Linux)
if grep -q Microsoft /proc/version || [[ -n "$WSL_DISTRO_NAME" ]]; then
# WSL-specific configuration
source "$DOTFILES/platforms/wsl/zshrc"
else
# Native Linux configuration
source "$DOTFILES/platforms/linux/zshrc"
fi
;;
Darwin)
# macOS-specific configuration
source "$DOTFILES/platforms/mac/zshrc"
;;
# CYGWIN*|MINGW*|MSYS*)
# source "$DOTFILES/platform/wsl.zsh"
# ;;
esac
for file in $DOTFILES/tools/zsh/mod/*.zsh; do
source $file
done

View file

@ -1,98 +0,0 @@
# ZSH Config #
export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH
export PATH=$HOME/.local/share/gem/ruby/3.3.0/bin:$PATH # Ruby Executables
HIST_STAMPS="yyyy-mm-dd"
HISTSIZE=10000
SAVEHIST=10000
export NVM_DIR="$HOME/.config/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm
# plugins=(git web-search jsontools z vi-mode zsh-syntax-highlighting zsh-autosuggestions)
# Plugins (Manually Managed) #
# $ZDOTDIR/plugins
# echo "[DEBUG] Loading plugins..."
# echo $ZDOTDIR
# Load zsh-syntax-highlighting before zsh-history-substring-search
# Reference: https://github.com/zsh-users/zsh-history-substring-search?tab=readme-ov-file#usage
source $ZDOTDIR/plugins/zsh-autosuggestions/zsh-autosuggestions.zsh
source $ZDOTDIR/plugins/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh
source $ZDOTDIR/plugins/zsh-history-substring-search/zsh-history-substring-search.zsh
# Tools Related Environment Variables #
PAGER="less"
EDITOR="nvim"
VISUAL="nvim"
# Use XDG Base Directory Specification #
# ~/.azure/ -> $XDG_DATA_HOME/azure/
export AZURE_CONFIG_DIR="$XDG_DATA_HOME"/azure
# ~/.cargo/ -> $XDG_DATA_HOME/cargo
export CARGO_HOME="$XDG_DATA_HOME"/cargo
# ~/.cgdb/ -> $XDG_CONFIG_HOME/cgdb/
export CGDB_DIR="$XDG_CONFIG_HOME"/cgdb
# ~/.docker -> $XDG_CONFIG_HOME/docker
export DOCKER_CONFIG="$XDG_CONFIG_HOME"/docker
# ~/.dotnet -> $XDG_DATA_HOME/dotnet
# Not working
# export DOTNET_CLI_HOME="$XDG_DATA_HOME"/dotnet
# ~/.gnupg -> $XDG_CONFIG_HOME/gnupg
export GNUPGHOME="$XDG_DATA_HOME"/gnupg
# ~/go -> $XDG_DATA_HOME/go
export GOPATH="$XDG_DATA_HOME"/go
# ~/.inputrc -> $XDG_CONFIG_HOME/readline/inputrc
export INPUTRC="$XDG_CONFIG_HOME"/readline/inputrc
# ~/.juliaup/ -> $XDG_DATA_HOME/julia/
export JULIA_DEPOT_PATH="$XDG_DATA_HOME/julia:$JULIA_DEPOT_PATH"
# Check if node is installed
if command -v node > /dev/null; then
# ~/.node_repl_history -> $XDG_STATE_HOME/node/repl_history
export NODE_REPL_HISTORY="$XDG_STATE_HOME"/node/repl_history
# ~/.ts_node_repl_history -> $XDG_STATE_HOME/node/ts_node_repl_history
export TS_NODE_REPL_HISTORY="$XDG_STATE_HOME"/node/ts_node_repl_history
# ~/.npmrc -> $XDG_CONFIG_HOME/npm/npmrc
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME"/npm/npmrc
# ~/.npm -> $XDG_CACHE_HOME/npm
export NPM_CONFIG_INIT_MODULE="$XDG_CONFIG_HOME"/npm/config/npm-init.js
export NPM_CONFIG_CACHE="$XDG_CACHE_HOME"/npm
export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR"/npm
fi
# ~/.nv -> $XDG_CACHE_HOME/nv (CUDA)
# macOS does not have Cuda; Check if CUDA is installed
if [ "$(uname)" != "Darwin" ] && [ -d "/usr/local/cuda" ]; then
export CUDA_CACHE_PATH="$XDG_CACHE_HOME"/nv
fi
# ~/,parallel -> $XDG_CONFIG_HOME/parallel
export PARALLEL_HOME="$XDG_CONFIG_HOME"/parallel
# ~/.python_history -> $XDG_DATA_HOME/python/history
# Works only with Python 3.13.0a3 and later
export PYTHON_HISTORY="$XDG_DATA_HOME"/python/history
# ~/.screenrc -> $XDG_CONFIG_HOME/screen/screenrc
export SCREENRC="$XDG_CONFIG_HOME"/screen/screenrc
# ~/.screen/ -> $XDG_RUNTIME_DIR/screen
export SCREENDIR="${XDG_RUNTIME_DIR}/screen"
# ~/.spacemacs/ -> $XDG_CONFIG_HOME/spacemacs
export SPACEMACSDIR="$XDG_CONFIG_HOME"/spacemacs
# ~/.tldrc/ -> $XDG_CACHE_HOME/tldr
export TLDR_CACHE_DIR="$XDG_CACHE_HOME"/tldr
# ~/.w3m -> $XDG_DATA_HOME/w3m
export W3M_DIR="$XDG_DATA_HOME"/w3m
# ~/.wakatime.cfg -> $XDG_CONFIG_HOME/wakatime.cfg
# ~/.wakatime/ -> $XDG_CONFIG_HOME/wakatime/
export WAKATIME_HOME="$XDG_CONFIG_HOME/wakatime"
# ~/.wget-hsts -> $XDG_DATA_HOME/wget-hsts
alias wget='wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"'
# ~/.z -> $XDG_DATA_HOME/z
export _Z_DATA="$XDG_DATA_HOME/z"
# ~/.zcompdump* -> $XDG_CACHE_HOME/zsh/zcompdump*
# compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"
# ~/.zsh_history -> $XDG_STATE_HOME/zsh/history
export HISTFILE="$XDG_STATE_HOME"/zsh/history
# https://unix.stackexchange.com/questions/33994/
# Use `set -k` to mark leading `#` as a comment character
set -k

20
tools/zsh/global.zshenv Normal file
View file

@ -0,0 +1,20 @@
# $DOTFILES/tools/zsh/global.zshenv
# system-wide zshenv file 系统级别的 zshenv 文件,用于设置全局环境变量
# Location:
# /etc/zshenv: (macOS and some distro)
# /etc/zsh/zshenv: (some distro)
# Linking:
# sudo cp $DOTFILES/tools/zsh/global.zshenv /etc/zshenv # or /etc/zsh/zshenv
# Set ZDOTDIR to $HOME/.config/zsh if it exists
# This allows us to keep our zsh configuration in $HOME/.config/zsh
# and zshenv will be located at $HOME/.config/zsh/.zshenv instead of
# $HOME/.zshenv
# 如果存在 $HOME/.config/zsh 目录,则将 ZDOTDIR 设置为 $HOME/.config/zsh
# 防止 .zshenv 文件自动生成在用户目录下
# Ensure SPACE between [ and -d and ]
if [ -d $HOME/.config/zsh ]; then
export ZDOTDIR=$HOME/.config/zsh
fi

View file

@ -1,23 +0,0 @@
# $DOTFILES/keymap.zsh
bindkey -v # Vi Keybindings
# Colemak hnei
# bindkey -M vicmd 'h' vi-backward-char # No change
bindkey -M vicmd 'n' down-line-or-history
bindkey -M vicmd 'e' up-line-or-history
bindkey -M vicmd 'i' vi-forward-char
# Similar position to [i] in QWERTY
bindkey -M vicmd 'l' vi-insert
bindkey -M vicmd 'L' vi-insert-bol
# Ne{[k]s}t
bindkey -M vicmd 'k' vi-repeat-search
bindkey -M vicmd 'K' vi-rev-repeat-search
# [J]ump
bindkey -M vicmd 'j' vi-forward-word-end
bindkey -M vicmd 'J' vi-forward-blank-word-end
# Use N to Join
bindkey -M vicmd 'N' vi-join
# Search History with [r]everse (default emacs keybinding)
bindkey '^R' history-incremental-search-backward

89
tools/zsh/mod/alias.zsh Normal file
View file

@ -0,0 +1,89 @@
# $DOTFILES/tools/zsh/mod/alias.zsh
# Sourced by user's zshrc 在用户的 zshrc 中被引用
# PowerShell Equivalent, for cross-platform compatibility
alias ni=touch
alias cls=clear
alias ii=open
# Dev #
alias gpp='g++ -std=c++2b' # Set the default C++ standard to C++20
alias gcc='gcc -std=c99' # Set the default C standard to C99
alias cl='clang -std=c99'
alias clpp='clang++ -std=c++2b'
alias python=python3 # Set the default Python version to Python 3
alias py=python # Alias for Python
alias pip=pip3 # Alias for pip
# alias bashcfg="nvim ~/.bashrc"
alias zshcfg="nvim $ZDOTDIR/.zshrc"
alias shcfg=zshcfg
alias reload="source $ZDOTDIR/.zshrc"
alias nvimrc="nvim $XDG_CONFIG_HOME/nvim/"
alias pulldots="cd $DOTFILES && git pull"
# Editors #
alias v=nvim
alias c=code
alias sv="sudo vim"
alias sn="sudo nvim"
# lsd - modern ls
if command -v lsd > /dev/null; then
alias ls='lsd -A'
alias l='lsd -lah'
alias ll='lsd -l'
alias tree='lsd --tree'
fi
# Functions #
mkcd() {
mkdir -p $1 && cd $1
}
cdls(){
cd $1 && ls
}
tc(){
touch $1 && code $1
}
tv(){
touch $1 && nvim $1
}
# Use neovide as gVim
gvi() {
local target=$1
if command -v neovide.exe > /dev/null; then
neovide.exe "$target"
else
if command -v neovide > /dev/null; then
neovide "$target"
else
echo "neovide is not installed"
fi
fi
}
alias update="source $DOTFILES/scripts/update.zsh"
if command -v pacman > /dev/null; then
alias pac="sudo pacman"
alias paci="sudo pacman -S"
alias pacr="sudo pacman -R"
alias pacu="sudo pacman -Syu"
fi
if command -v apt > /dev/null; then
alias apt="sudo apt"
alias apti="sudo apt install"
alias aptu="sudo apt update && sudo apt upgrade"
alias aptr="sudo apt autoremove && sudo apt remove"
fi
if command -v brew > /dev/null; then
alias brewi="brew install"
alias brewu="brew update && brew upgrade"
alias brewc="brew cleanup"
alias brewr="brew uninstall"
fi

41
tools/zsh/mod/config.zsh Normal file
View file

@ -0,0 +1,41 @@
# $DOTFILES/tools/zsh/mod/config.zsh
# Sourced by user's zshrc 在用户的 zshrc 中被引用
# ZSH Config, no need to `export` these variables
HISTFILE="$XDG_STATE_HOME"/zsh/history
HIST_STAMPS="yyyy-mm-dd"
HISTSIZE=10000
SAVEHIST=10000
# Manually manage plugins 手动管理插件
# Load zsh-syntax-highlighting before zsh-history-substring-search
# Reference: https://github.com/zsh-users/zsh-history-substring-search?tab=readme-ov-file#usage
plugins=(
"zsh-autosuggestions"
"zsh-syntax-highlighting"
"zsh-history-substring-search"
)
plugin_dir="$ZDOTDIR/plugins"
for plugin in "${plugins[@]}"; do
plugin_path="$plugin_dir/$plugin/$plugin.zsh"
if [[ -f $plugin_path ]]; then
source "$plugin_path"
else
echo "Warning: Plugin not found: $plugin_path"
fi
done
# https://unix.stackexchange.com/questions/33994/
# Use `set -k` to mark leading `#` as a comment character
set -k
# TODO: Below should be reorganized
export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH
export PATH=$HOME/.local/share/gem/ruby/3.3.0/bin:$PATH # Ruby Executables
export NVM_DIR="$HOME/.config/nvm"
[ -s "$NVM_DIR/nvm.sh" ] && \. "$NVM_DIR/nvm.sh" # This loads nvm

46
tools/zsh/mod/keymap.zsh Normal file
View file

@ -0,0 +1,46 @@
# $DOTFILES/tools/zsh/mod/keymap.zsh
# Sourced by user's zshrc 在用户的 zshrc 中被引用
bindkey -v # Vi Keybindings
# Colemak hnei
# ^
# n
# < h i >
# e
# v
# bindkey -M vicmd 'h' vi-backward-char # No change
bindkey -M vicmd 'n' down-line-or-history
bindkey -M vicmd 'e' up-line-or-history
bindkey -M vicmd 'i' vi-forward-char
# Similar position to [i] in QWERTY
bindkey -M vicmd 'l' vi-insert
bindkey -M vicmd 'L' vi-insert-bol
# Ne{[k]s}t
bindkey -M vicmd 'k' vi-repeat-search
bindkey -M vicmd 'K' vi-rev-repeat-search
# [J]ump
bindkey -M vicmd 'j' vi-forward-word-end
bindkey -M vicmd 'J' vi-forward-blank-word-end
# Use N to Join
bindkey -M vicmd 'N' vi-join
# Emacs Hybrid
bindkey '^A' beginning-of-line
bindkey '^E' end-of-line
bindkey '^F' forward-char
bindkey '^B' backward-char
bindkey '^P' up-line-or-history
bindkey '^N' down-line-or-history
bindkey '^R' history-incremental-search-backward
# TODO: did not test
bindkey '^K' kill-line
bindkey '^X^E' edit-command-line
# LEADER CONVENTION
# ^X defines as a prefix key in shell
# ^A defines as a prefix key in tmux
# ^B defines as a prefix key in Terminal Emulators
# SPC defines as a prefix key in nvim

39
tools/zsh/mod/navi.zsh Normal file
View file

@ -0,0 +1,39 @@
# $DOTFILES/tools/zsh/mod/navi.zsh
# Sourced by user's zshrc 在用户的 zshrc 中被引用
# Relative navigation #
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
# Use `-` to jump to the previous directory
# Oh-My-Zsh defines a similar one
function - { cd - }
# Use `z` to jump to a directory
eval "$(zoxide init zsh)"
# Absolute navigation #
alias dotfiles="cd $DOTFILES && ls"
# TODO: Test on WSL
if [ "$IS_WSL" = true ]; then # IS_WSL is defined in $DOTFILES/platforms/wsl/zshrc
alias dt="cd /mnt/c/Users/$(whoami)/Desktop && ls"
alias doku="cd /mnt/c/Users/$(whoami)/Documents && ls"
alias down="cd /mnt/c/Users/$(whoami)/Downloads && ls"
alias src="cd /mnt/d/Source"
alias one="cd /mnt/c/Users/$(whoami)/OneDrive"
alias gdrive="cd /mnt/g"
else
alias dt="cd $HOME/Desktop && ls"
alias doku="cd $HOME/Documents && ls"
alias down="cd $HOME/Downloads && ls"
alias src="cd $HOME/Documents/Source"
fi
# macOS specific, no OneDrive & Google Drive on Linux
if [ "$(uname)" = "Darwin" ]; then
alias one="cd $HOME/OneDrive"
alias gdrive="cd $HOME/Google\ Drive"
fi

6
tools/zsh/mod/prompt.zsh Normal file
View file

@ -0,0 +1,6 @@
# $DOTFILES/tools/zsh/mod/prompt.zsh
# Sourced by user's zshrc 在用户的 zshrc 中被引用
export STARSHIP_CONFIG=$DOTFILES/tools/starship/starship_zsh.toml
eval "$(starship init zsh)"

View file

@ -1,11 +0,0 @@
# Relative navigation
alias ..="cd .."
alias ...="cd ../.."
alias ....="cd ../../.."
alias .....="cd ../../../.."
alias ......="cd ../../../../.."
function - { cd - }
eval "$(zoxide init zsh)"

View file

@ -1,3 +0,0 @@
export STARSHIP_CONFIG=$DOTFILES/.config/starship/starship_zsh.toml
eval "$(starship init zsh)"

View file

@ -1,19 +0,0 @@
# $DOTFILES/zsh/update.sh
# This file won't be sourced by zsh by default
# Use `source` to run this file for updating plugins
# Plugins #
# Auto `git pull` on $ZDOTDIR/plugins
for plugin in $ZDOTDIR/plugins/*; do
if [ -d "$plugin" ]; then
cd $plugin
git pull --quiet --no-edit
fi
done
if [ which brew > /dev/null ]; then
brew update
brew upgrade
fi

131
tools/zsh/zshenv Normal file
View file

@ -0,0 +1,131 @@
# $DOTFILES/tools/zsh/zshenv
# User-specific environment variables for zsh 用户级别的 zsh 环境变量
# Location:
# $ZDOTDIR/.zshenv (specified by ZDOTDIR)
# ~/.zshenv (default location)
# Linking:
# ln -sf $DOTFILES/tools/zsh/.zshenv $ZDOTDIR/.zshenv
# This file is sourced by all zsh sessions upon startup.
# For me (this user), define XDG Base Directory Specification variables
# and some configs that does not obey XDG Base Directory Specification
# but can be configured(by setting the variables) to (just like) obey it.
# 在此定义 XDG 基础目录规范变量和一些不遵循 XDG 基础目录规范的配置,
# 使得他们可以通过设置变量来遵循 XDG 基础目录规范。
# XDG Base Directory Specification
export XDG_CONFIG_HOME="${XDG_CONFIG_HOME:-$HOME/.config}"
export XDG_DATA_HOME="${XDG_DATA_HOME:-$HOME/.local/share}"
export XDG_STATE_HOME="${XDG_STATE_HOME:-$HOME/.local/state}"
export XDG_CACHE_HOME="${XDG_CACHE_HOME:-$HOME/.cache}"
export XDG_RUNTIME_DIR="/run/user/$(id -u)"
# Disable shell sessions on macOS when using default terminal
SHELL_SESSIONS_DISABLE=1
# Zsh # Redefine to make sure it's in $XDG_CONFIG_HOME
export ZDOTDIR="${XDG_CONFIG_HOME}/zsh"
# Tools Related Environment Variables
export PAGER="less -R"
export EDITOR="nvim"
export VISUAL="nvim"
# macOS Specific
# This syntax is POSIX standard, for portability
if [ "$(uname)" = "Darwin" ]; then
fi
# Linux Specific
if [ "$(uname)" = "Linux" ]; then
# CUDA
export CUDA_CACHE_PATH="$XDG_CACHE_HOME"/nv
fi
# Azure CLI
if command -v az > /dev/null; then
export AZURE_CONFIG_DIR="$XDG_DATA_HOME"/azure
fi
# Cargo
if command -v cargo > /dev/null; then
export CARGO_HOME="$XDG_DATA_HOME"/cargo
fi
# CGDB
if command -v cgdb > /dev/null; then
export CGDB_DIR="$XDG_CONFIG_HOME"/cgdb
fi
# .NET
if command -v dotnet > /dev/null; then
export DOTNET_CLI_HOME="$XDG_DATA_HOME"/dotnet
fi
# Docker
if command -v docker > /dev/null; then
export DOCKER_CONFIG="$XDG_CONFIG_HOME"/docker
fi
# GnuPG
if command -v gpg > /dev/null; then
export GNUPGHOME="$XDG_DATA_HOME"/gnupg
fi
# Go
if command -v go > /dev/null; then
export GOPATH="$XDG_DATA_HOME"/go
fi
# Julia
if command -v julia > /dev/null; then
export JULIA_DEPOT_PATH="$XDG_DATA_HOME/julia:$JULIA_DEPOT_PATH"
fi
# Node.js
if command -v node > /dev/null; then
export NODE_REPL_HISTORY="$XDG_STATE_HOME"/node/repl_history
export TS_NODE_REPL_HISTORY="$XDG_STATE_HOME"/node/ts_node_repl_history
export NPM_CONFIG_USERCONFIG="$XDG_CONFIG_HOME"/npm/npmrc
export NPM_CONFIG_INIT_MODULE="$XDG_CONFIG_HOME"/npm/config/npm-init.js
export NPM_CONFIG_CACHE="$XDG_CACHE_HOME"/npm
export NPM_CONFIG_TMP="$XDG_RUNTIME_DIR"/npm
fi
# Parallel
if command -v parallel > /dev/null; then
export PARALLEL_HOME="$XDG_CONFIG_HOME"/parallel
fi
# Python
# Works only with Python 3.13.0a3 and later
if command -v python3 > /dev/null; then
export PYTHON_HISTORY="$XDG_DATA_HOME"/python/history
fi
# GNU Screen
if command -v screen > /dev/null; then
export SCREENRC="$XDG_CONFIG_HOME"/screen/screenrc
export SCREENDIR="${XDG_RUNTIME_DIR}/screen"
fi
# Spacemacs
if command -v emacs > /dev/null; then
export SPACEMACSDIR="$XDG_CONFIG_HOME"/spacemacs
fi
# tldr
# Works only with C client (did not verify)
if command -v tldr > /dev/null; then
export TLDR_CACHE_DIR="$XDG_CACHE_HOME"/tldr
fi
# W3M
if command -v w3m > /dev/null; then
export W3M_DIR="$XDG_DATA_HOME"/w3m
fi
# Wakatime
if command -v wakatime > /dev/null; then
export WAKATIME_HOME="$XDG_CONFIG_HOME/wakatime"
fi
# Wget
if command -v wget > /dev/null; then
alias wget='wget --hsts-file="$XDG_CACHE_HOME/wget-hsts"'
fi
# z
if command -v z > /dev/null; then
export _Z_DATA="$XDG_DATA_HOME/z"
fi
# zsh .zcompdump
# compinit -d "$XDG_CACHE_HOME"/zsh/zcompdump-"$ZSH_VERSION"
# Vcpkg TODO: Move vcpkg path
if command -v vcpkg > /dev/null; then
export VCPKG_ROOT="$XDG_DATA_HOME"/vcpkg
fi