-
Notifications
You must be signed in to change notification settings - Fork 12
/
Copy path_cd-gitroot
50 lines (43 loc) · 1.22 KB
/
_cd-gitroot
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
#compdef cd-gitroot
# ------------------------------------------------------------------------------
# Copyright (c) 2013 Hideaki Miyake
# Licensed under the MIT License (MIT)
# ------------------------------------------------------------------------------
# Description
# -----------
#
# Completion script for cd-gitroot (https://github.com/mollifier/cd-gitroot)
#
# ------------------------------------------------------------------------------
# Authors
# -------
#
# * Hideaki Miyake (https://github.com/mollifier)
#
# ------------------------------------------------------------------------------
declare -a opts args
args=(
'-h[display this help and exit]'
'1:path:_cd-gitroot_path'
)
local curcontext=$curcontext state line ret=1
declare -A opt_args
# show directories in git top level directory
(( $+functions[_cd-gitroot_path] )) ||
_cd-gitroot_path() {
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) != 'true' ]]; then
return 1
fi
local root_path=$(git rev-parse --show-toplevel)
_path_files -W "$root_path" -/
}
_arguments -C $opts \
$args && ret=0
return $ret
# Local Variables:
# mode: Shell-Script
# sh-indentation: 2
# indent-tabs-mode: nil
# sh-basic-offset: 2
# End:
# vim: ft=zsh sw=2 ts=2 et