From 6fae25b305d714b3ab7608fa003f1af9bf024545 Mon Sep 17 00:00:00 2001 From: Hsieh Chin Fan Date: Tue, 14 Feb 2023 13:33:23 +0800 Subject: Rename tools into bin --- bin/init/check_upstream | 24 ++++++++++++++++ bin/init/exit.sh | 5 ++++ bin/init/load-settings.sh | 70 +++++++++++++++++++++++++++++++++++++++++++++++ bin/init/sync.sh | 37 +++++++++++++++++++++++++ 4 files changed, 136 insertions(+) create mode 100755 bin/init/check_upstream create mode 100755 bin/init/exit.sh create mode 100755 bin/init/load-settings.sh create mode 100755 bin/init/sync.sh (limited to 'bin/init') diff --git a/bin/init/check_upstream b/bin/init/check_upstream new file mode 100755 index 0000000..fa6d277 --- /dev/null +++ b/bin/init/check_upstream @@ -0,0 +1,24 @@ +#! /bin/bash + +# This script is for repo forked from others +# check $1(repo) if upstream branch origin/master is +# ahead of local branch $2(default to dev) + +if [ ! -d "$1" ]; then + return 0 +fi + +head='dev' +if [ $# -eq 2 ] +then + head=$2 +fi + +cd "$1" && \ +git fetch origin && \ +if ! git rev-list "$head" | grep "$(git rev-parse origin/master)" > /dev/null; then + [[ $(git pull my) == 'Alrady up to date.' ]] || \ + echo "New commit at" "$1" +fi + +echo "$(date)" check "$1" >> "$SETTING_DIR/log" || echo error happens when check upstream at $1 diff --git a/bin/init/exit.sh b/bin/init/exit.sh new file mode 100755 index 0000000..3723670 --- /dev/null +++ b/bin/init/exit.sh @@ -0,0 +1,5 @@ +#! /usr/bin/env bash + +#if [[ `cat /etc/hostname` != 'vultr' ]]; then +# rsync -a --delete ~/.thunderbird/ pham@topo.tw:~/.thunderbird & +#fi diff --git a/bin/init/load-settings.sh b/bin/init/load-settings.sh new file mode 100755 index 0000000..fcd6494 --- /dev/null +++ b/bin/init/load-settings.sh @@ -0,0 +1,70 @@ +trap 'exit.sh' EXIT + +export SETTING_DIR=${SETTING_DIR:=$HOME/helper} +export EDITOR=vim +export TERM=xterm-256color +export XDG_CONFIG_HOME=~/.config + +# Get current shell +export shell=$(/dev/null +find $SETTING_DIR/bin -type f -executable -exec realpath {} + | \ +xargs -I{} ln -sf {} $BIN_DIR + +# Mail +MAIL=$HOME/Maildir + +# sync with important git repos +setsid sync.sh + +# local +PATH=$PATH:$HOME/.local/bin +# go +PATH=$PATH:$HOME/go/bin +# android-studio +PATH=$PATH:$HOME/android-studio/bin +# cargo +PATH=$PATH:$HOME/.cargo/bin +# yarn +PATH=$PATH:$HOME/.yarn/bin + +# fzf +if which fzf &>/dev/null; then + fzf_preview() { fzf --preview 'cat {}'; } + source ~/.fzf.${shell} &>/dev/null +fi + +# Set zsh or bash +if [[ $- =~ i ]]; then + if [[ $shell == zsh ]]; then + setopt extended_glob + fpath=($SETTING_DIR/zsh $fpath) + alias history='history -i' + autoload compinit; compinit + + #autoload -U deer + #zle -N deer + #bindkey '\ek' deer + bindkey -s '\ek' 'fzf_preview ' + elif [[ $shell == bash ]]; then + shopt -s extglob + HISTTIMEFORMAT='%Y-%m-%d %T ' + + bind -m emacs-standard -x '"\ek": fzf_preview' + fi +fi + +# Working DIR +[[ `pwd` == $HOME ]] && cd ~/Downloads + +true diff --git a/bin/init/sync.sh b/bin/init/sync.sh new file mode 100755 index 0000000..bcd7bed --- /dev/null +++ b/bin/init/sync.sh @@ -0,0 +1,37 @@ +#!/bin/bash + +# If git is working in other process, then don't sync again +pidof git >/dev/null && exit 0 + +# my repo +sync() { + { + cd $1 && [[ -n `git remote -v` ]] || return + } 2>/dev/null + GIT_SSH_COMMAND="ssh -o ControlMaster=no" git pull --quiet || echo Has trouble when syncing `pwd` +} +sync $SETTING_DIR & +sync ~/log & +sync ~/blog & +sync ~/git/vps & +sync ~/.task & +sync ~/.password-store & +sync ~/.vim/vim-init & +sync ~/bean & + +while true; do + if test $(jobs -r | wc -l) -gt 0; then + sleep 1; + else + which notify-send &>/dev/null && notify-send 'Repos synced' + break + fi +done & + +# others repo +#check_upstream ~/git/tig || echo in `pwd` >/dev/tty & + +# thunderbird +#if [[ `cat /etc/hostname` != 'vultr' ]]; then +# rsync -a pham@topo.tw:~/.thunderbird/ ~/.thunderbird & +#fi -- cgit v1.2.3-70-g09d2