aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--alias19
-rwxr-xr-xtools/git/check-repos.sh46
2 files changed, 48 insertions, 17 deletions
diff --git a/alias b/alias
index 2956eb1..c264154 100644
--- a/alias
+++ b/alias
@@ -72,6 +72,7 @@ alias gg='gist grep'
72 72
73# unix 73# unix
74alias chx='chmod +x' 74alias chx='chmod +x'
75alias chr='chmod +r'
75alias s='sudo systemctl' 76alias s='sudo systemctl'
76alias j='sudo journalctl -xe' 77alias j='sudo journalctl -xe'
77alias ju='sudo journalctl -u' 78alias ju='sudo journalctl -u'
@@ -222,23 +223,7 @@ alias gls='git log -S'
222alias cdgg='cd $(git rev-parse --show-toplevel)' 223alias cdgg='cd $(git rev-parse --show-toplevel)'
223alias cdgw='cdgg && cd .github/workflows' 224alias cdgw='cdgg && cd .github/workflows'
224alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" " -f2)' # cd to first submodule 225alias cdgs='cd $(git submodule status | sed "s/^.//" | cut -d" " -f2)' # cd to first submodule
225check_repo() { 226alias ch="/home/pham/helper/tools/git/check-repos.sh"
226 cd $1 2>/dev/null || return 0
227 echo check $1
228 git status -s
229 [[ -n $(git cherry ${2:-origin}) ]] 2>/dev/null && print "\e[31m[ahead]\e[0m"
230}
231check() {
232 DIR=`pwd`
233 check_repo $SETTING_DIR
234 check_repo $HOME/.password-store
235 check_repo $HOME/log
236 check_repo $HOME/.task
237 check_repo $HOME/bean
238 check_repo $HOME/.vim/vim-init vps
239 cd $DIR
240}
241alias ch='check'
242 227
243# github 228# github
244export GITHUB_API='https://api.github.com' 229export GITHUB_API='https://api.github.com'
diff --git a/tools/git/check-repos.sh b/tools/git/check-repos.sh
new file mode 100755
index 0000000..308bea6
--- /dev/null
+++ b/tools/git/check-repos.sh
@@ -0,0 +1,46 @@
1#! /bin/bash
2
3LIST=~/.repos
4[[ $1 == -n ]] && {
5 COUNT_ONLY=true
6 count=0
7}
8
9
10# Only works when file ~/.repos exists and readable
11if [ ! -r $LIST ]; then
12 echo File ~/.repos not found/readable
13 exit 1
14fi
15
16
17while read repo remote; do
18 [[ "$repo" =~ ^[[:space:]]*#.* ]] && continue
19
20 # In case repo is consists of variable like $HOME
21 # Use eval to get git information
22 eval cd $repo 2>/dev/null || {
23 echo Repo $repo is inaccessible
24 exit 1
25 }
26
27 # Changes in working dir, not yet to be a commit
28 changes="$(git -c color.status=always status --short)"
29
30 # Diff between from local repo and remote
31 cherry="$(git cherry)"
32
33 if [[ $COUNT_ONLY == true ]]; then
34 # If '-n' is specified, only count repo with changes/local-diff
35 [[ -n "$changes" || -n "$cherry" ]] && (( count++ ))
36 else
37 # Or, just print their status
38 echo Check $repo
39 [[ -n "$changes" ]] && echo "$changes"
40 [[ -n "$cherry" ]] && echo -e "\e[31m[ahead]\e[0m"
41 fi
42done <$LIST
43
44
45# If '-n' is specified, print number of repos with changes/local-diff
46[[ $COUNT_ONLY == true ]] && echo $count