Skip to content

Commit

Permalink
global: fix subshell detection in Bash 3.2
Browse files Browse the repository at this point in the history
  • Loading branch information
akinomyoga committed Jan 6, 2020
1 parent 6311cea commit 4b5a458
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
4 changes: 2 additions & 2 deletions ble.pp
Expand Up @@ -187,7 +187,7 @@ function ble/bin/.freeze-utility-path {

# POSIX utilities

_ble_init_posix_command_list=(sed date rm mkdir mkfifo sleep stty sort awk chmod grep man cat wc mv)
_ble_init_posix_command_list=(sed date rm mkdir mkfifo sleep stty sort awk chmod grep man cat wc mv sh)
function ble/.check-environment {
if ! type "${_ble_init_posix_command_list[@]}" &>/dev/null; then
local cmd commandMissing=
Expand Down Expand Up @@ -651,7 +651,7 @@ function ble/base/unload-for-reload {
return 0
}
function ble/base/unload {
[[ $$ == $BASHPID ]] || return
ble/util/is-running-in-subshell && return 1
local IFS=$' \t\n'
ble/term/stty/TRAPEXIT
ble/term/leave
Expand Down
2 changes: 1 addition & 1 deletion src/edit.sh
Expand Up @@ -3519,7 +3519,7 @@ function ble-edit/exec/restore-BASH_REMATCH {

function ble/builtin/exit {
local ext=${1-$?}
if ((BASHPID!=$$)) || [[ $_ble_decode_bind_state == none ]]; then
if ble/util/is-running-in-subshell || [[ $_ble_decode_bind_state == none ]]; then
builtin exit "$ext"
return
fi
Expand Down
12 changes: 12 additions & 0 deletions src/util.sh
Expand Up @@ -895,6 +895,18 @@ else
function ble/util/is-stdin-ready { false; }
fi

# Note: BASHPID は Bash-4.0 以上
if ((_ble_bash>=40000)); then
function ble/util/is-running-in-subshell { [[ $$ != $BASHPID ]]; }
else
function ble/util/is-running-in-subshell {
((BASH_SUBSHELL)) && return 0
local bashpid= command='echo $PPID'
ble/util/assign bashpid 'ble/bin/sh -c "$command"'
[[ $$ != $bashpid ]]
}
fi

## 関数 ble/util/openat fdvar redirect
## "exec {fdvar}>foo" に該当する操作を実行します。
## @param[out] fdvar
Expand Down

0 comments on commit 4b5a458

Please sign in to comment.