Skip to content

Commit

Permalink
edit: fix a bug that the shell hangs with "source ble.sh --noattach &…
Browse files Browse the repository at this point in the history
…& ble-attach"
  • Loading branch information
akinomyoga committed Jan 18, 2020
1 parent c7d314f commit ce93c08
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 28 deletions.
20 changes: 10 additions & 10 deletions ble.pp
Original file line number Diff line number Diff line change
Expand Up @@ -591,18 +591,17 @@ function ble-attach {
return
fi

[[ $_ble_attached ]] && return
_ble_attached=1

# when detach flag is present
if [[ $_ble_edit_detach_flag ]]; then
case $_ble_edit_detach_flag in
(exit) ;;
(exit) return 0 ;;
(*) _ble_edit_detach_flag= ;; # cancel "detach"
esac
return 0
fi

[[ $_ble_attached ]] && return
_ble_attached=1

# 特殊シェル設定を待避
ble/base/adjust-bash-options
ble/base/adjust-POSIXLY_CORRECT
Expand All @@ -626,7 +625,6 @@ function ble-attach {
ble-edit/detach
return 1
fi
_ble_edit_detach_flag= # do not detach or exit

ble-edit/reset-history # 27s for bash-3.0

Expand All @@ -642,13 +640,15 @@ function ble-detach {
return
fi

[[ $_ble_attached ]] || return
_ble_attached=
[[ $_ble_attached && ! $_ble_edit_detach_flag ]] || return

# Note: 実際の detach 処理は ble-edit/bind/.check-detach で実行される
_ble_edit_detach_flag=${1:-detach} # schedule detach
}
function ble-detach/impl {
[[ $_ble_attached ]] || return
_ble_attached=

ble-edit/detach
ble-decode/detach
READLINE_LINE='' READLINE_POINT=0
Expand All @@ -663,10 +663,10 @@ function ble-detach/message {

function ble/base/unload-for-reload {
if [[ $_ble_attached ]]; then
_ble_attached=
ble-detach/impl
echo "${_ble_term_setaf[12]}[ble: reload]$_ble_term_sgr0" 1>&2
_ble_edit_detach_flag=reload
[[ $_ble_edit_detach_flag ]] ||
_ble_edit_detach_flag=reload
fi
ble/base/unload
return 0
Expand Down
33 changes: 15 additions & 18 deletions src/edit.sh
Original file line number Diff line number Diff line change
Expand Up @@ -7088,21 +7088,6 @@ function ble-edit/bind/.exit-TRAPRTMAX {
## @exit detach した場合に 0 を返します。それ以外の場合に 1 を返します。
##
function ble-edit/bind/.check-detach {
# Note: #D1130 reload の為に detach して attach しなかった場合
if [[ ! $_ble_attached && $_ble_edit_detach_flag == reload ]]; then
ble-detach/message \
"${_ble_term_setaf[12]}[ble: detached]$_ble_term_sgr0" \
"Please run \`stty sane' to recover the correct TTY state."

if ((_ble_bash>=40000)); then
READLINE_LINE='stty sane;' READLINE_POINT=10
printf %s "$READLINE_LINE"
fi

ble-edit/exec:gexec/.eval-prologue
return 0
fi

if [[ ! -o emacs && ! -o vi ]]; then
# 実は set +o emacs などとした時点で eval の評価が中断されるので、これを検知することはできない。
# 従って、現状ではここに入ってくることはないようである。
Expand All @@ -7115,7 +7100,8 @@ function ble-edit/bind/.check-detach {
_ble_edit_detach_flag=
#ble/term/visible-bell ' Bye!! '

ble-detach/impl
local attached=$_ble_attached
[[ $attached ]] && ble-detach/impl

if [[ $type == exit ]]; then
# ※この部分は現在使われていない。
Expand All @@ -7138,8 +7124,19 @@ function ble-edit/bind/.check-detach {
fi
fi

ble/base/restore-bash-options
ble/base/restore-POSIXLY_CORRECT
if [[ $attached ]]; then
# ここで ble-detach/impl した時は調整は最低限でOK
ble/base/restore-bash-options
ble/base/restore-POSIXLY_CORRECT
builtin eval "$_ble_base_restore_FUNCNEST" # これ以降関数は呼び出せない
else
# Note: 既に ble-detach/impl されていた時 (reload 時) は
# epilogue によって detach 後の状態が壊されているので
# 改めて prologue を呼び出す必要がある。
# #D1130 #D1199 #D1223
ble-edit/exec:"$bleopt_internal_exec_type"/.eval-prologue
fi

return 0
else
# Note: ここに入った時 -o emacs か -o vi のどちらかが成立する。なぜなら、
Expand Down

0 comments on commit ce93c08

Please sign in to comment.