diff --git a/backup.sh b/backup.sh index f1d324a..cc652e5 100755 --- a/backup.sh +++ b/backup.sh @@ -1,20 +1,20 @@ #! /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 @@ -22,13 +22,15 @@ 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 diff --git a/brew/install_backup.sh b/brew/install_backup.sh new file mode 100755 index 0000000..0113b9e --- /dev/null +++ b/brew/install_backup.sh @@ -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 diff --git a/install_backup.sh b/install_backup.sh index 0113b9e..4f22b83 100755 --- a/install_backup.sh +++ b/install_backup.sh @@ -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 "插入以下内容: " @@ -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 "🎉 自动化备份脚本安装完成" diff --git a/macos/Brewfile b/macos/xiaoyi/Brewfile similarity index 56% rename from macos/Brewfile rename to macos/xiaoyi/Brewfile index 7480b49..6af58f8 100644 --- a/macos/Brewfile +++ b/macos/xiaoyi/Brewfile @@ -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 "python@3.9" +# 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 @@ -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 @@ -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 diff --git a/macos/zshrc b/macos/xiaoyi/zshrc similarity index 93% rename from macos/zshrc rename to macos/xiaoyi/zshrc index 56a5d9e..b6cdc78 100644 --- a/macos/zshrc +++ b/macos/xiaoyi/zshrc @@ -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 @@ -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 ) @@ -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" @@ -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 } @@ -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 @@ -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 diff --git a/upload.sh b/upload.sh new file mode 100755 index 0000000..f1d324a --- /dev/null +++ b/upload.sh @@ -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