-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathfunctions.sh
74 lines (67 loc) · 1.83 KB
/
functions.sh
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
# Packages autocomplete
_get_packages_autocomplete()
{
_init_completion || return
COMPREPLY=($(apt-cache --no-generate pkgnames "$cur" 2>/dev/null))
return 0
}
# Packages remove autocomplete
_get_packages_remove_autocomplete ()
{
local cur opt;
COMPREPLY=();
cur="${COMP_WORDS[COMP_CWORD]}";
if [ -f /etc/debian_version ]; then
COMPREPLY=($( _xfunc dpkg _comp_dpkg_installed_packages $cur ));
else
_xfunc rpm _rpm_installed_packages;
fi;
return 0
}
# Service autocomplete
_get_service_autocomplete()
{
local cur prev words cword;
_init_completion || return;
[[ $cword -gt 2 ]] && return 0;
if [[ $cword -eq 1 && $prev == ?(*/)S ]]; then
_services;
[[ -e /etc/mandrake-release ]] && _xinetd_services;
else
local sysvdirs;
_sysvdirs;
COMPREPLY=($( compgen -W '`sed -e "y/|/ /" \
-ne "s/^.*\(U\|msg_u\)sage.*{\(.*\)}.*$/\2/p" \
${sysvdirs[0]}/${prev##*/} 2>/dev/null` start stop' -- "$cur" ));
fi
}
# Autocomplete wrapper function
# URL: http://unix.stackexchange.com/questions/4219/how-do-i-get-bash-completion-for-command-aliases
make_completion_wrapper () {
local function_name="$2"
local arg_count=$(($#-3))
local comp_function_name="$1"
shift 2
local function="
function $function_name {
((COMP_CWORD+=$arg_count))
COMP_WORDS=( "$@" \${COMP_WORDS[@]:1} )
"$comp_function_name"
return 0
}"
eval "$function"
}
# Get current branch in git repo
function parse_git_branch() {
BRANCH=`git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/\1/'`
if [ ! "${BRANCH}" == "" ]
then
echo "[${BRANCH}] "
else
echo ""
fi
}
# Check if a command exists
command_exists () {
type "$1" &> /dev/null ;
}