How to make Midnight Commander exit to its current directory

The other responses are fine, but I feel like they are unsatisfying, here is my solution, which I think is the simplest:

Put this line into your ~/.profile

alias mc='source /usr/lib/mc/mc-wrapper.sh'

Create an executable with the following content:

MC_USER=`id | sed 's/[^(]*(//;s/).*//'`
MC_PWD_FILE="${TMPDIR-/tmp}/mc-$MC_USER/mc.pwd.$$"
/usr/bin/mc -P "$MC_PWD_FILE" "$@"

if test -r "$MC_PWD_FILE"; then
        MC_PWD="`cat "$MC_PWD_FILE"`"
        if test -n "$MC_PWD" && test -d "$MC_PWD"; then
                cd "$MC_PWD"
        fi
        unset MC_PWD
fi

rm -f "$MC_PWD_FILE"
unset MC_PWD_FILE

Then define an alias pointing to that executable:

alias mc='. ~/.config/mc/exitcwd'

Don't forget to apply the alias:

source ~/.bashrc

Simple:

mcedit ~/.profile

Add this line at the end of file:

alias mc='source /usr/lib/mc/mc-wrapper.sh'

Type this command to execute changes

source ~/.profile

Then, to save both sides of mc windows, click at the top of MC

Options -> Panel options -> Auto save panels setup

Tags:

Mc