Skip to content

Commit

Permalink
Backup on: Wed Sep 28 16:29:40 CST 2022
Browse files Browse the repository at this point in the history
  • Loading branch information
小翊 committed Sep 28, 2022
1 parent 613644e commit 1fde6de
Show file tree
Hide file tree
Showing 6 changed files with 127 additions and 88 deletions.
30 changes: 16 additions & 14 deletions backup.sh
Original file line number Diff line number Diff line change
@@ -1,34 +1,36 @@
#! /bin/bash

# 全局变量,填入项目地址
# HEAD
DIR=$HOME/dotfiles
export git=/usr/bin/git

switch_branch(){
echo "dir: $DIR"
# brew_backup
git checkout -b main > /tmp/tmplog
if grep -q "fatal: A branch named" /tmp/tmplog ; then
echo "create new branch"
else
echo "checkout to main"
git checkout main
fi
# backup my config
backup() {
echo "Backup ~/.zshrc to ~/dotfiles/macos/$(whoami)/zshrc"
cp ~/.zshrc ~/dotfiles/macos/$(whoami)/zshrc

echo "Backup brew bundle to ~/dotfiles/macos/$(whoami)/Brewfile"
brew bundle dump --describe --force --no-upgrade --file="~/dotfiles/macos/$(whoami)/Brewfile"

# echo "Backup brew to ~/dotfiles/brew/backup"
# sh -c $HOME/dotfiles/brew/backup.sh

# code --list-extensions > ~/dotfiles/_rc/exts.txt
}

# > Backup to Github
backup_to_github(){
msg='Backup on: '`date`
# echo $msg

git add $DIR
git add $DIR/macos
git commit -m "$msg"
git push --set-upstream origin main
git push
}

# switch_branch
# 备份
backup
# 备份到 github 要最后运行
backup_to_github

exit 0
41 changes: 41 additions & 0 deletions brew/install_backup.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
#! /bin/bash

# 全局变量
WD=`pwd`
# > 安装自动备份脚本到 contab
install_to_crontab() {
script="bash $WD/backup.sh"
# echo $script
crontab -l > /tmp/crontab_conf
if grep -q "no crontab" /tmp/crontab_conf ; then
# echo /tmp/crontab_conf
# manual
echo "自动添加失败,请尝试手动添加: "
echo
echo SHELL=$SHELL > crontab_conf
echo PATH=$PATH >> crontab_conf
echo "00 12 * * * $script > /tmp/dotfiles_Backup.log && osascript -e 'display notification \"$WD/brew/backup\" with title \"dotfiles 备份成功, 已上传至 GitHub\" '" >> crontab_conf
echo "运行 \$ crontab -e"

echo "插入以下内容: "
cat crontab_conf
exit 1
else
# echo "hav crontab"
# auto
crontab -l > crontab_conf
echo SHELL=$SHELL >> crontab_conf
echo PATH=$PATH >> crontab_conf
echo "00 12 * * * $script > /tmp/dotfiles_Backup.log && osascript -e 'display notification \"$WD/backup\" with title \"dotfiles 备份成功, 已上传至 GitHub\" '" >> crontab_conf
crontab crontab_conf && rm -f crontab_conf

echo "🎉 自动化备份脚本安装完成"
echo
echo "目前的 crontab 配置"
echo
crontab -l
exit 0
fi
}

install_to_crontab
4 changes: 2 additions & 2 deletions install_backup.sh
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ install_to_crontab() {
echo
echo SHELL=$SHELL > crontab_conf
echo PATH=$PATH >> crontab_conf
echo "00 12 * * * $script > /tmp/dotfiles_Backup.log && osascript -e 'display notification \"$WD/brew/backup\" with title \"dotfiles 备份成功, 已上传至 GitHub\" '" >> crontab_conf
echo "00 16 * * * $script > /tmp/dotfiles_Backup.log && osascript -e 'display notification \"$WD/brew/backup\" with title \"dotfiles 备份成功, 已上传至 GitHub\" '" >> crontab_conf
echo "运行 \$ crontab -e"

echo "插入以下内容: "
Expand All @@ -26,7 +26,7 @@ install_to_crontab() {
crontab -l > crontab_conf
echo SHELL=$SHELL >> crontab_conf
echo PATH=$PATH >> crontab_conf
echo "00 12 * * * $script > /tmp/dotfiles_Backup.log && osascript -e 'display notification \"$WD/backup\" with title \"dotfiles 备份成功, 已上传至 GitHub\" '" >> crontab_conf
echo "00 16 * * * $script > /tmp/dotfiles_Backup.log && osascript -e 'display notification \"$WD/backup\" with title \"dotfiles 备份成功, 已上传至 GitHub\" '" >> crontab_conf
crontab crontab_conf && rm -f crontab_conf

echo "🎉 自动化备份脚本安装完成"
Expand Down
53 changes: 4 additions & 49 deletions macos/Brewfile → macos/xiaoyi/Brewfile
Original file line number Diff line number Diff line change
@@ -1,67 +1,37 @@
tap "1password/tap"
tap "bigwig-club/brew"
tap "buo/cask-upgrade"
tap "cloudflare/cloudflare"
tap "github/gh"
tap "homebrew/bundle"
tap "homebrew/cask"
tap "homebrew/cask-fonts"
tap "homebrew/cask-versions"
tap "homebrew/core"
tap "homebrew/services"
# Shell extension to jump to frequently used directories
brew "autojump"
# Get a file from an HTTP, HTTPS or FTP server
brew "curl"
# View disk space usage and delete unwanted data, fast
brew "dua-cli"
# Distributed revision control system
brew "git"
# Development kit for the Java programming language
brew "openjdk"
# Interpreted, interactive, object-oriented programming language
brew "[email protected]"
# Fast and simple Node.js version manager
brew "fnm"
# User interface to the TELNET protocol
brew "telnet"
# Internet file retriever
brew "wget"
# Command-line helper for the 1Password password manager
cask "1password-cli"
cask "account-switcher"
# Transfer files from and to an Android smartphone
cask "android-file-transfer"
# Android SDK component
cask "android-platform-tools"
# Application uninstaller
cask "appcleaner"
# Tool to flash OS images to SD cards & USB drives
cask "balenaetcher"
# Tool to list all active shortcuts of the current application
cask "cheatsheet"
# Rule-based custom proxy with GUI based on clash
cask "clashx-pro"
# Voice and text chat software
cask "discord"
# Typeface made for developers
cask "font-jetbrains-mono"
# Developer targeted fonts with a high number of glyphs
cask "font-jetbrains-mono-nerd-font"
# GIT client
cask "fork"
# Tool to set light or dark appearance on a per-app basis
cask "gray"
# Free and open-source media player
cask "iina"
# Terminal emulator as alternative to Apple's Terminal app
cask "iterm2"
# File archiver
cask "keka"
# Helper application for the Keka file archiver
cask "kekaexternalhelper"
# Switch input method per application
cask "keyboardholder"
# Open-source firewall to block unknown outgoing connections
cask "lulu"
# Simple and elegant markdown editor
cask "mark-text"
# Tool to control external monitor brightness & volume
Expand All @@ -72,9 +42,6 @@ cask "mos"
cask "ngrok"
# App to write, plan, collaborate, and get organized
cask "notion"
cask "paper"
# Tool for uploading images
cask "picgo"
# QuickLook plug-in that renders source code with syntax highlighting
cask "qlcolorcode"
# Display image info and preview unsupported formats in QuickLook
Expand All @@ -90,26 +57,14 @@ cask "quicklook-json"
cask "quicklookase"
# Control your tools with a few keystrokes
cask "raycast"
# Tool to reverse the direction of scrolling
cask "scroll-reverser"
# Screenshot measurement and annotation tool
cask "shottr"
# Snip or pin screenshots
cask "snipaste"
# Music streaming service
cask "spotify"
# Network toolbox
cask "surge"
# System monitor for the menu bar
cask "stats"
# App to switch hosts
cask "switchhosts"
# Terminal emulator, SSH and serial client
cask "tabby"
# Messaging app with a focus on speed and security
cask "telegram"
# Finder extension for opening a terminal from the current directory
cask "termhere"
# General-purpose text editor
cask "textmate"
# Remote desktop application focusing on security
cask "vnc-viewer"
# Rust-based terminal
Expand Down
53 changes: 30 additions & 23 deletions macos/zshrc → macos/xiaoyi/zshrc
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,6 @@

export ZSH="$HOME/.oh-my-zsh"

export N_PREFIX=$HOME/.n
export PATH=$N_PREFIX/bin:$PATH

# 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
Expand Down Expand Up @@ -82,14 +79,13 @@ plugins=(
git
# osx
zsh-autosuggestions
# git
# zsh-syntax-highlighting
# fast-syntax-highlighting
F-Sy-H
zsh-gitcd
# zsh-completion will be added to FPATH directly
# zsh-completions
# zsh-z
zsh-z
# zsh-interactive-cd
fzf-tab
)
Expand All @@ -99,6 +95,11 @@ export NPM_CONFIG_PREFIX="$HOME/.npm-global"
# Create .npm-global folder if not exists
[[ ! -d "$HOME/.npm-global" ]] && mkdir -p $HOME/.npm-global

# export N_PREFIX=$HOME/.n
# export PATH=$N_PREFIX/bin:$PATH

eval "$(fnm env --use-on-cd)"

# Path should be set after fnm
export PATH="$HOME/bin:/usr/local/bin:/usr/local/sbin:$HOME/.yarn/bin:$NPM_CONFIG_PREFIX/bin:/usr/local/opt/openjdk/bin:/usr/local/opt/openjdk@8/bin:/opt/homebrew/bin:$PATH"

Expand Down Expand Up @@ -390,9 +391,15 @@ gig() { curl -L -s https://www.gitignore.io/api/$@;}

# backup my config
bk() {
cp ~/.zshrc ~/dotfiles/macos/zshrc
brew bundle dump --describe --force --no-upgrade --file="~/dotfiles/macos/Brewfile"
sh -c $HOME/dotfiles/brew/backup.sh
echo "Backup ~/.zshrc to ~/dotfiles/macos/$(whoami)/zshrc"
cp ~/.zshrc ~/dotfiles/macos/$(whoami)/zshrc

echo "Backup brew bundle to ~/dotfiles/macos/$(whoami)/Brewfile"
brew bundle dump --describe --force --no-upgrade --file="~/dotfiles/macos/$(whoami)/Brewfile"

# echo "Backup brew to ~/dotfiles/brew/backup"
# sh -c $HOME/dotfiles/brew/backup.sh

# code --list-extensions > ~/dotfiles/_rc/exts.txt
}

Expand Down Expand Up @@ -427,20 +434,20 @@ if (( $+commands[thefuck] )) &>/dev/null; then
fi

## Lazyload pyenv
if (( $+commands[pyenv] )) &>/dev/null; then
_sukka_lazyload_command_pyenv() {
export PATH="${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}" # pyenv init --path
eval "$(command pyenv init -)"
}
sukka_lazyload_add_command pyenv

_sukka_lazyload_completion_pyenv() {
source "${__SUKKA_HOMEBREW_PYENV_PREFIX}/completions/pyenv.zsh"
}
sukka_lazyload_add_completion pyenv

export PYENV_ROOT="${PYENV_ROOT:=${HOME}/.pyenv}"
fi
# if (( $+commands[pyenv] )) &>/dev/null; then
# _sukka_lazyload_command_pyenv() {
# export PATH="${PYENV_ROOT}/bin:${PYENV_ROOT}/shims:${PATH}" # pyenv init --path
# eval "$(command pyenv init -)"
# }
# sukka_lazyload_add_command pyenv

# _sukka_lazyload_completion_pyenv() {
# source "${__SUKKA_HOMEBREW_PYENV_PREFIX}/completions/pyenv.zsh"
# }
# sukka_lazyload_add_completion pyenv

# export PYENV_ROOT="${PYENV_ROOT:=${HOME}/.pyenv}"
# fi

# hexo completion
if (( $+commands[hexo] )) &>/dev/null; then
Expand Down Expand Up @@ -536,4 +543,4 @@ zstyle :bracketed-paste-magic paste-finish pastefinish


# autojump
[[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
# [[ -s $(brew --prefix)/etc/profile.d/autojump.sh ]] && . $(brew --prefix)/etc/profile.d/autojump.sh
34 changes: 34 additions & 0 deletions upload.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#! /bin/bash

# 全局变量,填入项目地址
# HEAD
DIR=$HOME/dotfiles
export git=/usr/bin/git

switch_branch(){
echo "dir: $DIR"
# brew_backup
git checkout -b main > /tmp/tmplog
if grep -q "fatal: A branch named" /tmp/tmplog ; then
echo "create new branch"
else
echo "checkout to main"
git checkout main
fi
}

# > Backup to Github
backup_to_github(){
msg='Backup on: '`date`
# echo $msg

git add $DIR
git commit -m "$msg"
git push --set-upstream origin main
git push
}

# switch_branch
# 备份到 github 要最后运行
backup_to_github
exit 0

0 comments on commit 1fde6de

Please sign in to comment.