diff options
Diffstat (limited to 'tools/init')
| -rwxr-xr-x | tools/init/check_upstream | 24 | ||||
| -rwxr-xr-x | tools/init/load-settings.sh | 31 | ||||
| -rwxr-xr-x | tools/init/sync.sh | 11 |
3 files changed, 66 insertions, 0 deletions
diff --git a/tools/init/check_upstream b/tools/init/check_upstream new file mode 100755 index 0000000..e9e8841 --- /dev/null +++ b/tools/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" | ||
diff --git a/tools/init/load-settings.sh b/tools/init/load-settings.sh new file mode 100755 index 0000000..041941a --- /dev/null +++ b/tools/init/load-settings.sh | |||
| @@ -0,0 +1,31 @@ | |||
| 1 | if [[ $0 == 'zsh' ]]; then | ||
| 2 | setopt extended_glob | ||
| 3 | elif [[ $0 == 'bash' ]]; then | ||
| 4 | shopt -s extglob | ||
| 5 | fi | ||
| 6 | |||
| 7 | # set default editor | ||
| 8 | export EDITOR=vim | ||
| 9 | |||
| 10 | # load custom aliases | ||
| 11 | SETTING_DIR=${SETTING_DIR:=$HOME/settings} | ||
| 12 | source $SETTING_DIR/alias | ||
| 13 | |||
| 14 | # Add custom scripts into PATH | ||
| 15 | BIN_DIR=$HOME/bin | ||
| 16 | PATH=$PATH:$BIN_DIR | ||
| 17 | mkdir -p $BIN_DIR | ||
| 18 | find $BIN_DIR -xtype l | xargs rm 2>/dev/null || true | ||
| 19 | |||
| 20 | find $SETTING_DIR/tools -type f -executable | \ | ||
| 21 | xargs realpath | xargs -I{} ln -sf {} $BIN_DIR | ||
| 22 | |||
| 23 | # load custom functions | ||
| 24 | OSM_UTIL_DIR=$SETTING_DIR/tools/osm | ||
| 25 | source $OSM_UTIL_DIR/osm | ||
| 26 | |||
| 27 | # sync with important git repos | ||
| 28 | $SETTING_DIR/tools/init/sync.sh | ||
| 29 | |||
| 30 | # go | ||
| 31 | PATH=$PATH:$HOME/go/bin | ||
diff --git a/tools/init/sync.sh b/tools/init/sync.sh new file mode 100755 index 0000000..00ed4b8 --- /dev/null +++ b/tools/init/sync.sh | |||
| @@ -0,0 +1,11 @@ | |||
| 1 | #!/bin/bash | ||
| 2 | |||
| 3 | # my repo | ||
| 4 | cd $SETTING_DIR && git pull --quiet || echo in `pwd` > /dev/tty & | ||
| 5 | if [ -d ~/vimwiki ]; then | ||
| 6 | cd ~/vimwiki && git pull --quiet || echo in `pwd` > /dev/tty & | ||
| 7 | fi | ||
| 8 | |||
| 9 | # others repo | ||
| 10 | check_upstream ~/git/tig || echo in `pwd` > /dev/tty & | ||
| 11 | check_upstream ~/.vim_runtime || echo in `pwd` > /dev/tty & | ||