Skip to content

Commit 808f38c

Browse files
committed
added -c and -u as color and update flags, respectively
1 parent eb60ca6 commit 808f38c

File tree

3 files changed

+121
-93
lines changed

3 files changed

+121
-93
lines changed

tgit/check_status

Lines changed: 88 additions & 87 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,24 @@
66
# ------------------------------------------------------------------------------
77
# Configuration
88
# ------------------------------------------------------------------------------
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'
914

1015
SPACESHIP_GIT_STATUS_SHOW="${SPACESHIP_GIT_STATUS_SHOW=true}"
1116
SPACESHIP_GIT_STATUS_PREFIX="${SPACESHIP_GIT_STATUS_PREFIX=" ["}"
1217
SPACESHIP_GIT_STATUS_SUFFIX="${SPACESHIP_GIT_STATUS_SUFFIX="]"}"
1318
SPACESHIP_GIT_STATUS_COLOR="${SPACESHIP_GIT_STATUS_COLOR="red"}"
1419
SPACESHIP_GIT_STATUS_UNTRACKED="${SPACESHIP_GIT_STATUS_UNTRACKED="?"}"
15-
SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="+"}"
16-
SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="!"}"
20+
SPACESHIP_GIT_STATUS_ADDED="${SPACESHIP_GIT_STATUS_ADDED="${LIGHT_GREEN}+${NC}"}"
21+
SPACESHIP_GIT_STATUS_MODIFIED="${SPACESHIP_GIT_STATUS_MODIFIED="${YELLOW}!${NC}"}"
1722
SPACESHIP_GIT_STATUS_RENAMED="${SPACESHIP_GIT_STATUS_RENAMED="»"}"
18-
SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED=""}"
23+
SPACESHIP_GIT_STATUS_DELETED="${SPACESHIP_GIT_STATUS_DELETED="${RED}${NC}"}"
1924
SPACESHIP_GIT_STATUS_STASHED="${SPACESHIP_GIT_STATUS_STASHED="$"}"
2025
SPACESHIP_GIT_STATUS_UNMERGED="${SPACESHIP_GIT_STATUS_UNMERGED="="}"
21-
SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD=""}"
26+
SPACESHIP_GIT_STATUS_AHEAD="${SPACESHIP_GIT_STATUS_AHEAD="${CYAN}${NC}"}"
2227
SPACESHIP_GIT_STATUS_BEHIND="${SPACESHIP_GIT_STATUS_BEHIND=""}"
2328
SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED=""}"
2429

@@ -36,86 +41,82 @@ SPACESHIP_GIT_STATUS_DIVERGED="${SPACESHIP_GIT_STATUS_DIVERGED="⇕"}"
3641

3742
# spaceship::is_git || return
3843

39-
INDEX=''
40-
git_status=""
41-
42-
43-
INDEX=$(cd "$1" && command git status --porcelain -b 2> /dev/null)
44-
45-
# Check for untracked files
46-
if $(echo "$INDEX" | command grep -E '^\?\? ' &> /dev/null); then
47-
git_status="$SPACESHIP_GIT_STATUS_UNTRACKED$git_status"
48-
fi
49-
50-
# Check for staged files
51-
if $(echo "$INDEX" | command grep '^A[ MDAU] ' &> /dev/null); then
52-
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
53-
elif $(echo "$INDEX" | command grep '^M[ MD] ' &> /dev/null); then
54-
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
55-
elif $(echo "$INDEX" | command grep '^UA' &> /dev/null); then
56-
git_status="$SPACESHIP_GIT_STATUS_ADDED$git_status"
57-
fi
58-
59-
# Check for modified files
60-
if $(echo "$INDEX" | command grep '^[ MARC]M ' &> /dev/null); then
61-
git_status="$SPACESHIP_GIT_STATUS_MODIFIED$git_status"
62-
fi
63-
64-
# Check for renamed files
65-
if $(echo "$INDEX" | command grep '^R[ MD] ' &> /dev/null); then
66-
git_status="$SPACESHIP_GIT_STATUS_RENAMED$git_status"
67-
fi
68-
69-
# Check for deleted files
70-
if $(echo "$INDEX" | command grep '^[MARCDU ]D ' &> /dev/null); then
71-
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
72-
elif $(echo "$INDEX" | command grep '^D[ UM] ' &> /dev/null); then
73-
git_status="$SPACESHIP_GIT_STATUS_DELETED$git_status"
74-
fi
75-
76-
# Check for stashes
77-
if $(command git rev-parse --verify refs/stash >/dev/null 2>&1); then
78-
git_status="$SPACESHIP_GIT_STATUS_STASHED$git_status"
79-
fi
80-
81-
# Check for unmerged files
82-
if $(echo "$INDEX" | command grep '^U[UDA] ' &> /dev/null); then
83-
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
84-
elif $(echo "$INDEX" | command grep '^AA ' &> /dev/null); then
85-
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
86-
elif $(echo "$INDEX" | command grep '^DD ' &> /dev/null); then
87-
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
88-
elif $(echo "$INDEX" | command grep '^[DA]U ' &> /dev/null); then
89-
git_status="$SPACESHIP_GIT_STATUS_UNMERGED$git_status"
90-
fi
91-
92-
# Check whether branch is ahead
93-
is_ahead=false
94-
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*ahead' &> /dev/null); then
95-
is_ahead=true
96-
fi
97-
98-
# Check whether branch is behind
99-
is_behind=false
100-
if $(echo "$INDEX" | command grep '^## [^ ]\+ .*behind' &> /dev/null); then
101-
is_behind=true
102-
fi
103-
104-
# Check wheather branch has diverged
105-
if [[ "$is_ahead" == true && "$is_behind" == true ]]; then
106-
git_status="$SPACESHIP_GIT_STATUS_DIVERGED$git_status"
107-
else
108-
[[ "$is_ahead" == true ]] && git_status="$SPACESHIP_GIT_STATUS_AHEAD$git_status"
109-
[[ "$is_behind" == true ]] && git_status="$SPACESHIP_GIT_STATUS_BEHIND$git_status"
110-
fi
111-
112-
echo "$git_status"
113-
# if [[ -n $git_status ]]; then
114-
# # Status prefixes are colorized
115-
# spaceship::section \
116-
# "$SPACESHIP_GIT_STATUS_COLOR" \
117-
# "$SPACESHIP_GIT_STATUS_PREFIX$git_status$SPACESHIP_GIT_STATUS_SUFFIX"
118-
# fi
119-
# }
120-
121-
# $spaceship_git_status $1
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+

