7
7
# ##########################################################################
8
8
9
9
_bash-it-get-component-name-from-path () {
10
- # filename without path
11
- filename=" ${1##*/ } "
12
- # filename without path or priority
13
- filename=" ${filename##* ---} "
14
- # filename without path, priority or extension
15
- echo " ${filename% .* .bash} "
10
+ # filename without path
11
+ filename=" ${1##*/ } "
12
+ # filename without path or priority
13
+ filename=" ${filename##* ---} "
14
+ # filename without path, priority or extension
15
+ echo " ${filename% .* .bash} "
16
16
}
17
17
18
18
_bash-it-get-component-type-from-path () {
19
- # filename without path
20
- filename=" ${1##*/ } "
21
- # filename without extension
22
- filename=" ${filename% .bash} "
23
- # extension without priority or name
24
- filename=" ${filename##* .} "
25
- echo " ${filename} " # | cut -d '.' -f 2
19
+ # filename without path
20
+ filename=" ${1##*/ } "
21
+ # filename without extension
22
+ filename=" ${filename% .bash} "
23
+ # extension without priority or name
24
+ filename=" ${filename##* .} "
25
+ echo " ${filename} "
26
26
}
27
27
28
28
# This function searches an array for an exact match against the term passed
@@ -45,98 +45,96 @@ _bash-it-get-component-type-from-path() {
45
45
#
46
46
#
47
47
_bash-it-array-contains-element () {
48
- local e
49
- for e in " ${@: 2} " ; do
50
- [[ " $e " == " $1 " ]] && return 0
51
- done
52
- return 1
48
+ local e
49
+ for e in " ${@: 2} " ; do
50
+ [[ " $e " == " $1 " ]] && return 0
51
+ done
52
+ return 1
53
53
}
54
54
55
55
# Dedupe a simple array of words without spaces.
56
56
_bash-it-array-dedup () {
57
57
local IFS=$' \n '
58
- echo " $@ " | tr ' ' ' \n' | sort -u
58
+ echo " $@ " | tr ' ' ' \n' | sort -u
59
59
}
60
60
61
61
# Outputs a full path of the grep found on the filesystem
62
- function _bash-it-grep()
63
- {
62
+ function _bash-it-grep() {
64
63
: " ${BASH_IT_GREP:= $(type -p egrep || type -p grep)} "
65
64
printf " %s" " ${BASH_IT_GREP:- ' /usr/bin/grep' } "
66
65
}
67
66
68
-
69
67
# ##########################################################################
70
68
# Component-specific functions (component is either an alias, a plugin, or a
71
69
# completion).
72
70
# ##########################################################################
73
71
74
- function _bash-it-component-help()
75
- {
76
- local component file func
77
- component=" $( _bash-it-pluralize-component " ${1} " ) "
78
- file=" $( _bash-it-component-cache-file " ${component} " ) "
79
- if [[ ! -s " ${file} " || -z " $( find " ${file} " -mmin -300) " ]] ; then
80
- rm -f " ${file} " 2> /dev/null
81
- func=" _bash-it-${component} "
82
- " ${func} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E ' \[' > " ${file} "
83
- fi
84
- cat " ${file} "
72
+ function _bash-it-component-help() {
73
+ local component file func
74
+ component=" $( _bash-it-pluralize-component " ${1} " ) "
75
+ file=" $( _bash-it-component-cache-file " ${component} " ) "
76
+ if [[ ! -s " ${file} " || -z " $( find " ${file} " -mmin -300) " ]]; then
77
+ rm -f " ${file} " 2> /dev/null
78
+ func=" _bash-it-${component} "
79
+ " ${func} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E ' \[' > " ${file} "
80
+ fi
81
+ cat " ${file} "
85
82
}
86
83
87
84
function _bash-it-component-cache-file() {
88
- local component file
89
- component=" $( _bash-it-pluralize-component " ${1} " ) "
90
- file=" ${BASH_IT} /tmp/cache/${component} "
91
- [[ -f " ${file} " ]] || mkdir -p " ${file%/* } "
92
- printf ' %s' " ${file} "
85
+ local component file
86
+ component=" $( _bash-it-pluralize-component " ${1} " ) "
87
+ file=" ${BASH_IT? } /tmp/cache/${component} "
88
+ [[ -f " ${file} " ]] || mkdir -p " ${file%/* } "
89
+ printf ' %s' " ${file} "
93
90
}
94
91
95
92
_bash-it-pluralize-component () {
96
- local component=" ${1} "
97
- local -i len=$(( ${# component} - 1 ))
98
- # pluralize component name for consistency
99
- [[ " ${component: ${len} : 1} " != ' s' ]] && component=" ${component} s"
100
- [[ " ${component} " == " alias" ]] && component=" aliases"
101
- printf ' %s' " ${component} "
93
+ local component=" ${1} "
94
+ local -i len=$(( ${# component} - 1 ))
95
+ # pluralize component name for consistency
96
+ [[ " ${component: ${len} : 1} " != ' s' ]] && component=" ${component} s"
97
+ [[ " ${component} " == " alias" ]] && component=" aliases"
98
+ printf ' %s' " ${component} "
102
99
}
103
100
104
101
_bash-it-clean-component-cache () {
105
- local component=" $1 "
106
- local cache
107
- local -a BASH_IT_COMPONENTS=(aliases plugins completions)
108
- if [[ -z " ${component} " ]] ; then
109
- for component in " ${BASH_IT_COMPONENTS[@]} " ; do
110
- _bash-it-clean-component-cache " ${component} "
111
- done
112
- else
113
- cache=" $( _bash-it-component-cache-file " ${component} " ) "
114
- if [[ -f " ${cache} " ]] ; then
115
- rm -f " ${cache} "
116
- fi
117
- fi
102
+ local component=" $1 "
103
+ local cache
104
+ local -a BASH_IT_COMPONENTS=(aliases plugins completions)
105
+ if [[ -z " ${component} " ]]; then
106
+ for component in " ${BASH_IT_COMPONENTS[@]} " ; do
107
+ _bash-it-clean-component-cache " ${component} "
108
+ done
109
+ else
110
+ cache=" $( _bash-it-component-cache-file " ${component} " ) "
111
+ if [[ -f " ${cache} " ]]; then
112
+ rm -f " ${cache} "
113
+ fi
114
+ fi
118
115
}
119
116
120
117
# Returns an array of items within each compoenent.
121
118
_bash-it-component-list () {
122
- local IFS=$' \n ' component=" $1 "
123
- _bash-it-component-help " ${component} " | awk ' {print $1}' | sort -u
119
+ local IFS=$' \n ' component=" $1 "
120
+ _bash-it-component-help " ${component} " | awk ' {print $1}' | sort -u
124
121
}
125
122
126
123
_bash-it-component-list-matching () {
127
- local component=" $1 " ; shift
128
- local term=" $1 "
129
- _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -- " ${term} " | awk ' {print $1}' | sort -u
124
+ local component=" $1 "
125
+ shift
126
+ local term=" $1 "
127
+ _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -- " ${term} " | awk ' {print $1}' | sort -u
130
128
}
131
129
132
130
_bash-it-component-list-enabled () {
133
- local IFS=$' \n ' component=" $1 "
134
- _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E ' \[x\]' | awk ' {print $1}' | sort -u
131
+ local IFS=$' \n ' component=" $1 "
132
+ _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E ' \[x\]' | awk ' {print $1}' | sort -u
135
133
}
136
134
137
135
_bash-it-component-list-disabled () {
138
- local IFS=$' \n ' component=" $1 "
139
- _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -v ' \[x\]' | awk ' {print $1}' | sort -u
136
+ local IFS=$' \n ' component=" $1 "
137
+ _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -v ' \[x\]' | awk ' {print $1}' | sort -u
140
138
}
141
139
142
140
# Checks if a given item is enabled for a particular component/file-type.
@@ -148,9 +146,9 @@ _bash-it-component-list-disabled() {
148
146
# Examples:
149
147
# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
150
148
_bash-it-component-item-is-enabled () {
151
- local component=" $1 "
152
- local item=" $2 "
153
- _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E ' \[x\]' | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -q -- " ^${item} \s"
149
+ local component=" $1 "
150
+ local item=" $2 "
151
+ _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E ' \[x\]' | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -q -- " ^${item} \s"
154
152
}
155
153
156
154
# Checks if a given item is disabled for a particular component/file-type.
@@ -162,7 +160,7 @@ _bash-it-component-item-is-enabled() {
162
160
# Examples:
163
161
# _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled"
164
162
_bash-it-component-item-is-disabled () {
165
- local component=" $1 "
166
- local item=" $2 "
167
- _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -v ' \[x\]' | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -q -- " ^${item} \s"
163
+ local component=" $1 "
164
+ local item=" $2 "
165
+ _bash-it-component-help " ${component} " | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -v ' \[x\]' | ${BASH_IT_GREP:- $(_bash-it-grep)} -E -q -- " ^${item} \s"
168
166
}
0 commit comments