Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to make Midnight Commander exit to its current directory

Tags:

I've been using, in equal amounts, Fedora and Ubuntu for well over a decade now, and there's one minor but irritating difference I noticed from their installs of midnight commander. When you change dirs inside it using Fedora, then exit, it has done the chdir for you but in Ubuntu it keeps it at the place you started. Googling threw up a solution for older Ubuntus here: http://ptspts.blogspot.co.uk/2010/01/how-to-make-midnight-commander-exit-to.html but trying that fails on 16. When I say fails, I mean the commands are accepted without complaint but it doesn't change mc's behaviour in Ubuntu.

like image 926
Carl Whalley Avatar asked Aug 18 '16 11:08

Carl Whalley


People also ask

How do I get out of Midnight Commander?

To quit mc, use key F10.

What does midnight commander do?

Midnight Commander is a console application with a text user interface. The main interface consists of two panels which display the file system. File selection is done using arrow keys, the insert key is used to select files and the function keys perform operations such as renaming, editing and copying files.


2 Answers

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'
like image 80
soger Avatar answered Sep 28 '22 09:09

soger


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
like image 28
Kolyunya Avatar answered Sep 28 '22 08:09

Kolyunya