-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathwyx-cli.sh
executable file
·77 lines (65 loc) · 1.61 KB
/
wyx-cli.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/bin/bash
# CLI CONSTS
if [[ "$OSTYPE" == "darwin"* ]] || [[ "$(ps -o args= -p $$)" = *"zsh"* ]]; then
mypath="${(%):-%N}"
else
mypath="${BASH_SOURCE[0]}"
fi
WYX_DIR=$(dirname "$mypath")
WYX_DATA_DIR=$WYX_DIR/.wyx-cli-data
WYX_SCRIPT_DIR=$WYX_DIR/src/commands/scripts
export WYX_DIR WYX_DATA_DIR WYX_SCRIPT_DIR
source $WYX_DIR/src/classes/sys/sys.h
sys sys
source $WYX_DIR/src/classes/lib/lib.h
lib lib
wyx_git_branch=""
# AUTO UPDATE CLI
pull() {
if [ "$1" != "$wyx_git_branch" ]; then
git checkout "$1" || return 1
fi
git pull origin "$1" || return 1
}
wyx_update() {
if ! grep -q "WYX_GIT_AUTO_UPDATE=true" "${WYX_DATA_DIR}/.env" ; then
sys.log.warn "Auto update disabled" && echo ""
return 1
fi
sys.log.info "Checking for updates..."
current_dir=$(pwd)
cd "$WYX_DIR" || return 1
if git rev-parse --git-dir > /dev/null 2>&1; then
wyx_git_branch=$(git branch | sed -n -e 's/^\* \(.*\)/\1/p')
fi
if [ "$wyx_git_branch" != "master" ]; then
sys.log.warn "Not on master branch, skipping update" && echo ""
cd "$current_dir" || return 1
return 1
fi
git fetch
UPSTREAM=${1:-'@{u}'}
LOCAL=$(git rev-parse @)
REMOTE=$(git rev-parse "$UPSTREAM")
BASE=$(git merge-base @ "$UPSTREAM")
if [ "$LOCAL" = "$REMOTE" ]; then
sys.log.info "Up-to-date"
elif [ "$LOCAL" = "$BASE" ]; then
sys.log.info "Updating..."
pull "$wyx_git_branch"
elif [ "$REMOTE" = "$BASE" ]; then
echo "Need to push"
else
echo "Diverged"
fi
echo ""
# {
cd "$current_dir" || return 1
# } &> /dev/null
}
if [ "$1" = "" ]; then
wyx_update ""
fi
# ARGPARSE
source "$WYX_DIR/completion.sh"
source "$WYX_DIR/argparse.sh" "${@:1}"