Ticket #2945 (new defect)
Opened 12 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: |
Description
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}')" flags="$( 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 output="$output$flags" fi 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:
- Add above code snippet to ~/.bashrc to get this git prompt.
- Create a new directory and a git repository in it (git init). git_prompt now reads " (init)".
- Start MC
- Create new file 'foo' using Shift-F4 and save it.
- git_prompt is still " (init)", where it should be " (init*)".
- Change directory and go back.
- git_prompt now correctly reads " (init*)".
- Delete 'foo' using F8.
- 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.
Proposal:
MC should update $PS1 even after each internal file operation.
Version:
$ LC_MESSAGES=C mc -V 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; $ LC_MESSAGES=C mc -F 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