66# Generic utilies
77# ##########################################################################
88
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} "
9+ function _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} "
1616}
1717
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
18+ function _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} "
2626}
2727
2828# This function searches an array for an exact match against the term passed
@@ -44,99 +44,97 @@ _bash-it-get-component-type-from-path() {
4444# contains pear!
4545#
4646#
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
47+ function _bash-it-array-contains-element() {
48+ local e
49+ for e in " ${@: 2} " ; do
50+ [[ " $e " == " $1 " ]] && return 0
51+ done
52+ return 1
5353}
5454
5555# Dedupe a simple array of words without spaces.
56- _bash-it-array-dedup () {
56+ function _bash-it-array-dedup() {
5757 local IFS=$' \n '
58- echo " $@ " | tr ' ' ' \n' | sort -u
58+ echo " $@ " | tr ' ' ' \n' | sort -u
5959}
6060
6161# Outputs a full path of the grep found on the filesystem
62- function _bash-it-grep()
63- {
62+ function _bash-it-grep() {
6463 : " ${BASH_IT_GREP:= $(type -p egrep || type -p grep)} "
6564 printf " %s" " ${BASH_IT_GREP:- ' /usr/bin/grep' } "
6665}
6766
68-
6967# ##########################################################################
7068# Component-specific functions (component is either an alias, a plugin, or a
7169# completion).
7270# ##########################################################################
7371
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} "
8582}
8683
8784function _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} "
9390}
9491
95- _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} "
92+ function _bash-it-pluralize-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} "
10299}
103100
104- _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
101+ function _bash-it-clean-component-cache() {
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
118115}
119116
120117# Returns an array of items within each compoenent.
121- _bash-it-component-list () {
122- local IFS=$' \n ' component=" $1 "
123- _bash-it-component-help " ${component} " | awk ' {print $1}' | sort -u
118+ function _bash-it-component-list() {
119+ local IFS=$' \n ' component=" $1 "
120+ _bash-it-component-help " ${component} " | awk ' {print $1}' | sort -u
124121}
125122
126- _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
123+ function _bash-it-component-list-matching() {
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
130128}
131129
132- _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
130+ function _bash-it-component-list-enabled() {
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
135133}
136134
137- _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
135+ function _bash-it-component-list-disabled() {
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
140138}
141139
142140# Checks if a given item is enabled for a particular component/file-type.
@@ -147,10 +145,10 @@ _bash-it-component-list-disabled() {
147145#
148146# Examples:
149147# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
150- _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"
148+ function _bash-it-component-item-is-enabled() {
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"
154152}
155153
156154# Checks if a given item is disabled for a particular component/file-type.
@@ -161,8 +159,8 @@ _bash-it-component-item-is-enabled() {
161159#
162160# Examples:
163161# _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled"
164- _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"
162+ function _bash-it-component-item-is-disabled() {
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"
168166}
0 commit comments