Account for various locations of bash/zsh completion scripts

On different systems, bash/zsh completion scripts for git are installed
in various places. Account for that by searching the list of known paths.

In zsh mode, if a git-distributed zsh completion script can't be found
(e.g. on Ubuntu), ignore that and let it fall back to zsh-distributed
completion script.
This commit is contained in:
Mislav Marohnić 2013-11-13 17:12:48 +01:00
Родитель 755d5aa06d
Коммит a766b98b72
1 изменённых файлов: 11 добавлений и 4 удалений

Просмотреть файл

@ -31,11 +31,14 @@ git_distributed_zsh_completion = lambda {
}
git_distributed_bash_completion = lambda {
git_prefix.call + 'share/git-core/contrib/completion/git-completion.bash'
[ git_prefix.call + 'share/git-core/contrib/completion/git-completion.bash',
Pathname.new('/etc/bash_completion.d/git'),
Pathname.new('/usr/share/bash-completion/completions/git'),
Pathname.new('/usr/share/bash-completion/git'),
].detect {|p| p.exist? }
}
link_completion = Proc.new { |from, name|
name ||= from.basename
raise ArgumentError, from.to_s unless File.exist?(from)
FileUtils.ln_s(from, cpldir + name, :force => true)
}
@ -162,8 +165,12 @@ Given(/^I'm using ((?:zsh|git)-distributed) base git completions$/) do |type|
(cpldir + '_git').exist?.should be_false
when 'git-distributed'
if 'zsh' == shell
link_completion.call(git_distributed_zsh_completion.call)
link_completion.call(git_distributed_bash_completion.call)
if git_distributed_zsh_completion.call.exist?
link_completion.call(git_distributed_zsh_completion.call, '_git')
link_completion.call(git_distributed_bash_completion.call, 'git-completion.bash')
else
warn "warning: git-distributed zsh completion wasn't found; using zsh-distributed instead"
end
end
else
raise ArgumentError, type