Skip to content

Commit 5d89557

Browse files
gbgabocalebe94
authored andcommitted
updated Makefile for tgit
1 parent 56e7b63 commit 5d89557

4 files changed

Lines changed: 200 additions & 2 deletions

File tree

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,13 @@ tsearch: ${CONFIG_FOLDER} ${BIN_FOLDER} tyaml
2222
install tsearch/params.yaml ${CONFIG_FOLDER}
2323
@echo "done!"
2424

25+
tgit: ${CONFIG_FOLDER} ${BIN_FOLDER}
26+
@echo "Installing tgit..."
27+
install -m 555 tgit/tgit ${BIN_FOLDER}
28+
install -m 555 tgit/dmenu_tgit ${BIN_FOLDER}
29+
install -m 555 tgit/tgit_status ${BIN_FOLDER}
30+
@echo "done!"
31+
2532
tpomodoro: ${CONFIG_FOLDER} ${BIN_FOLDER}
2633
@echo "Installing tpomodoro..."
2734
install -m 555 tpomodoro/tpomodoro ${BIN_FOLDER}
@@ -80,7 +87,7 @@ uninstall:
8087
rm -f ${BIN_FOLDER}/tprogbar
8188
@echo "done!"
8289

83-
install: tsearch ttodo tmenu tyaml tnotes tgoeswall tpomodoro tprogbar
90+
install: tsearch ttodo tmenu tyaml tnotes tgoeswall tpomodoro tprogbar tgit
8491
@echo "tinytools installed successfully!"
8592

86-
.PHONY: install tsearch tpomodoro ttodo tmenu tyaml tnotes tgoeswall uninstall tprogbar
93+
.PHONY: install tsearch tpomodoro ttodo tmenu tyaml tnotes tgoeswall uninstall tprogbar tgit

tgit/dmenu_tgit

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
#!/bin/bash
2+
3+
repo=$(echo "$(tgit)" | dmenu -i -p Repos: | awk '{print $2}')
4+
5+
[[ -n $repo ]] || exit
6+
path="$HOME/$repo"
7+
prompt=$(print "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$(tgit_status $path)]:"
8+
options="open\nstatus\ndiff\ncheckout"
9+
option=$(echo -e "$options" | dmenu -i -p "$prompt")
10+
11+
[[ -n $option ]] || exit
12+
case "$option" in
13+
"checkout")
14+
branches="$(cd $path && git branch -r)"
15+
branch=$(echo -e "$branches" | dmenu -i -p Checkout:)
16+
x-terminal-emulator -e 'bash -c "cd '$path' && git '$option $branch'; zsh"'
17+
;;
18+
"open")
19+
codium $path
20+
;;
21+
*)
22+
x-terminal-emulator -e 'bash -c "cd '$path' && git '$option'; zsh"'
23+
;;
24+
esac

tgit/tgit

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
#!/bin/bash
2+
3+
repos=''
4+
5+
update() {
6+
repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1' | grep -E -v 'vim|antigen')
7+
touch /tmp/repos.dat
8+
echo -e "$repos" > /tmp/repos.dat
9+
}
10+
11+
get_repos(){
12+
if [ -f "/tmp/repos.dat" ]; then
13+
echo -e "$(cat "/tmp/repos.dat")"
14+
else
15+
update && echo -e "$(cat "/tmp/repos.dat")"
16+
fi
17+
}
18+
19+
list() {
20+
for i in $repos
21+
do
22+
cd $i
23+
if [[ "$(git rev-parse --git-dir)" == ".git" ]]; then
24+
status=$(tgit_status $i $1)
25+
name="${i/"$HOME/"/''}"
26+
list="$list\n[$status] $name"
27+
fi
28+
done
29+
tmpfile=$(mktemp)
30+
echo -e "$list" >> $tmpfile
31+
list=$(column $tmpfile -t)
32+
rm "$tmpfile"
33+
echo -e "$list"
34+
}
35+
36+
repos=$(get_repos)
37+
38+
while getopts uc option
39+
do
40+
case "${option}" in
41+
u) update && exit;;
42+
c) echo -e "$(list -c)" && exit ;;
43+
esac
44+
done
45+
echo -e "$(list)"

tgit/tgit_status

