Skip to content

Commit 9c1e17b

Browse files
authored
Addtional fixes for shellcheck (#137)
* Disable remaining shellcheck false warning * Avoid passing empty argument to `return` * Avoid word splitting of the exit status * Follow the shellcheck suggestion
1 parent a131ff9 commit 9c1e17b

File tree

1 file changed

+4
-4
lines changed

1 file changed

+4
-4
lines changed

bash-preexec.sh

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,7 @@ bash_preexec_imported="defined"
5555

5656
# WARNING: This variable is no longer used and should not be relied upon.
5757
# Use ${bash_preexec_imported} instead.
58+
# shellcheck disable=SC2034
5859
__bp_imported="${bash_preexec_imported}"
5960

6061
# Should be available to each precmd and preexec
@@ -177,7 +178,7 @@ __bp_precmd_invoke_cmd() {
177178
# precmd functions. This is available for instance in zsh. We can simulate it in bash
178179
# by setting the value here.
179180
__bp_set_ret_value() {
180-
return "${1:-}"
181+
return ${1:+"$1"}
181182
}
182183

183184
__bp_in_prompt_command() {
@@ -268,7 +269,7 @@ __bp_preexec_invoke_exec() {
268269
# Only execute each function if it actually exists.
269270
# Test existence of function with: declare -[fF]
270271
if type -t "$preexec_function" 1>/dev/null; then
271-
__bp_set_ret_value ${__bp_last_ret_value:-}
272+
__bp_set_ret_value "${__bp_last_ret_value:-}"
272273
# Quote our function invocation to prevent issues with IFS
273274
"$preexec_function" "$this_command"
274275
preexec_function_ret_value="$?"
@@ -325,8 +326,7 @@ __bp_install() {
325326
local existing_prompt_command
326327
# Remove setting our trap install string and sanitize the existing prompt command string
327328
existing_prompt_command="${PROMPT_COMMAND:-}"
328-
# shellcheck disable=SC1087
329-
existing_prompt_command="${existing_prompt_command//$__bp_install_string[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
329+
existing_prompt_command="${existing_prompt_command//${__bp_install_string}[;$'\n']}" # Edge case of appending to PROMPT_COMMAND
330330
existing_prompt_command="${existing_prompt_command//$__bp_install_string}"
331331
__bp_sanitize_string existing_prompt_command "$existing_prompt_command"
332332

0 commit comments

Comments
 (0)