Ticket #2945 (new defect)

Opened 6 years ago

MC does not update $PS1 after internal file operations

Reported by: marcel Owned by:
Priority: trivial Milestone: Future Releases
Component: mc-core Version: 4.8.7
Keywords: Cc:
Blocked By: Blocking:
Branch state: no branch Votes for changeset:


I have the following $PS1 prompt in my ~/.bashrc:

function git_prompt() {
	status="$(git status 2>/dev/null)"
	[[ $? != 0 ]] && return;
	output="$(echo "$status" | awk '/# Initial commit/ {print "init"}')"
	[[ "$output" ]] || output="$(echo "$status" | awk '/# On branch/ {print $4}')"
		echo "$status" | awk 'BEGIN {r=""} \
			/^# Changes to be committed:$/        {r="*"}\
			/^# Changes not staged for commit:$/  {r="*"}\
			/^# Untracked files:$/                {r="*"}\
			END {print r}'
	if [[ "$flags" ]]; then
	echo " ($output)"

PS1='[\w]$(git_prompt)\$ '

Function git_prompt displays the current git branch with an added asterisk ($flags) when the source tree is dirty, i.e. there is something to commit. When working from the shell, the flag is updated after each command. When working in MC, the flag doesn't change after file operations using internal commands. I suspect MC only evaluates $PS1 after directory changes and external file operations (using the command line in MC).

Steps to reproduce:

  1. Add above code snippet to ~/.bashrc to get this git prompt.
  2. Create a new directory and a git repository in it (git init). git_prompt now reads " (init)".
  3. Start MC
  4. Create new file 'foo' using Shift-F4 and save it.
  5. git_prompt is still " (init)", where it should be " (init*)".
  6. Change directory and go back.
  7. git_prompt now correctly reads " (init*)".
  8. Delete 'foo' using F8.
  9. git_prompt is still " (init*)", where it should be " (init)".

Using shell commands like 'echo "bar">foo' and 'rm foo' within MC results in correct behaviour.


MC should update $PS1 even after each internal file operation.


GNU Midnight Commander 4.8.7
Built with GLib 2.34.3
Using the S-Lang library with terminfo database
With builtin Editor
With subshell support as default
With support for background operations
With mouse support on xterm and Linux console
With support for X11 events
With internationalization support
With multiple codepages support
Virtual File Systems: cpiofs, tarfs, sfs, extfs, ftpfs, sftpfs, fish, smbfs
Data types: char: 8; int: 32; long: 32; void *: 32; size_t: 32; off_t: 64;
Root directory: /home/mk

[System data]
    Config directory: /etc/mc/
    Data directory:   /usr/share/mc/
    File extension handlers: /usr/lib/mc/ext.d/
    VFS plugins and scripts: /usr/lib/mc/
	extfs.d:        /usr/lib/mc/extfs.d/
	fish:           /usr/lib/mc/fish/

[User data]
    Config directory: /home/mk/.config/mc/
    Data directory:   /home/mk/.local/share/mc/
	skins:          /home/mk/.local/share/mc/skins/
	extfs.d:        /home/mk/.local/share/mc/extfs.d/
	fish:           /home/mk/.local/share/mc/fish/
	mcedit macros:  /home/mk/.local/share/mc/mc.macros
	mcedit external macros: /home/mk/.local/share/mc/mcedit/macros.d/macro.*
    Cache directory:  /home/mk/.cache/mc/
$ mc --configure-options
 '--prefix=/usr' '--sysconfdir=/etc' '--enable-vfs-smb' '--with-x' '--libexecdir=/usr/lib' 'CFLAGS=-march=i686 -mtune=generic -O2 -pipe -fstack-protector --param=ssp-buffer-size=4 -D_FORTIFY_SOURCE=2' 'LDFLAGS=-Wl,-O1,--sort-common,--as-needed,-z,relro'
$ uname -a
Linux eeebox 3.6.10-1-ARCH #1 SMP PREEMPT Tue Dec 11 10:19:36 CET 2012 i686 GNU/Linux
Note: See TracTickets for help on using tickets.