Skip to content

Commit 9bb19f7

Browse files
committed
lib/utilities: shfmt
My apologies to future `git blame` hunters ♥
1 parent 77988c6 commit 9bb19f7

File tree

2 files changed

+73
-72
lines changed

2 files changed

+73
-72
lines changed

clean_files.txt

+3
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,9 @@ completion/available/vault.completion.bash
7474
completion/available/vuejs.completion.bash
7575
completion/available/wpscan.completion.bash
7676

77+
# libraries
78+
lib/utilities.bash
79+
7780
# plugins
7881
#
7982
plugins/available/alias-completion.plugin.bash

lib/utilities.bash

+70-72
Original file line numberDiff line numberDiff line change
@@ -7,22 +7,22 @@
77
###########################################################################
88

99
_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}"
1616
}
1717

1818
_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}"
2626
}
2727

2828
# This function searches an array for an exact match against the term passed
@@ -45,98 +45,96 @@ _bash-it-get-component-type-from-path() {
4545
#
4646
#
4747
_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
5353
}
5454

5555
# Dedupe a simple array of words without spaces.
5656
_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

8784
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}"
9390
}
9491

9592
_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}"
10299
}
103100

104101
_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
118115
}
119116

120117
# Returns an array of items within each compoenent.
121118
_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
124121
}
125122

126123
_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
130128
}
131129

132130
_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
135133
}
136134

137135
_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
140138
}
141139

142140
# Checks if a given item is enabled for a particular component/file-type.
@@ -148,9 +146,9 @@ _bash-it-component-list-disabled() {
148146
# Examples:
149147
# _bash-it-component-item-is-enabled alias git && echo "git alias is enabled"
150148
_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"
154152
}
155153

156154
# Checks if a given item is disabled for a particular component/file-type.
@@ -162,7 +160,7 @@ _bash-it-component-item-is-enabled() {
162160
# Examples:
163161
# _bash-it-component-item-is-disabled alias git && echo "git aliases are disabled"
164162
_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"
168166
}

0 commit comments

Comments
 (0)