tgit/dmenu_tgit

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,13 @@
11
#!/bin/bash
22

33
tgit="/home/gabo/packages/tinytools/tgit/tgit"
4-
repo=$(echo -e "$($tgit)" | dmenu -i -p Repos: | awk '{print $2}')
4+
check_status="/home/gabo/packages/tinytools/tgit/check_status"
5+
repo=$(echo "$($tgit)" | dmenu -i -p Repos: | awk '{print $2}')
56

67
[[ -n $repo ]] || exit
78
path="$HOME/$repo"
8-
prompt=$(echo "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$($check_status $path)]:"
9-
options="status\ndiff\ncheckout"
9+
prompt=$(print "$repo" | awk -F'/' 'NF>1{print $(NF)}') && prompt="$prompt [$($check_status $path)]:"
10+
options="open\nstatus\ndiff\ncheckout"
1011
option=$(echo -e "$options" | dmenu -i -p "$prompt")
1112

1213
[[ -n $option ]] || exit
@@ -16,6 +17,9 @@ case "$option" in
1617
branch=$(echo -e "$branches" | dmenu -i -p Checkout:)
1718
x-terminal-emulator -e 'bash -c "cd '$path' && git '$option $branch'; zsh"'
1819
;;
20+
"open")
21+
codium $path
22+
;;
1923
*)
2024
x-terminal-emulator -e 'bash -c "cd '$path' && git '$option'; zsh"'
2125
;;

tgit/tgit

Lines changed: 26 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,28 @@
11
#!/bin/bash
22

33
check_status="/home/gabo/packages/tinytools/tgit/check_status"
4-
repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1')
4+
repos=''
5+
6+
update() {
7+
repos=$(find $HOME -name ".git" | awk -F/ 'BEGIN { OFS = FS } NF{NF-=1};1')
8+
touch /tmp/repos.dat
9+
echo -e "$repos" > /tmp/repos.dat
10+
}
11+
12+
get_repos(){
13+
if [ -f "/tmp/repos.dat" ]; then
14+
echo -e "$(cat "/tmp/repos.dat")"
15+
else
16+
update && echo -e "$(cat "/tmp/repos.dat")"
17+
fi
18+
}
519

620
list() {
721
for i in $repos
822
do
923
cd $i
1024
if [[ "$(git rev-parse --git-dir)" == ".git" ]]; then
11-
status=$($check_status $i)
25+
status=$($check_status $i $1)
1226
name="${i/"$HOME/"/''}"
1327
list="$list\n[$status] $name"
1428
fi
@@ -20,4 +34,13 @@ list() {
2034
echo -e "$list"
2135
}
2236

23-
list
37+
repos=$(get_repos)
38+
39+
while getopts uc option
40+
do
41+
case "${option}" in
42+
u) update && exit;;
43+
c) echo -e "$(list -c)" && exit ;;
44+
esac
45+
done
46+
echo -e "$(list)"

0 commit comments

Comments
 (0)