-
Notifications
You must be signed in to change notification settings - Fork 0
/
lsgit
executable file
·32 lines (25 loc) · 951 Bytes
/
lsgit
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
#!/bin/zsh
# Find all git directories under a specified directory or $HOME, by default.
# Uses fd to search for any directory that contains a .git folder.
# Ignores anything under ~/.local/share/ such as
# ~/.local/share/cargo/* Contains checkouts for cargo packages
# ~/.local/share/nvim/* Contains repos for plugins
lsgit() {
[[ -f /usr/bin/fd ]] || { echo "fd is required"; return 1 }
[[ -v LSGIT_DIR ]] \
&& local dir="${1:-$LSGIT_DIR}" \
|| local dir="${1:-$HOME}"
[[ -d $dir ]] || { echo "directory $dir not found."; return 1 }
git_dirs=(
$(fd --prune --hidden --no-ignore \
--exclude "/{boot,dev,etc,proc,sys}" \
--exclude "/usr/{bin,lib,lib32}" \
--exclude ".local/share" \
--exclude ".cache" \
--exclude "mnt" \
--type directory --glob ".git" $dir | sort)
)
for d in "${git_dirs[@]}"; do
echo ${d%%.git/}
done
}