Add zsh configuration sync system
- Add zshrc.template with full oh-my-zsh configuration - Add install-zsh-config.sh for complete installation - Add quick-install.sh for one-command installation - Add sync script for configuration updates - Include custom aliases and plugin configurations - Support for ansible, docker, terraform, kubernetes tools
This commit is contained in:
parent
377f176501
commit
92febc12aa
|
|
@ -0,0 +1,146 @@
|
|||
# ZSH 配置同步方案
|
||||
|
||||
这个目录包含了完整的 oh-my-zsh 配置,可以在多个 VPS 之间同步使用。
|
||||
|
||||
## 文件结构
|
||||
|
||||
```
|
||||
configuration/zsh/
|
||||
├── README.md # 本文件
|
||||
├── install-zsh-config.sh # 完整安装脚本
|
||||
├── quick-install.sh # 快速安装脚本
|
||||
├── zshrc.template # ZSH 配置文件模板
|
||||
└── oh-my-zsh-custom/ # 自定义 oh-my-zsh 配置
|
||||
├── aliases.zsh # 自定义别名
|
||||
└── plugins/ # 自定义插件
|
||||
```
|
||||
|
||||
## 使用方法
|
||||
|
||||
### 方法一:快速安装(推荐)
|
||||
|
||||
在新 VPS 上运行:
|
||||
|
||||
```bash
|
||||
# 一键安装
|
||||
curl -fsSL https://ben:8d7d70f324796be650b79415303c31f567bf459b@gitea.tailnet-68f9.ts.net/ben/mgmt/raw/branch/main/configuration/zsh/quick-install.sh | bash
|
||||
```
|
||||
|
||||
### 方法二:手动安装
|
||||
|
||||
1. 克隆仓库:
|
||||
```bash
|
||||
git clone https://ben:8d7d70f324796be650b79415303c31f567bf459b@gitea.tailnet-68f9.ts.net/ben/mgmt.git /root/mgmt
|
||||
```
|
||||
|
||||
2. 运行安装脚本:
|
||||
```bash
|
||||
cd /root/mgmt
|
||||
chmod +x configuration/zsh/install-zsh-config.sh
|
||||
./configuration/zsh/install-zsh-config.sh
|
||||
```
|
||||
|
||||
## 配置同步
|
||||
|
||||
安装完成后,可以使用以下命令同步最新配置:
|
||||
|
||||
```bash
|
||||
# 同步配置
|
||||
sync-zsh-config
|
||||
```
|
||||
|
||||
这个命令会:
|
||||
1. 从 Gitea 拉取最新配置
|
||||
2. 备份当前配置
|
||||
3. 部署新配置
|
||||
|
||||
## 包含的功能
|
||||
|
||||
### 插件
|
||||
- **git** - Git 集成
|
||||
- **docker** - Docker 支持
|
||||
- **ansible** - Ansible 支持
|
||||
- **terraform** - OpenTofu/Terraform 支持
|
||||
- **kubectl** - Kubernetes 支持
|
||||
- **zsh-autosuggestions** - 命令自动建议
|
||||
- **zsh-syntax-highlighting** - 语法高亮
|
||||
- **zsh-completions** - 增强补全
|
||||
|
||||
### 别名
|
||||
- **项目管理**: `mgmt-status`, `mgmt-deploy`, `mgmt-cleanup`
|
||||
- **Ansible**: `ansible-check`, `ansible-deploy`, `ansible-ping`
|
||||
- **OpenTofu**: `tofu-init`, `tofu-plan`, `tofu-apply`
|
||||
- **Docker**: `dps`, `dex`, `dlog`, `dclean`
|
||||
- **Kubernetes**: `k`, `kgp`, `kgs`, `kaf`
|
||||
- **Git**: `gs`, `ga`, `gc`, `gp`, `gl`
|
||||
- **系统**: `ll`, `la`, `ports`, `myip`
|
||||
|
||||
### 主题
|
||||
- **agnoster** - 功能丰富的主题,显示 Git 状态
|
||||
|
||||
## 更新配置
|
||||
|
||||
当您在主 VPS 上更新配置后:
|
||||
|
||||
1. 提交更改:
|
||||
```bash
|
||||
cd /root/mgmt
|
||||
git add configuration/zsh/
|
||||
git commit -m "Update zsh configuration"
|
||||
git push origin main
|
||||
```
|
||||
|
||||
2. 在其他 VPS 上同步:
|
||||
```bash
|
||||
sync-zsh-config
|
||||
```
|
||||
|
||||
## 自定义配置
|
||||
|
||||
如果您需要在特定 VPS 上添加自定义配置:
|
||||
|
||||
1. 编辑 `~/.zshrc` 文件
|
||||
2. 在文件末尾添加您的自定义配置
|
||||
3. 这些配置不会被同步脚本覆盖
|
||||
|
||||
## 故障排除
|
||||
|
||||
### 如果同步失败
|
||||
```bash
|
||||
# 检查网络连接
|
||||
ping gitea.tailnet-68f9.ts.net
|
||||
|
||||
# 手动拉取
|
||||
cd /root/mgmt
|
||||
git pull origin main
|
||||
```
|
||||
|
||||
### 如果别名不工作
|
||||
```bash
|
||||
# 重新加载配置
|
||||
source ~/.zshrc
|
||||
|
||||
# 检查别名
|
||||
alias | grep <alias-name>
|
||||
```
|
||||
|
||||
### 如果插件不工作
|
||||
```bash
|
||||
# 检查插件目录
|
||||
ls ~/.oh-my-zsh/plugins/
|
||||
ls ~/.oh-my-zsh/custom/plugins/
|
||||
```
|
||||
|
||||
## 安全说明
|
||||
|
||||
- 此配置包含访问 Gitea 的凭据
|
||||
- 请确保只在可信的 VPS 上使用
|
||||
- 建议定期更新访问令牌
|
||||
|
||||
## 支持
|
||||
|
||||
如有问题,请检查:
|
||||
1. 网络连接是否正常
|
||||
2. Git 凭据是否正确
|
||||
3. 依赖包是否已安装
|
||||
4. 权限是否正确
|
||||
|
|
@ -0,0 +1,256 @@
|
|||
#!/bin/bash
|
||||
|
||||
# ZSH 配置安装脚本
|
||||
# 用于在其他 VPS 上安装和同步 oh-my-zsh 配置
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# 颜色定义
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
# 日志函数
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_warning() {
|
||||
echo -e "${YELLOW}[WARNING]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# 检查是否为 root 用户
|
||||
check_root() {
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
log_error "此脚本需要 root 权限运行"
|
||||
exit 1
|
||||
fi
|
||||
}
|
||||
|
||||
# 安装依赖
|
||||
install_dependencies() {
|
||||
log_info "安装依赖包..."
|
||||
|
||||
# 更新包列表
|
||||
apt update
|
||||
|
||||
# 安装必要的包
|
||||
apt install -y \
|
||||
zsh \
|
||||
git \
|
||||
curl \
|
||||
wget \
|
||||
htop \
|
||||
tree \
|
||||
jq \
|
||||
tmux \
|
||||
fonts-powerline \
|
||||
fontconfig
|
||||
|
||||
log_success "依赖包安装完成"
|
||||
}
|
||||
|
||||
# 安装 oh-my-zsh
|
||||
install_oh_my_zsh() {
|
||||
log_info "安装 oh-my-zsh..."
|
||||
|
||||
if [[ -d "$HOME/.oh-my-zsh" ]]; then
|
||||
log_warning "oh-my-zsh 已安装,跳过安装步骤"
|
||||
return 0
|
||||
fi
|
||||
|
||||
# 安装 oh-my-zsh
|
||||
RUNZSH=no CHSH=no sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"
|
||||
|
||||
log_success "oh-my-zsh 安装完成"
|
||||
}
|
||||
|
||||
# 安装自定义插件
|
||||
install_custom_plugins() {
|
||||
log_info "安装自定义插件..."
|
||||
|
||||
local custom_dir="$HOME/.oh-my-zsh/custom/plugins"
|
||||
|
||||
# zsh-autosuggestions
|
||||
if [[ ! -d "$custom_dir/zsh-autosuggestions" ]]; then
|
||||
log_info "安装 zsh-autosuggestions..."
|
||||
git clone https://github.com/zsh-users/zsh-autosuggestions "$custom_dir/zsh-autosuggestions"
|
||||
fi
|
||||
|
||||
# zsh-syntax-highlighting
|
||||
if [[ ! -d "$custom_dir/zsh-syntax-highlighting" ]]; then
|
||||
log_info "安装 zsh-syntax-highlighting..."
|
||||
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git "$custom_dir/zsh-syntax-highlighting"
|
||||
fi
|
||||
|
||||
# zsh-completions
|
||||
if [[ ! -d "$custom_dir/zsh-completions" ]]; then
|
||||
log_info "安装 zsh-completions..."
|
||||
git clone https://github.com/zsh-users/zsh-completions "$custom_dir/zsh-completions"
|
||||
fi
|
||||
|
||||
log_success "自定义插件安装完成"
|
||||
}
|
||||
|
||||
# 部署配置文件
|
||||
deploy_configs() {
|
||||
log_info "部署配置文件..."
|
||||
|
||||
local script_dir="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
|
||||
|
||||
# 备份现有配置
|
||||
if [[ -f "$HOME/.zshrc" ]]; then
|
||||
log_info "备份现有 .zshrc..."
|
||||
cp "$HOME/.zshrc" "$HOME/.zshrc.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
fi
|
||||
|
||||
# 部署 .zshrc
|
||||
if [[ -f "$script_dir/zshrc.template" ]]; then
|
||||
log_info "部署 .zshrc 配置..."
|
||||
cp "$script_dir/zshrc.template" "$HOME/.zshrc"
|
||||
else
|
||||
log_error "找不到 zshrc.template 文件"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 部署自定义配置
|
||||
if [[ -d "$script_dir/oh-my-zsh-custom" ]]; then
|
||||
log_info "部署自定义 oh-my-zsh 配置..."
|
||||
# 只复制非 git 仓库的文件
|
||||
find "$script_dir/oh-my-zsh-custom" -type f -not -path "*/.git/*" -exec cp --parents {} "$HOME/.oh-my-zsh/custom/" \;
|
||||
fi
|
||||
|
||||
log_success "配置文件部署完成"
|
||||
}
|
||||
|
||||
# 设置默认 shell
|
||||
set_default_shell() {
|
||||
log_info "设置 zsh 为默认 shell..."
|
||||
|
||||
# 检查 zsh 是否在 /etc/shells 中
|
||||
if ! grep -q "$(which zsh)" /etc/shells; then
|
||||
log_info "添加 zsh 到 /etc/shells..."
|
||||
echo "$(which zsh)" >> /etc/shells
|
||||
fi
|
||||
|
||||
# 设置默认 shell
|
||||
chsh -s "$(which zsh)"
|
||||
|
||||
log_success "默认 shell 设置为 zsh"
|
||||
}
|
||||
|
||||
# 创建同步脚本
|
||||
create_sync_script() {
|
||||
log_info "创建同步脚本..."
|
||||
|
||||
cat > /usr/local/bin/sync-zsh-config << 'EOF'
|
||||
#!/bin/bash
|
||||
|
||||
# ZSH 配置同步脚本
|
||||
# 从 Gitea 仓库拉取最新配置
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
MGMT_DIR="/root/mgmt"
|
||||
ZSH_CONFIG_DIR="$MGMT_DIR/configuration/zsh"
|
||||
|
||||
log_info() {
|
||||
echo -e "\033[0;34m[INFO]\033[0m $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "\033[0;32m[SUCCESS]\033[0m $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "\033[0;31m[ERROR]\033[0m $1"
|
||||
}
|
||||
|
||||
# 检查 mgmt 目录是否存在
|
||||
if [[ ! -d "$MGMT_DIR" ]]; then
|
||||
log_error "mgmt 目录不存在: $MGMT_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 进入 mgmt 目录
|
||||
cd "$MGMT_DIR"
|
||||
|
||||
# 拉取最新配置
|
||||
log_info "拉取最新配置..."
|
||||
git pull origin main
|
||||
|
||||
# 检查 zsh 配置目录
|
||||
if [[ ! -d "$ZSH_CONFIG_DIR" ]]; then
|
||||
log_error "zsh 配置目录不存在: $ZSH_CONFIG_DIR"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 备份当前配置
|
||||
if [[ -f "$HOME/.zshrc" ]]; then
|
||||
log_info "备份当前配置..."
|
||||
cp "$HOME/.zshrc" "$HOME/.zshrc.backup.$(date +%Y%m%d_%H%M%S)"
|
||||
fi
|
||||
|
||||
# 部署新配置
|
||||
log_info "部署新配置..."
|
||||
cp "$ZSH_CONFIG_DIR/zshrc.template" "$HOME/.zshrc"
|
||||
|
||||
if [[ -d "$ZSH_CONFIG_DIR/oh-my-zsh-custom" ]]; then
|
||||
cp -r "$ZSH_CONFIG_DIR/oh-my-zsh-custom"/* "$HOME/.oh-my-zsh/custom/"
|
||||
fi
|
||||
|
||||
log_success "ZSH 配置同步完成!"
|
||||
log_info "请运行 'source ~/.zshrc' 或重新登录以应用新配置"
|
||||
EOF
|
||||
|
||||
chmod +x /usr/local/bin/sync-zsh-config
|
||||
|
||||
log_success "同步脚本创建完成: /usr/local/bin/sync-zsh-config"
|
||||
}
|
||||
|
||||
# 显示使用说明
|
||||
show_usage() {
|
||||
log_success "ZSH 配置安装完成!"
|
||||
echo ""
|
||||
log_info "使用方法:"
|
||||
echo " 1. 重新登录或运行: source ~/.zshrc"
|
||||
echo " 2. 同步配置: sync-zsh-config"
|
||||
echo " 3. 查看别名: alias"
|
||||
echo ""
|
||||
log_info "可用命令:"
|
||||
echo " - mgmt-status, mgmt-deploy, mgmt-cleanup"
|
||||
echo " - ansible-check, ansible-deploy, ansible-ping"
|
||||
echo " - tofu-init, tofu-plan, tofu-apply"
|
||||
echo " - dps, dex, dlog (Docker)"
|
||||
echo " - k, kgp, kgs (Kubernetes)"
|
||||
echo ""
|
||||
}
|
||||
|
||||
# 主函数
|
||||
main() {
|
||||
log_info "开始安装 ZSH 配置..."
|
||||
|
||||
check_root
|
||||
install_dependencies
|
||||
install_oh_my_zsh
|
||||
install_custom_plugins
|
||||
deploy_configs
|
||||
set_default_shell
|
||||
create_sync_script
|
||||
show_usage
|
||||
|
||||
log_success "安装完成!"
|
||||
}
|
||||
|
||||
# 运行主函数
|
||||
main "$@"
|
||||
|
|
@ -0,0 +1,242 @@
|
|||
# =============================================================================
|
||||
# CUSTOM ALIASES FOR MANAGEMENT SYSTEM
|
||||
# =============================================================================
|
||||
|
||||
# Project Management
|
||||
alias mgmt='cd /root/mgmt'
|
||||
alias mgmt-status='cd /root/mgmt && ./mgmt.sh status'
|
||||
alias mgmt-deploy='cd /root/mgmt && ./mgmt.sh deploy'
|
||||
alias mgmt-cleanup='cd /root/mgmt && ./mgmt.sh cleanup'
|
||||
alias mgmt-swarm='cd /root/mgmt && ./mgmt.sh swarm'
|
||||
alias mgmt-tofu='cd /root/mgmt && ./mgmt.sh tofu'
|
||||
|
||||
# Ansible Management
|
||||
alias ansible-check='cd /root/mgmt/configuration && ansible-playbook --syntax-check'
|
||||
alias ansible-deploy='cd /root/mgmt/configuration && ansible-playbook -i inventories/production/inventory.ini'
|
||||
alias ansible-ping='cd /root/mgmt/configuration && ansible -i inventories/production/inventory.ini all -m ping'
|
||||
alias ansible-vault='cd /root/mgmt/configuration && ansible-vault'
|
||||
alias ansible-galaxy='cd /root/mgmt/configuration && ansible-galaxy'
|
||||
|
||||
# OpenTofu/Terraform Management
|
||||
alias tofu-init='cd /root/mgmt/tofu/environments/dev && tofu init'
|
||||
alias tofu-plan='cd /root/mgmt/tofu/environments/dev && tofu plan -var-file="terraform.tfvars"'
|
||||
alias tofu-apply='cd /root/mgmt/tofu/environments/dev && tofu apply -var-file="terraform.tfvars"'
|
||||
alias tofu-destroy='cd /root/mgmt/tofu/environments/dev && tofu destroy -var-file="terraform.tfvars"'
|
||||
alias tofu-output='cd /root/mgmt/tofu/environments/dev && tofu output'
|
||||
alias tofu-validate='cd /root/mgmt/tofu/environments/dev && tofu validate'
|
||||
alias tofu-fmt='cd /root/mgmt/tofu/environments/dev && tofu fmt -recursive'
|
||||
|
||||
# Docker Management
|
||||
alias d='docker'
|
||||
alias dc='docker-compose'
|
||||
alias dps='docker ps'
|
||||
alias dpsa='docker ps -a'
|
||||
alias di='docker images'
|
||||
alias dex='docker exec -it'
|
||||
alias dlog='docker logs -f'
|
||||
alias dstop='docker stop'
|
||||
alias dstart='docker start'
|
||||
alias drm='docker rm'
|
||||
alias drmi='docker rmi'
|
||||
alias dclean='docker system prune -f'
|
||||
alias dbuild='docker build'
|
||||
alias drun='docker run'
|
||||
alias dpull='docker pull'
|
||||
alias dpush='docker push'
|
||||
|
||||
# Docker Swarm Management
|
||||
alias dswarm='docker swarm'
|
||||
alias dstack='docker stack'
|
||||
alias dservice='docker service'
|
||||
alias dnode='docker node'
|
||||
alias dnetwork='docker network'
|
||||
alias dsecret='docker secret'
|
||||
alias dconfig='docker config'
|
||||
alias dstack-ls='docker stack ls'
|
||||
alias dstack-rm='docker stack rm'
|
||||
alias dstack-deploy='docker stack deploy'
|
||||
alias dservice-ls='docker service ls'
|
||||
alias dservice-ps='docker service ps'
|
||||
alias dservice-logs='docker service logs'
|
||||
|
||||
# Kubernetes Management
|
||||
alias k='kubectl'
|
||||
alias kgp='kubectl get pods'
|
||||
alias kgs='kubectl get services'
|
||||
alias kgd='kubectl get deployments'
|
||||
alias kgn='kubectl get nodes'
|
||||
alias kgi='kubectl get ingress'
|
||||
alias kgc='kubectl get configmaps'
|
||||
alias kgs='kubectl get secrets'
|
||||
alias kdp='kubectl describe pod'
|
||||
alias kds='kubectl describe service'
|
||||
alias kdd='kubectl describe deployment'
|
||||
alias kdn='kubectl describe node'
|
||||
alias kdi='kubectl describe ingress'
|
||||
alias kaf='kubectl apply -f'
|
||||
alias kdf='kubectl delete -f'
|
||||
alias kl='kubectl logs -f'
|
||||
alias ke='kubectl edit'
|
||||
alias kx='kubectl exec -it'
|
||||
alias kctx='kubectl config current-context'
|
||||
alias kuse='kubectl config use-context'
|
||||
|
||||
# Git Management
|
||||
alias gs='git status'
|
||||
alias ga='git add'
|
||||
alias gc='git commit'
|
||||
alias gp='git push'
|
||||
alias gl='git pull'
|
||||
alias gd='git diff'
|
||||
alias gb='git branch'
|
||||
alias gco='git checkout'
|
||||
alias gcom='git checkout main'
|
||||
alias gcod='git checkout develop'
|
||||
alias gst='git stash'
|
||||
alias gstp='git stash pop'
|
||||
alias gstl='git stash list'
|
||||
alias gstc='git stash clear'
|
||||
alias gcl='git clone'
|
||||
alias gfe='git fetch'
|
||||
alias gme='git merge'
|
||||
alias gr='git rebase'
|
||||
alias grc='git rebase --continue'
|
||||
alias gra='git rebase --abort'
|
||||
alias gres='git reset'
|
||||
alias gresh='git reset --hard'
|
||||
alias gress='git reset --soft'
|
||||
|
||||
# System Management
|
||||
alias ll='ls -alF'
|
||||
alias la='ls -A'
|
||||
alias l='ls -CF'
|
||||
alias ..='cd ..'
|
||||
alias ...='cd ../..'
|
||||
alias ....='cd ../../..'
|
||||
alias grep='grep --color=auto'
|
||||
alias fgrep='fgrep --color=auto'
|
||||
alias egrep='egrep --color=auto'
|
||||
alias ports='netstat -tuln'
|
||||
alias myip='curl -s https://httpbin.org/ip | jq -r .origin'
|
||||
alias speedtest='curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3'
|
||||
alias psg='ps aux | grep'
|
||||
alias top='htop'
|
||||
alias cp='cp -i'
|
||||
alias mv='mv -i'
|
||||
alias rm='rm -i'
|
||||
alias mkdir='mkdir -pv'
|
||||
|
||||
# Network Management
|
||||
alias ping='ping -c 4'
|
||||
alias traceroute='traceroute -n'
|
||||
alias nmap='nmap -sS -O'
|
||||
alias ss='ss -tuln'
|
||||
|
||||
# File Operations
|
||||
alias find='find . -name'
|
||||
alias locate='locate -i'
|
||||
alias which='which -a'
|
||||
alias whereis='whereis -b'
|
||||
|
||||
# Text Processing
|
||||
alias cat='cat -n'
|
||||
alias less='less -R'
|
||||
alias more='more -R'
|
||||
alias head='head -n 20'
|
||||
alias tail='tail -n 20'
|
||||
alias wc='wc -l'
|
||||
|
||||
# Archive Operations
|
||||
alias tar='tar -v'
|
||||
alias zip='zip -r'
|
||||
alias unzip='unzip -l'
|
||||
alias gzip='gzip -v'
|
||||
alias gunzip='gunzip -v'
|
||||
|
||||
# Process Management
|
||||
alias jobs='jobs -l'
|
||||
alias bg='bg %'
|
||||
alias fg='fg %'
|
||||
alias kill='kill -9'
|
||||
alias pkill='pkill -f'
|
||||
|
||||
# Environment
|
||||
alias env='env | sort'
|
||||
alias set='set | sort'
|
||||
alias unset='unset'
|
||||
alias export='export'
|
||||
alias source='source'
|
||||
|
||||
# History
|
||||
alias h='history'
|
||||
alias hg='history | grep'
|
||||
alias hc='history -c'
|
||||
|
||||
# Directory Navigation
|
||||
alias cd..='cd ..'
|
||||
alias cd...='cd ../..'
|
||||
alias cd....='cd ../../..'
|
||||
alias cd-='cd -'
|
||||
alias cd~='cd ~'
|
||||
alias cd/='cd /'
|
||||
|
||||
# Quick Access
|
||||
alias vim='vim'
|
||||
alias nano='nano'
|
||||
alias emacs='emacs'
|
||||
alias code='code'
|
||||
alias subl='subl'
|
||||
|
||||
# Monitoring
|
||||
alias df='df -h'
|
||||
alias du='du -h'
|
||||
alias free='free -h'
|
||||
alias meminfo='cat /proc/meminfo'
|
||||
alias cpuinfo='cat /proc/cpuinfo'
|
||||
alias uptime='uptime -p'
|
||||
|
||||
# Security
|
||||
alias chmod='chmod -v'
|
||||
alias chown='chown -v'
|
||||
alias chgrp='chgrp -v'
|
||||
alias passwd='passwd'
|
||||
alias su='su -'
|
||||
alias sudo='sudo -E'
|
||||
|
||||
# Development
|
||||
alias make='make -j$(nproc)'
|
||||
alias cmake='cmake -DCMAKE_BUILD_TYPE=Release'
|
||||
alias gcc='gcc -Wall -Wextra'
|
||||
alias g++='g++ -Wall -Wextra'
|
||||
alias python='python3'
|
||||
alias pip='pip3'
|
||||
alias node='node'
|
||||
alias npm='npm'
|
||||
alias yarn='yarn'
|
||||
|
||||
# Logs
|
||||
alias journal='journalctl -f'
|
||||
alias syslog='tail -f /var/log/syslog'
|
||||
alias auth='tail -f /var/log/auth.log'
|
||||
alias kern='tail -f /var/log/kern.log'
|
||||
alias mail='tail -f /var/log/mail.log'
|
||||
|
||||
# Backup
|
||||
alias backup='tar -czf backup-$(date +%Y%m%d-%H%M%S).tar.gz'
|
||||
alias restore='tar -xzf'
|
||||
|
||||
# Cleanup
|
||||
alias clean='rm -rf ~/.cache/* ~/.tmp/* /tmp/*'
|
||||
alias clean-docker='docker system prune -af --volumes'
|
||||
alias clean-k8s='kubectl delete pods --field-selector=status.phase=Succeeded'
|
||||
alias clean-ansible='rm -rf ~/.ansible/tmp/*'
|
||||
|
||||
# Information
|
||||
alias info='uname -a'
|
||||
alias whoami='whoami'
|
||||
alias id='id'
|
||||
alias groups='groups'
|
||||
alias users='users'
|
||||
alias w='w'
|
||||
alias who='who'
|
||||
alias last='last -n 10'
|
||||
|
|
@ -0,0 +1,12 @@
|
|||
# Put files in this folder to add your own custom functionality.
|
||||
# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization
|
||||
#
|
||||
# Files in the custom/ directory will be:
|
||||
# - loaded automatically by the init script, in alphabetical order
|
||||
# - loaded last, after all built-ins in the lib/ directory, to override them
|
||||
# - ignored by git by default
|
||||
#
|
||||
# Example: add custom/shortcuts.zsh for shortcuts to your local projects
|
||||
#
|
||||
# brainstormr=~/Projects/development/planetargon/brainstormr
|
||||
# cd $brainstormr
|
||||
|
|
@ -0,0 +1,3 @@
|
|||
# Add your own custom plugins in the custom/plugins directory. Plugins placed
|
||||
# here will override ones with the same name in the main plugins directory.
|
||||
# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-plugins
|
||||
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 85919cd1ffa7d2d5412f6d3fe437ebdbeeec4fc5
|
||||
|
|
@ -0,0 +1 @@
|
|||
Subproject commit d08cee09cecdc2d95bf501183597411a7632be7c
|
||||
|
|
@ -0,0 +1 @@
|
|||
Subproject commit 5eb677bb0fa9a3e60f0eff031dc13926e093df92
|
||||
|
|
@ -0,0 +1,6 @@
|
|||
# Put your custom themes in this folder.
|
||||
# See: https://github.com/ohmyzsh/ohmyzsh/wiki/Customization#overriding-and-adding-themes
|
||||
#
|
||||
# Example:
|
||||
|
||||
PROMPT="%{$fg[red]%}%n%{$reset_color%}@%{$fg[blue]%}%m %{$fg[yellow]%}%~ %{$reset_color%}%% "
|
||||
|
|
@ -0,0 +1,56 @@
|
|||
#!/bin/bash
|
||||
|
||||
# 快速安装脚本 - 从 Gitea 仓库直接安装 ZSH 配置
|
||||
# 用法: curl -fsSL https://your-gitea.com/ben/mgmt/raw/branch/main/configuration/zsh/quick-install.sh | bash
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
# 颜色定义
|
||||
RED='\033[0;31m'
|
||||
GREEN='\033[0;32m'
|
||||
YELLOW='\033[1;33m'
|
||||
BLUE='\033[0;34m'
|
||||
NC='\033[0m'
|
||||
|
||||
log_info() {
|
||||
echo -e "${BLUE}[INFO]${NC} $1"
|
||||
}
|
||||
|
||||
log_success() {
|
||||
echo -e "${GREEN}[SUCCESS]${NC} $1"
|
||||
}
|
||||
|
||||
log_error() {
|
||||
echo -e "${RED}[ERROR]${NC} $1"
|
||||
}
|
||||
|
||||
# Gitea 仓库信息
|
||||
GITEA_URL="https://ben:8d7d70f324796be650b79415303c31f567bf459b@gitea.tailnet-68f9.ts.net/ben/mgmt.git"
|
||||
MGMT_DIR="/root/mgmt"
|
||||
|
||||
log_info "开始快速安装 ZSH 配置..."
|
||||
|
||||
# 检查 root 权限
|
||||
if [[ $EUID -ne 0 ]]; then
|
||||
log_error "此脚本需要 root 权限运行"
|
||||
exit 1
|
||||
fi
|
||||
|
||||
# 克隆或更新仓库
|
||||
if [[ -d "$MGMT_DIR" ]]; then
|
||||
log_info "更新现有仓库..."
|
||||
cd "$MGMT_DIR"
|
||||
git pull origin main
|
||||
else
|
||||
log_info "克隆仓库..."
|
||||
git clone "$GITEA_URL" "$MGMT_DIR"
|
||||
cd "$MGMT_DIR"
|
||||
fi
|
||||
|
||||
# 运行安装脚本
|
||||
log_info "运行 ZSH 配置安装脚本..."
|
||||
chmod +x "$MGMT_DIR/configuration/zsh/install-zsh-config.sh"
|
||||
"$MGMT_DIR/configuration/zsh/install-zsh-config.sh"
|
||||
|
||||
log_success "快速安装完成!"
|
||||
log_info "请重新登录或运行: source ~/.zshrc"
|
||||
|
|
@ -0,0 +1,260 @@
|
|||
# If you come from bash you might have to change your $PATH.
|
||||
# export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH
|
||||
|
||||
# Path to your Oh My Zsh installation.
|
||||
export ZSH="$HOME/.oh-my-zsh"
|
||||
|
||||
# Set name of the theme to load --- if set to "random", it will
|
||||
# load a random theme each time Oh My Zsh is loaded, in which case,
|
||||
# to know which specific one was loaded, run: echo $RANDOM_THEME
|
||||
# See https://github.com/ohmyzsh/ohmyzsh/wiki/Themes
|
||||
ZSH_THEME="agnoster"
|
||||
|
||||
# Set list of themes to pick from when loading at random
|
||||
# Setting this variable when ZSH_THEME=random will cause zsh to load
|
||||
# a theme from this variable instead of looking in $ZSH/themes/
|
||||
# If set to an empty array, this variable will have no effect.
|
||||
# ZSH_THEME_RANDOM_CANDIDATES=( "robbyrussell" "agnoster" )
|
||||
|
||||
# Uncomment the following line to use case-sensitive completion.
|
||||
# CASE_SENSITIVE="true"
|
||||
|
||||
# Uncomment the following line to use hyphen-insensitive completion.
|
||||
# Case-sensitive completion must be off. _ and - will be interchangeable.
|
||||
# HYPHEN_INSENSITIVE="true"
|
||||
|
||||
# Uncomment one of the following lines to change the auto-update behavior
|
||||
# zstyle ':omz:update' mode disabled # disable automatic updates
|
||||
# zstyle ':omz:update' mode auto # update automatically without asking
|
||||
zstyle ':omz:update' mode reminder # just remind me to update when it's time
|
||||
|
||||
# Uncomment the following line to change how often to auto-update (in days).
|
||||
# zstyle ':omz:update' frequency 13
|
||||
|
||||
# Uncomment the following line if pasting URLs and other text is messed up.
|
||||
# DISABLE_MAGIC_FUNCTIONS="true"
|
||||
|
||||
# Uncomment the following line to disable colors in ls.
|
||||
# DISABLE_LS_COLORS="true"
|
||||
|
||||
# Uncomment the following line to disable auto-setting terminal title.
|
||||
# DISABLE_AUTO_TITLE="true"
|
||||
|
||||
# Uncomment the following line to enable command auto-correction.
|
||||
# ENABLE_CORRECTION="true"
|
||||
|
||||
# Uncomment the following line to display red dots whilst waiting for completion.
|
||||
# You can also set it to another string to have that shown instead of the default red dots.
|
||||
# e.g. COMPLETION_WAITING_DOTS="%F{yellow}waiting...%f"
|
||||
# Caution: this setting can cause issues with multiline prompts in zsh < 5.7.1 (see #5765)
|
||||
# COMPLETION_WAITING_DOTS="true"
|
||||
|
||||
# Uncomment the following line if you want to disable marking untracked files
|
||||
# under VCS as dirty. This makes repository status check for large repositories
|
||||
# much, much faster.
|
||||
# DISABLE_UNTRACKED_FILES_DIRTY="true"
|
||||
|
||||
# Uncomment the following line if you want to change the command execution time
|
||||
# stamp shown in the history command output.
|
||||
# You can set one of the optional three formats:
|
||||
# "mm/dd/yyyy"|"dd.mm.yyyy"|"yyyy-mm-dd"
|
||||
# or set a custom format using the strftime function format specifications,
|
||||
# see 'man strftime' for details.
|
||||
# HIST_STAMPS="mm/dd/yyyy"
|
||||
|
||||
# Would you like to use another custom folder than $ZSH/custom?
|
||||
# ZSH_CUSTOM=/path/to/new-custom-folder
|
||||
|
||||
# Which plugins would you like to load?
|
||||
# Standard plugins can be found in $ZSH/plugins/
|
||||
# Custom plugins may be added to $ZSH_CUSTOM/plugins/
|
||||
# Example format: plugins=(rails git textmate ruby lighthouse)
|
||||
# Add wisely, as too many plugins slow down shell startup.
|
||||
plugins=(
|
||||
git
|
||||
docker
|
||||
docker-compose
|
||||
ansible
|
||||
terraform
|
||||
kubectl
|
||||
helm
|
||||
aws
|
||||
gcloud
|
||||
zsh-autosuggestions
|
||||
zsh-syntax-highlighting
|
||||
zsh-completions
|
||||
colored-man-pages
|
||||
command-not-found
|
||||
extract
|
||||
history-substring-search
|
||||
sudo
|
||||
systemd
|
||||
tmux
|
||||
vscode
|
||||
web-search
|
||||
z
|
||||
)
|
||||
|
||||
source $ZSH/oh-my-zsh.sh
|
||||
|
||||
# User configuration
|
||||
|
||||
# export MANPATH="/usr/local/man:$MANPATH"
|
||||
|
||||
# You may need to manually set your language environment
|
||||
# export LANG=en_US.UTF-8
|
||||
|
||||
# Preferred editor for local and remote sessions
|
||||
if [[ -n $SSH_CONNECTION ]]; then
|
||||
export EDITOR='vim'
|
||||
else
|
||||
export EDITOR='vim'
|
||||
fi
|
||||
|
||||
# Compilation flags
|
||||
# export ARCHFLAGS="-arch $(uname -m)"
|
||||
|
||||
# =============================================================================
|
||||
# CUSTOM CONFIGURATION FOR MANAGEMENT SYSTEM
|
||||
# =============================================================================
|
||||
|
||||
# Load proxy configuration if exists
|
||||
if [[ -f /root/mgmt/configuration/proxy.env ]]; then
|
||||
source /root/mgmt/configuration/proxy.env
|
||||
fi
|
||||
|
||||
# Project management aliases
|
||||
alias mgmt='cd /root/mgmt'
|
||||
alias mgmt-status='cd /root/mgmt && ./mgmt.sh status'
|
||||
alias mgmt-deploy='cd /root/mgmt && ./mgmt.sh deploy'
|
||||
alias mgmt-cleanup='cd /root/mgmt && ./mgmt.sh cleanup'
|
||||
|
||||
# Ansible aliases
|
||||
alias ansible-check='cd /root/mgmt/configuration && ansible-playbook --syntax-check'
|
||||
alias ansible-deploy='cd /root/mgmt/configuration && ansible-playbook -i inventories/production/inventory.ini'
|
||||
alias ansible-ping='cd /root/mgmt/configuration && ansible -i inventories/production/inventory.ini all -m ping'
|
||||
|
||||
# OpenTofu/Terraform aliases
|
||||
alias tofu-init='cd /root/mgmt/tofu/environments/dev && tofu init'
|
||||
alias tofu-plan='cd /root/mgmt/tofu/environments/dev && tofu plan -var-file="terraform.tfvars"'
|
||||
alias tofu-apply='cd /root/mgmt/tofu/environments/dev && tofu apply -var-file="terraform.tfvars"'
|
||||
alias tofu-destroy='cd /root/mgmt/tofu/environments/dev && tofu destroy -var-file="terraform.tfvars"'
|
||||
alias tofu-output='cd /root/mgmt/tofu/environments/dev && tofu output'
|
||||
|
||||
# Docker aliases
|
||||
alias d='docker'
|
||||
alias dc='docker-compose'
|
||||
alias dps='docker ps'
|
||||
alias dpsa='docker ps -a'
|
||||
alias di='docker images'
|
||||
alias dex='docker exec -it'
|
||||
alias dlog='docker logs -f'
|
||||
alias dstop='docker stop'
|
||||
alias dstart='docker start'
|
||||
alias drm='docker rm'
|
||||
alias drmi='docker rmi'
|
||||
alias dclean='docker system prune -f'
|
||||
|
||||
# Docker Swarm aliases
|
||||
alias dswarm='docker swarm'
|
||||
alias dstack='docker stack'
|
||||
alias dservice='docker service'
|
||||
alias dnode='docker node'
|
||||
alias dnetwork='docker network'
|
||||
alias dsecret='docker secret'
|
||||
alias dconfig='docker config'
|
||||
|
||||
# Kubernetes aliases
|
||||
alias k='kubectl'
|
||||
alias kgp='kubectl get pods'
|
||||
alias kgs='kubectl get services'
|
||||
alias kgd='kubectl get deployments'
|
||||
alias kgn='kubectl get nodes'
|
||||
alias kdp='kubectl describe pod'
|
||||
alias kds='kubectl describe service'
|
||||
alias kdd='kubectl describe deployment'
|
||||
alias kaf='kubectl apply -f'
|
||||
alias kdf='kubectl delete -f'
|
||||
alias kl='kubectl logs -f'
|
||||
|
||||
# Git aliases
|
||||
alias gs='git status'
|
||||
alias ga='git add'
|
||||
alias gc='git commit'
|
||||
alias gp='git push'
|
||||
alias gl='git pull'
|
||||
alias gd='git diff'
|
||||
alias gb='git branch'
|
||||
alias gco='git checkout'
|
||||
alias gcom='git checkout main'
|
||||
alias gcod='git checkout develop'
|
||||
alias gst='git stash'
|
||||
alias gstp='git stash pop'
|
||||
|
||||
# System aliases
|
||||
alias ll='ls -alF'
|
||||
alias la='ls -A'
|
||||
alias l='ls -CF'
|
||||
alias ..='cd ..'
|
||||
alias ...='cd ../..'
|
||||
alias ....='cd ../../..'
|
||||
alias grep='grep --color=auto'
|
||||
alias fgrep='fgrep --color=auto'
|
||||
alias egrep='egrep --color=auto'
|
||||
|
||||
# Network aliases
|
||||
alias ports='netstat -tuln'
|
||||
alias myip='curl -s https://httpbin.org/ip | jq -r .origin'
|
||||
alias speedtest='curl -s https://raw.githubusercontent.com/sivel/speedtest-cli/master/speedtest.py | python3'
|
||||
|
||||
# Process aliases
|
||||
alias psg='ps aux | grep'
|
||||
alias top='htop'
|
||||
|
||||
# File operations
|
||||
alias cp='cp -i'
|
||||
alias mv='mv -i'
|
||||
alias rm='rm -i'
|
||||
alias mkdir='mkdir -pv'
|
||||
|
||||
# History configuration
|
||||
HISTSIZE=10000
|
||||
SAVEHIST=10000
|
||||
HISTFILE=~/.zsh_history
|
||||
setopt HIST_VERIFY
|
||||
setopt SHARE_HISTORY
|
||||
setopt APPEND_HISTORY
|
||||
setopt INC_APPEND_HISTORY
|
||||
setopt HIST_IGNORE_DUPS
|
||||
setopt HIST_IGNORE_ALL_DUPS
|
||||
setopt HIST_REDUCE_BLANKS
|
||||
setopt HIST_IGNORE_SPACE
|
||||
|
||||
# Auto-completion configuration
|
||||
autoload -U compinit && compinit
|
||||
zstyle ':completion:*' matcher-list 'm:{a-zA-Z}={A-Za-z}'
|
||||
zstyle ':completion:*' list-colors "${(s.:.)LS_COLORS}"
|
||||
zstyle ':completion:*' menu select
|
||||
|
||||
# Key bindings
|
||||
bindkey '^[[A' history-substring-search-up
|
||||
bindkey '^[[B' history-substring-search-down
|
||||
bindkey '^[[1;5C' forward-word
|
||||
bindkey '^[[1;5D' backward-word
|
||||
|
||||
# Auto-suggestions configuration
|
||||
ZSH_AUTOSUGGEST_HIGHLIGHT_STYLE='fg=8'
|
||||
ZSH_AUTOSUGGEST_STRATEGY=(history completion)
|
||||
|
||||
# Syntax highlighting configuration
|
||||
ZSH_HIGHLIGHT_HIGHLIGHTERS=(main brackets pattern cursor)
|
||||
|
||||
# Welcome message
|
||||
echo "🚀 Management System Shell Ready!"
|
||||
echo "📁 Project: /root/mgmt"
|
||||
echo "🔧 Available commands: mgmt-status, mgmt-deploy, mgmt-cleanup"
|
||||
echo "🐳 Docker: d, dc, dps, dex, dlog"
|
||||
echo "☸️ Kubernetes: k, kgp, kgs, kaf, kdf"
|
||||
echo "🏗️ OpenTofu: tofu-init, tofu-plan, tofu-apply"
|
||||
echo "⚙️ Ansible: ansible-check, ansible-deploy, ansible-ping"
|
||||
echo ""
|
||||
Loading…
Reference in New Issue