2020-07-17 11:26:18 +00:00
|
|
|
#!/bin/bash
|
|
|
|
# Just source this file in your bashrc :)
|
|
|
|
|
2020-05-15 09:36:09 +00:00
|
|
|
_g_completion() {
|
2020-07-17 11:26:18 +00:00
|
|
|
root=$(git rev-parse --show-toplevel 2>/dev/null)
|
|
|
|
if [ "$root" ]
|
|
|
|
then
|
|
|
|
if echo "$2" | grep '^\/' > /dev/null
|
|
|
|
then
|
|
|
|
dirname=$(dirname "$2foo")
|
|
|
|
regex=$(echo $root | sed 's/\//\\\//g')
|
|
|
|
for dir in $(find $root$dirname -maxdepth 1 -mindepth 1 -type d | sed s'/^'"$regex"'//g' | grep '^'"$2")
|
|
|
|
do COMPREPLY+=("$dir/")
|
|
|
|
done
|
|
|
|
fi
|
|
|
|
fi
|
2020-05-15 09:36:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
complete -F _g_completion -o bashdefault -o dirnames g
|