diff --git a/CHANGELOG.md b/CHANGELOG.md index 0633cc6..63343ca 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -38,3 +38,9 @@ ## v2 update - The bottom empty row now visibly shows the cursor. - When TUI exits normally, the shell integration changes the parent Bash shell to the directory where TUI was closed. + +## v2 fix – interactive shell commands and exit directory + +- Fixed interactive action commands: the command loop no longer redirects stdin from the command file. +- Commands such as `unzip -l && read -rp "Enter..." || read -rp "FAILED..."` now receive input from the real terminal. +- The final TUI directory is always applied to the parent Bash shell when TUI exits, including Ctrl+C/SIGINT. diff --git a/tui/tui-shell.bash b/tui/tui-shell.bash index bf31f3f..d0a76ca 100644 --- a/tui/tui-shell.bash +++ b/tui/tui-shell.bash @@ -70,11 +70,16 @@ tui() { # change the parent Bash shell to the directory where TUI was # actually closed. This includes Ctrl+C (status 130). if (( rc != 42 )); then - cd "$tui_cwd" || { + # The TUI writes its actual final directory in cwd_file in its + # finally block. Always apply it to the parent Bash shell before + # handling the exit status, including SIGINT/Ctrl+C. + if cd "$tui_cwd"; then + rm -f "$command_file" "$cwd_file" + else + printf 'tui: cannot cd to final directory: %s\n' "$tui_cwd" >&2 rm -f "$command_file" "$cwd_file" return 1 - } - rm -f "$command_file" "$cwd_file" + fi if (( rc == 130 )); then return 0 fi @@ -90,7 +95,12 @@ tui() { return 1 } - while IFS= read -r cmd; do + # Do not redirect stdin while executing commands: commands may need + # interactive input (for example `read`, `joe`, or `less`). Read the + # command list into an array first, then let each command inherit the + # real terminal stdin. + mapfile -t tui_commands < "$command_file" + for cmd in "${tui_commands[@]}"; do [[ -z "$cmd" ]] && continue history -s -- "$cmd" @@ -102,7 +112,7 @@ tui() { read -rp 'Tryck Enter för att fortsätta...' _ break fi - done < "$command_file" + done popd >/dev/null || true