summaryrefslogtreecommitdiff
path: root/zsh/utils.zsh
blob: 111a2fb57d8508abae26fbf6263b62d5c0f4b780 (plain)
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
deps() {
    if [[ -f yarn.lock ]]; then
        yarn list --pattern "@arf/|@arjs/|@dt/|@grapecity/|@mescius/|barcodejs|js-expressions" --depth=0 -s 
    elif [[ -f pnpm-lock.yaml ]]; then
        pnpm list @arf/* @arjs/* @dt/* @grapecity/* @mescius/* barcodejs js-expressions
    elif [[ -f package-lock.json ]]; then
        echo "NPM does not support dependencies filtering, here's the full list:"
        npm list
    else
        echo "No package manager in this directory"
        return 1
    fi
}

# opens PR on bitbucket
bb() {
    repoUrl=$(npm repo --browser=false | grep http)
    branch=$(git rev-parse --abbrev-ref HEAD | jq -sRr @uri)
    xdg-open "$repoUrl/pull-requests/new?source=$branch"
}

# git -C $line describe --tags HEAD [latest tag]
# git -C $line tag --points-at HEAD [latest tagS]

# shows project list
lsproj() {
    ls | while read line;
    do {
        fill_count=$((32 - ${#line}))
        filler=$(repeat $fill_count printf "·")
        is_git_repo=$(git -C $line rev-parse --abbrev-ref HEAD 2> /dev/null)
        if [[ $is_git_repo ]] {
            project_dir="%B%K{green} $line $filler %k%b"
            branch=" %F{blue} $(git -C $line rev-parse --abbrev-ref HEAD)%f"
            tag=$(git -C $line describe --tags HEAD 2> /dev/null)
            print -P "$project_dir$branch [$tag]";
        }
    }
    done
}

lsproj2() {
    ls | while read line;
    do {
        fill_count=$((32 - ${#line}))
        filler=$(repeat $fill_count printf "·")
        is_git_repo=$(git -C $line rev-parse --abbrev-ref HEAD 2> /dev/null)
        if [[ $is_git_repo ]] {
            project_dir="%B%F{white}%K{green} $line %k%f%b"
            branch=" %F{blue} $(git -C $line rev-parse --abbrev-ref HEAD)%f"
            # tag=$(git -C $line describe --tags HEAD 2> /dev/null)
            print -P "|$project_dir\n|$branch\n|"            
        }
    }
    done
}

lsproj_watch() {
    while true;
    do {
        output=$(lsproj)
        clear;
        print $output;
        sleep 1;
    }
    done;
}

# TEMP

chkt() {
    ls | while read line;
    do {
        fill_count=$((32 - ${#line}))
        filler=$(for i in {1..$fill_count}; do printf "·"; done)
        is_git_repo=$(git -C $line rev-parse --abbrev-ref HEAD 2> /dev/null)
        if [[ $is_git_repo ]] {
            print "%B%F{white}%K{green} $line %k%f%b"
            git -C $line branch
        }
    }
    done
}

fore() {
    while read proj;
    do {
        echo $proj
        git -C $proj branch -d feature/update-arf-toolkit 2> /dev/null && echo "OK"
    }
    done
}


multiupd() {
    echo $1
    start_path=$(pwd)
    while read proj;
    do {
        cd $start_path/$proj
        print -P "%K{green}%F{white}%B update to $1 in $start_path/$proj %b%f%k"

        if [[ -f yarn.lock ]]; then
            yarn add $1 -E -W 2> >(grep -v warning 1>&2)
            git add yarn.lock
        elif [[ -f pnpm-lock.yaml ]]; then
            pnpm i $1 -E
            git add pnpm-lock.yaml
        elif [[ -f package-lock.json ]]; then
            npm i $1 -E
            git add package-lock.json
        fi
        git add package.json
    }
    done

    cd $start_path
}

createbr() {
    start_path=$(pwd)
    while read proj;
    do {
        cd $start_path/$proj
        print -P "%K{green}%F{white}%B $start_path/$proj %b%f%k"
        git co -b feature/update-arf-toolkit
        git ci -m "@arf/toolkit 0.16.5"
        git push
        bb 2> /dev/null || echo "PR is not open: $proj"
    }
    done
}