-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgitme-completion.bash
More file actions
35 lines (28 loc) · 1.06 KB
/
gitme-completion.bash
File metadata and controls
35 lines (28 loc) · 1.06 KB
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
_gitme_complete() {
local cur prev words cword
_init_completion || return
local GITME_CACHE_DIR="${GITME_CACHE_DIR:-$HOME/.gitme}"
local GITME_CACHE_FILE="$GITME_CACHE_DIR/cache"
local candidates=()
# Use cache if it exists and is not empty, otherwise fall back to scanning
if [[ -s "$GITME_CACHE_FILE" ]]; then
while IFS=$'\t' read -r dir remote_url; do
[[ -z "$dir" ]] && continue
repo_name="$(basename "$dir")"
candidates+=("$repo_name" "$remote_url")
done < "$GITME_CACHE_FILE"
else
local GITME_DIRS="${GITME_DIRS:-$HOME/git}"
IFS=':' read -ra DIRS <<< "$GITME_DIRS"
for base in "${DIRS[@]}"; do
[[ -d "$base" ]] || continue
while IFS= read -r dir; do
repo_name="$(basename "$dir")"
remote_url="$(git -C "$dir" config --get remote.origin.url 2>/dev/null || echo "")"
candidates+=("$repo_name" "$remote_url")
done < <(find "$base" -type d -name .git -exec dirname {} \;)
done
fi
COMPREPLY=($(compgen -W "${candidates[*]}" -- "$cur"))
}
complete -F _gitme_complete gitme