aboutsummaryrefslogtreecommitdiffhomepage
path: root/bin/init
diff options
context:
space:
mode:
authorHsieh Chin Fan <pham@topo.tw>2023-02-14 13:33:23 +0800
committerHsieh Chin Fan <pham@topo.tw>2023-02-14 13:33:23 +0800
commit6fae25b305d714b3ab7608fa003f1af9bf024545 (patch)
tree05507b2c0505659d2fd847ecce988dacab63a236 /bin/init
parent41ad31a2dee9ff912f222652f022b4c55cddcbf7 (diff)
Rename tools into bin
Diffstat (limited to 'bin/init')
-rwxr-xr-xbin/init/check_upstream24
-rwxr-xr-xbin/init/exit.sh5
-rwxr-xr-xbin/init/load-settings.sh70
-rwxr-xr-xbin/init/sync.sh37
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
7if [ ! -d "$1" ]; then
8 return 0
9fi
10
11head='dev'
12if [ $# -eq 2 ]
13then
14 head=$2
15fi
16
17cd "$1" && \
18git fetch origin && \
19if ! 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"
22fi
23
24echo "$(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 @@
1trap 'exit.sh' EXIT
2
3export SETTING_DIR=${SETTING_DIR:=$HOME/helper}
4export EDITOR=vim
5export TERM=xterm-256color
6export XDG_CONFIG_HOME=~/.config
7
8# Get current shell
9export shell=$(</proc/$$/cmdline sed -E 's/(.)-.+$/\1/' | tr -d '[\0\-]')
10shell=${shell##*/}
11
12# load custom aliases
13source $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
17BIN_DIR=$HOME/bin
18PATH=$BIN_DIR:$PATH
19mkdir -p $BIN_DIR
20find $BIN_DIR -xtype l -exec rm {} + 2>/dev/null
21find $SETTING_DIR/bin -type f -executable -exec realpath {} + | \
22xargs -I{} ln -sf {} $BIN_DIR
23
24# Mail
25MAIL=$HOME/Maildir
26
27# sync with important git repos
28setsid sync.sh
29
30# local
31PATH=$PATH:$HOME/.local/bin
32# go
33PATH=$PATH:$HOME/go/bin
34# android-studio
35PATH=$PATH:$HOME/android-studio/bin
36# cargo
37PATH=$PATH:$HOME/.cargo/bin
38# yarn
39PATH=$PATH:$HOME/.yarn/bin
40
41# fzf
42if which fzf &>/dev/null; then
43 fzf_preview() { fzf --preview 'cat {}'; }
44 source ~/.fzf.${shell} &>/dev/null
45fi
46
47# Set zsh or bash
48if [[ $- =~ 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
65fi
66
67# Working DIR
68[[ `pwd` == $HOME ]] && cd ~/Downloads
69
70true
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
4pidof git >/dev/null && exit 0
5
6# my repo
7sync() {
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}
13sync $SETTING_DIR &
14sync ~/log &
15sync ~/blog &
16sync ~/git/vps &
17sync ~/.task &
18sync ~/.password-store &
19sync ~/.vim/vim-init &
20sync ~/bean &
21
22while 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
29done &
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