This repository has been archived by the owner on Feb 13, 2020. It is now read-only.
forked from ingydotnet/git-subrepo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathinit
78 lines (72 loc) · 2.98 KB
/
init
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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!bash
#------------------------------------------------------------------------------
#
# This is the `git-subrepo` initialization script.
#
# This script turns on the `git-subrepo` Git subcommand, its manpages and TAB
# completion for the *Bash* and *zsh* shells.
#
# Just add a line like this to your shell startup configuration:
#
# source /path/to/git-subrepo/init
#
#------------------------------------------------------------------------------
[[ -n ${ZSH_VERSION-} ]] &&
GIT_SUBREPO_ROOT="$0" ||
GIT_SUBREPO_ROOT="$BASH_SOURCE"
if [[ "$GIT_SUBREPO_ROOT" =~ ^/ ]]; then
GIT_SUBREPO_ROOT="$(dirname $GIT_SUBREPO_ROOT)"
export GIT_SUBREPO_ROOT
export PATH="$GIT_SUBREPO_ROOT/lib:$PATH"
export MANPATH="$GIT_SUBREPO_ROOT/man:$MANPATH"
# Completion facilities
if [[ -n ${BASH_VERSION-} ]]; then
# Bash
if [ "$(type -t __gitcomp 2> /dev/null)" != function ]; then
# The standard Git completion script for Bash does not seem to be
# loaded, because its shell function `__gitcomp`, which our Bash
# completion script uses, does not appear to exist.
{
# Look for the Git completion script at the file-paths whereat it
# might be found, according to
# <https://github.com/git/git/blob/4109c28/contrib/completion/git-completion.zsh#L34-L36>
# and experimental and anecdotal evidence.
for f in \
/{usr,opt/local}/share/bash-completion/{completions/,}git \
{,/usr/local,~/.homebrew}/etc/bash_completion.d/git
do
# If a file is found at the location being checked…
if [[ -f $f ]]; then
# …source it.
source $f
[[ $(type -t __gitcomp) != function ]] &&
echo "WARNING: Git completion script '$f' does not provide a '__gitcomp' function"
# Proceed to loading our Bash completion facilities.
break
# We could instead `break` only if `source $f` succeeds, or if
# `$f` provides a `__gitcomp` function, but that would entail
# plowing ahead to the next potential Git completion script if
# this one errors partway through being sourced, possibly
# resulting in an inconsistent mishmash of Git completion scripts.
fi
done
} || {
# If no file was found at any of the potential file-paths checked
# above, source a bundled copy of
# <https://github.com/git/git/blob/c285171/contrib/completion/git-completion.bash>.
source "$GIT_SUBREPO_ROOT/share/git-completion.bash"
}
fi
# Load our Bash completion facilities.
source "$GIT_SUBREPO_ROOT/share/completion.bash"
elif [[ -n ${ZSH_VERSION-} ]]; then
# Zsh
#
# Prepend to `fpath` the path of the directory containing our zsh
# completion script, so that our completion script will be hooked into the
# zsh completion system.
fpath=($GIT_SUBREPO_ROOT/share/zsh-completion $fpath)
fi
else
echo "source the absolute path of '$GIT_SUBREPO_ROOT'"
fi