Lines changed: 122 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,122 @@
1+
#!/bin/bash
2+
#
3+
# Git status
4+
#
5+
6+
# ------------------------------------------------------------------------------
7+
# Configuration
8+
# ------------------------------------------------------------------------------
9+
RED='\033[0;31m'
10+
CYAN='\033[0;36m'
11+
LIGHT_GREEN='\033[1;32m'
12+
YELLOW='\033[1;33m'
13+
NC='\033[0m'
14+
15+
SPACESHIP_GIT_STATUS_SHOW="${SPACESHIP_GIT_STATUS_SHOW=true}"
16+
SPACESHIP_GIT_STATUS_PREFIX="${SPACESHIP_GIT_STATUS_PREFIX=" ["}"
17+
SPACESHIP_GIT_STATUS_SUFFIX="${SPACESHIP_GIT_STATUS_SUFFIX="]"}"
18+
SPACESHIP_GIT_STATUS_COLOR="${SPACESHIP_GIT_STATUS_COLOR="red"}"
19+
SPACESHIP_GIT_STATUS_UNTRACKED="${SPACESHIP_GIT_STATUS_UNTRACKED="?"}"
20+
SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="${LIGHT_GREEN}+${NC}"}"
21+
SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="${YELLOW}!${NC}"}"
22+
SPACESHIP_GIT_STATUS_RENAMED="${SPACESHIP_GIT_STATUS_RENAMED="»"}"
23+
SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED="${RED}${NC}"}"
24+
SPACESHIP_GIT_STATUS_STASHED="${SPACESHIP_GIT_STATUS_STASHED="$"}"
25+
SPACESHIP_GIT_STATUS_UNMERGED="${SPACESHIP_GIT_STATUS_UNMERGED="="}"
26+
SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD="${CYAN}${NC}"}"
27+
SPACESHIP_GIT_STATUS_BEHIND="${SPACESHIP_GIT_STATUS_BEHIND=""}"
28+
SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED=""}"
29+
30+
# ------------------------------------------------------------------------------
31+
# Section
32+
# ------------------------------------------------------------------------------
33+
34+
# We used to depend on OMZ git library,
35+
# But it doesn't handle many of the status indicator combinations.
36+
# Also, It's hard to maintain external dependency.
37+
# See PR #147 at https://git.io/vQkkB
38+
# See git help status to know more about status formats
39+
# spaceship_git_status() {
40+
# [[ $SPACESHIP_GIT_STATUS_SHOW == false ]] && return
41+
42+
# spaceship::is_git || return
43+
44+
INDEX=''
45+
git_status=""
46+
47+
INDEX=$(cd "$1" && command git status --porcelain -b 2> /dev/null)
48+
49+
# Check for untracked files
50+
if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
51+
git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status"
52+
fi
53+
54+
# Check for staged files
55+
if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then
56+
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
57+
elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then
58+
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
59+
elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then
60+
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
61+
fi
62+
63+
# Check for modified files
64+
if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then
65+
git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status"
66+
fi
67+
68+
# Check for renamed files
69+
if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then
70+
git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status"
71+
fi
72+
73+
# Check for deleted files
74+
if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then
75+
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
76+
elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then
77+
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
78+
fi
79+
80+
# Check for stashes
81+
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
82+
git_status="$SPACESHIP_GIT_STATUS_STASHED$git_status"
83+
fi
84+
85+
# Check for unmerged files
86+
if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then
87+
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
88+
elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then
89+
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
90+
elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then
91+
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
92+
elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then
93+
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
94+
fi
95+
96+
# Check whether branch is ahead
97+
is_ahead=false
98+
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then
99+
is_ahead=true
100+
fi
101+
102+
# Check whether branch is behind
103+
is_behind=false
104+
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then
105+
is_behind=true
106+
fi
107+
108+
# Check wheather branch has diverged
109+
if [[ "$is_ahead" == true && "$is_behind" == true ]]; then
110+
git_status="$SPACESHIP_GIT_STATUS_DIVERGED$git_status"
111+
else
112+
[[ "$is_ahead" == true ]] && git_status="$SPACESHIP_GIT_STATUS_AHEAD$git_status"
113+
[[ "$is_behind" == true ]] && git_status="$SPACESHIP_GIT_STATUS_BEHIND$git_status"
114+
fi
115+
116+
if [[ "$2" == "-c" ]]; then
117+
echo -e "$git_status"
118+
else
119+
echo $(echo -e "$git_status" | sed -r "s/\x1B\[([0-9]{1,3}(;[0-9]{1,2})?)?[mGK]//g")
120+
fi
121+
122+

0 commit comments

Comments
 (0)