Skip to content

Commit e579058

Browse files
adamprice2Adam Price
andauthored
Update to remove shellcheck warnings (#135)
* add shellcheck # shellcheck shell=bash directive to allow linting * BP_PIPESTATUS may be unused in function __bp_precmd_invoke_cmd, ignore * line 174 - SC2086 (info): Double quote to prevent globbing and word splitting. * line 249 false alarm 'SC1007 (warning): Remove space after = ', added ignore. * line 294 SC2155 (warning): Declare and assign separately to avoid masking return values. * line 295 SC2001 (style): See if you can use ${variable//search/replace}. Added ignore * line 323 SC1087 (error): Use braces when expanding arrays. Disable warning * fix indentation * line 249 false alarm 'SC1007 (warning): empty space to '' removed shellcheck directive Co-authored-by: Adam Price <[email protected]>
1 parent 8bfcb39 commit e579058

File tree

1 file changed

+13
-3
lines changed

1 file changed

+13
-3
lines changed

bash-preexec.sh

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@
3232
# using: the "DEBUG" trap, and the "PROMPT_COMMAND" variable. If you override
3333
# either of these after bash-preexec has been installed it will most likely break.
3434

35+
# Tell shellcheck what kind of file this is.
36+
# shellcheck shell=bash
37+
3538
# Make sure this is bash that's running and return otherwise.
3639
# Use POSIX syntax for this line:
3740
if [ -z "${BASH_VERSION-}" ]; then
@@ -135,6 +138,9 @@ __bp_interactive_mode() {
135138
__bp_precmd_invoke_cmd() {
136139
# Save the returned value from our last command, and from each process in
137140
# its pipeline. Note: this MUST be the first thing done in this function.
141+
# BP_PIPESTATUS may be unused, ignore
142+
# shellcheck disable=SC2034
143+
138144
__bp_last_ret_value="$?" BP_PIPESTATUS=("${PIPESTATUS[@]}")
139145

140146
# Don't invoke precmds if we are inside an execution of an "original
@@ -165,7 +171,7 @@ __bp_precmd_invoke_cmd() {
165171
# precmd functions. This is available for instance in zsh. We can simulate it in bash
166172
# by setting the value here.
167173
__bp_set_ret_value() {
168-
return ${1:-}
174+
return "${1:-}"
169175
}
170176

171177
__bp_in_prompt_command() {
@@ -239,7 +245,7 @@ __bp_preexec_invoke_exec() {
239245
local this_command
240246
this_command=$(
241247
export LC_ALL=C
242-
HISTTIMEFORMAT= builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //'
248+
HISTTIMEFORMAT='' builtin history 1 | sed '1 s/^ *[0-9][0-9]*[* ] //'
243249
)
244250

245251
# Sanity check to make sure we have something to invoke our function with.
@@ -284,7 +290,10 @@ __bp_install() {
284290
trap '__bp_preexec_invoke_exec "$_"' DEBUG
285291

286292
# Preserve any prior DEBUG trap as a preexec function
287-
local prior_trap=$(sed "s/[^']*'\(.*\)'[^']*/\1/" <<<"${__bp_trap_string:-}")
293+
local prior_trap
294+
# we can't easily do this with variable expansion. Leaving as sed command.
295+
# shellcheck disable=SC2001
296+
prior_trap=$(sed "s/[^']*'\(.*\)'[^']*/\1/" <<<"${__bp_trap_string:-}")
288297
unset __bp_trap_string
289298
if [[ -n "$prior_trap" ]]; then
290299
eval '__bp_original_debug_trap() {
@@ -310,6 +319,7 @@ __bp_install() {
310319
local existing_prompt_command
311320
# Remove setting our trap install string and sanitize the existing prompt command string
312321
existing_prompt_command="${PROMPT_COMMAND:-}"
322+
# shellcheck disable=SC1087
313323
existing_prompt_command="${existing_prompt_command//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
314324
existing_prompt_command="${existing_prompt_command//$__bp_install_string}"
315325
__bp_sanitize_string existing_prompt_command "$existing_prompt_command"

0 commit comments

Comments
 (0)