forked from colinmollenhour/modman
-
Notifications
You must be signed in to change notification settings - Fork 0
/
bash_completion
81 lines (78 loc) · 1.68 KB
/
bash_completion
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
78
79
80
81
#!/bin/bash
# Installation:
# Copy to /etc/bash_completion.d/modman
# or
# Append to ~/.bash_completion
#
_modman()
{
local cur prev opts mm module
COMPREPLY=()
cur="${COMP_WORDS[COMP_CWORD]}"
prev="${COMP_WORDS[COMP_CWORD-1]}"
if [ $COMP_CWORD -eq 1 ]; then prev='modman'; fi
mm=$(_modman_get_mm)
module=$(_modman_get_module)
case "${prev}" in
modman)
opts="init --help --version --tutorial"
if [ -n "$mm" ]; then
opts="${opts} list status incoming update-all deploy-all repair clean"
opts="${opts} checkout clone hgclone link deploy update remove"
fi
;;
init | --help | --version | --tutorial | list | status | incoming | repair | clean | --force | --copy)
opts=""
;;
update-all | deploy-all | checkout | clone | hgclone | link)
opts="--force --no-clean --no-local"
;;
deploy | update)
opts="$(modman list) --force --no-clean --no-local --no-shell"
;;
remove)
opts=$(modman list)
;;
*)
[ -d "$mm/${prev}" ] && opts="--force --no-clean --no-local --no-shell"
;;
esac
COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) )
return 0
}
_modman_get_mm()
{
local root _pwd
_pwd=$(pwd)
root=$(pwd -P)
while ! [ -d $root/.modman ]; do
if [ "$root" = "/" ]; then
cd $_pwd && return 1
fi
cd ..
root=`pwd`
done
cd $_pwd
echo "$root/.modman"
}
_modman_get_module()
{
local root module modpath mm _pwd
_pwd=`pwd`
mm=$(_modman_get_mm)
[ -z "$mm" ] && return 1
root="$(dirname $mm)"
module=''
while [ "$root" != "$(pwd)" ]; do
modpath=`pwd`
if [ "$mm" = "$(dirname $modpath)" ]; then
module=$(basename $modpath)
break
fi
cd ..
done
cd $_pwd
[ -z "$module" ] && return 1
echo $module
}
complete -F _modman modman