3

I have next bash function to ensure new-lines after commands:

user at terra in ~
$ echo "m"
m
user at terra in ~
$ echo -n "m"
m↵

And the function itself in a .bashrc:

function prompt_command {
    # get cursor position and add new line if we're not in first column
    echo -en "\033[6n" && read -sdR CURPOS
    [[ ${CURPOS##*;} -gt 1 ]] && echo "$(tput setab 1)↵$prompt_reset"
}
PROMPT_COMMAND=prompt_command

When I have PROMPT_COMMAND set - the MC starts from 10 to 30 seconds, but when commented - almost instantly.

Why is the, and how can this be fixed without disabling this issue?

strace, better to look around 13:59:06, there's a 9 seconds delay there... (normal strace for compare)

8
  • 1
    Why not attach to mc with gdb or strace, check where it is waiting and add this info to your question?
    – user17530
    Oct 3, 2014 at 5:45
  • @skwllsp Added, I think this would be enough.
    – m0nhawk
    Oct 3, 2014 at 6:02
  • strace -c is a wrong idea. What you need to do it to attach with strace in another session to your MC process when it suddenly freezes. something like strace -t -f -p $(pidof mc). Or to do the same with gdb
    – user17530
    Oct 3, 2014 at 6:10
  • It starts long. Between I press enter after mc and can actually see the mc.
    – m0nhawk
    Oct 3, 2014 at 6:12
  • If so you can instead of running mc run strace -f -t -o calls.txt mc` and look for long syscalls in calls.txt.
    – user17530
    Oct 3, 2014 at 6:16

2 Answers 2

3

It is waiting for input from stdin, as far as I understand.

`3021  13:58:57 read(0,  <unfinished ...>
3019  13:59:06 <... select resumed> )   = 0 (Timeout)`

You need to find what it is doing. However my guess:

read -sdR CURPOS

You can remove this read in order to try to fix the problem or change its timeout

1
  • Yes, this is read, thanks. Now I need to think how to improve this answer.
    – m0nhawk
    Oct 3, 2014 at 11:57
2

MC runs bash in a terminal. It leaves TERM set to the same value as the terminal that MC is running in, but it appears that it buffers or filters some exchanges between the inferior shell and the terminal.

You may want to use different customizations when bash is running as a direct subprocess of MC. Since MC's inferior shell only shows the prompt line, there isn't much point in worrying about the cursor position: just systematically add a newline.

if [[ "$(ps -o comm= -p $PPID)" == "mc" ]]; then
  PS1=$'\n'$PS1
else
  function prompt_command {
    # get cursor position and add new line if we're not in first column
    echo -en "\033[6n" && read -sdR CURPOS
    [[ ${CURPOS##*;} -gt 1 ]] && echo "$(tput setab 1)↵$prompt_reset"
  }
  PROMPT_COMMAND=prompt_command
fi

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .