diff options
| author | Hsieh Chin Fan <pham@topo.tw> | 2023-02-14 13:33:23 +0800 |
|---|---|---|
| committer | Hsieh Chin Fan <pham@topo.tw> | 2023-02-14 13:33:23 +0800 |
| commit | 6fae25b305d714b3ab7608fa003f1af9bf024545 (patch) | |
| tree | 05507b2c0505659d2fd847ecce988dacab63a236 /bin/init | |
| parent | 41ad31a2dee9ff912f222652f022b4c55cddcbf7 (diff) | |
Rename tools into bin
Diffstat (limited to 'bin/init')
| -rwxr-xr-x | bin/init/check_upstream | 24 | ||||
| -rwxr-xr-x | bin/init/exit.sh | 5 | ||||
| -rwxr-xr-x | bin/init/load-settings.sh | 70 | ||||
| -rwxr-xr-x | bin/init/sync.sh | 37 |
4 files changed, 136 insertions, 0 deletions
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 @@ | |||
| 1 | #! /bin/bash | ||
| 2 | |||
| 3 | # This script is for repo forked from others | ||
| 4 | # check $1(repo) if upstream branch origin/master is | ||
| 5 | # ahead of local branch $2(default to dev) | ||
| 6 | |||
| 7 | if [ ! -d "$1" ]; then | ||
| 8 | return 0 | ||
| 9 | fi | ||
| 10 | |||
| 11 | head='dev' | ||
| 12 | if [ $# -eq 2 ] | ||
| 13 | then | ||
| 14 | head=$2 | ||
| 15 | fi | ||
| 16 | |||
| 17 | cd "$1" && \ | ||
| 18 | git fetch origin && \ | ||
| 19 | if ! git rev-list "$head" | grep "$(git rev-parse origin/master)" > /dev/null; then | ||
| 20 | [[ $(git pull my) == 'Alrady up to date.' ]] || \ | ||
| 21 | echo "New commit at" "$1" | ||
| 22 | fi | ||
| 23 | |||
| 24 | 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 @@ | |||
| 1 | #! /usr/bin/env bash | ||
| 2 | |||
| 3 | #if [[ `cat /etc/hostname` != 'vultr' ]]; then | ||
| 4 | # rsync -a --delete ~/.thunderbird/ pham@topo.tw:~/.thunderbird & | ||
| 5 | #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 @@ | |||
| 1 | trap 'exit.sh' EXIT | ||
| 2 | |||
| 3 | export SETTING_DIR=${SETTING_DIR:=$HOME/helper} | ||
| 4 | export EDITOR=vim | ||
| 5 | export TERM=xterm-256color | ||
| 6 | export XDG_CONFIG_HOME=~/.config | ||
| 7 | |||
| 8 | # Get current shell | ||
| 9 | export shell=$(</proc/$$/cmdline sed -E 's/(.)-.+$/\1/' | tr -d '[\0\-]') | ||
| 10 | shell=${shell##*/} | ||
| 11 | |||
| 12 | # load custom aliases | ||
| 13 | source $SETTING_DIR/alias | ||
| 14 | [[ -d $SETTING_DIR/private ]] && for f in $SETTING_DIR/private/*; do source $f; done | ||
| 15 | |||
| 16 | # Add custom scripts into PATH | ||
| 17 | BIN_DIR=$HOME/bin | ||
| 18 | PATH=$BIN_DIR:$PATH | ||
| 19 | mkdir -p $BIN_DIR | ||
| 20 | find $BIN_DIR -xtype l -exec rm {} + 2>/dev/null | ||
| 21 | find $SETTING_DIR/bin -type f -executable -exec realpath {} + | \ | ||
| 22 | xargs -I{} ln -sf {} $BIN_DIR | ||
| 23 | |||
| 24 | |||
| 25 | MAIL=$HOME/Maildir | ||
| 26 | |||
| 27 | # sync with important git repos | ||
| 28 | setsid sync.sh | ||
| 29 | |||
| 30 | # local | ||
| 31 | PATH=$PATH:$HOME/.local/bin | ||
| 32 | # go | ||
| 33 | PATH=$PATH:$HOME/go/bin | ||
| 34 | # android-studio | ||
| 35 | PATH=$PATH:$HOME/android-studio/bin | ||
| 36 | # cargo | ||
| 37 | PATH=$PATH:$HOME/.cargo/bin | ||
| 38 | # yarn | ||
| 39 | PATH=$PATH:$HOME/.yarn/bin | ||
| 40 | |||
| 41 | # fzf | ||
| 42 | if which fzf &>/dev/null; then | ||
| 43 | fzf_preview() { fzf --preview 'cat {}'; } | ||
| 44 | source ~/.fzf.${shell} &>/dev/null | ||
| 45 | fi | ||
| 46 | |||
| 47 | # Set zsh or bash | ||
| 48 | if [[ $- =~ i ]]; then | ||
| 49 | if [[ $shell == zsh ]]; then | ||
| 50 | setopt extended_glob | ||
| 51 | fpath=($SETTING_DIR/zsh $fpath) | ||
| 52 | alias history='history -i' | ||
| 53 | autoload compinit; compinit | ||
| 54 | |||
| 55 | #autoload -U deer | ||
| 56 | #zle -N deer | ||
| 57 | #bindkey '\ek' deer | ||
| 58 | bindkey -s '\ek' 'fzf_preview ' | ||
| 59 | elif [[ $shell == bash ]]; then | ||
| 60 | shopt -s extglob | ||
| 61 | HISTTIMEFORMAT='%Y-%m-%d %T ' | ||
| 62 | |||
| 63 | bind -m emacs-standard -x '"\ek": fzf_preview' | ||
| 64 | fi | ||
| 65 | fi | ||
| 66 | |||
| 67 | # Working DIR | ||
| 68 | [[ `pwd` == $HOME ]] && cd ~/Downloads | ||
| 69 | |||
| 70 | 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 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # If git is working in other process, then don't sync again | ||
| 4 | pidof git >/dev/null && exit 0 | ||
| 5 | |||
| 6 | # my repo | ||
| 7 | sync() { | ||
| 8 | { | ||
| 9 | cd $1 && [[ -n `git remote -v` ]] || return | ||
| 10 | } 2>/dev/null | ||
| 11 | GIT_SSH_COMMAND="ssh -o ControlMaster=no" git pull --quiet || echo Has trouble when syncing `pwd` | ||
| 12 | } | ||
| 13 | sync $SETTING_DIR & | ||
| 14 | sync ~/log & | ||
| 15 | sync ~/blog & | ||
| 16 | sync ~/git/vps & | ||
| 17 | sync ~/.task & | ||
| 18 | sync ~/.password-store & | ||
| 19 | sync ~/.vim/vim-init & | ||
| 20 | sync ~/bean & | ||
| 21 | |||
| 22 | while true; do | ||
| 23 | if test $(jobs -r | wc -l) -gt 0; then | ||
| 24 | sleep 1; | ||
| 25 | else | ||
| 26 | which notify-send &>/dev/null && notify-send 'Repos synced' | ||
| 27 | break | ||
| 28 | fi | ||
| 29 | done & | ||
| 30 | |||
| 31 | # others repo | ||
| 32 | #check_upstream ~/git/tig || echo in `pwd` >/dev/tty & | ||
| 33 | |||
| 34 | # thunderbird | ||
| 35 | #if [[ `cat /etc/hostname` != 'vultr' ]]; then | ||
| 36 | # rsync -a pham@topo.tw:~/.thunderbird/ ~/.thunderbird & | ||
| 37 | #fi | ||