RSS

Surviving Mac OS X bash terminal with Midnight Commander (MC)

09 Sep

Abstract : Midnight Commander (MC) is one of the few tools I’m still using since I’ve been inducted into software engineering more than 10 years ago (for comparison I’ve changed 5 integrated development environments (IDE) ). MC is classified as “a visual file manager” but for me is something much more, it’s an engineering booster. In fact it’s my fist IDE (MCedit supports color highlighting for various programming languages). In short, MC is one of those few things that changes your world. That’s why I’m going to show you how you can painlessly integrate MC with Mac OS X bash terminal.

Goal : Configuring Midnight Commander under Mac OS X bash terminal

Acknowledgement : My gratitude goes to the open source community and especially to:
Miguel de Icaza – creator of Midnight Commander, Gnome, Mono, Gnumeric (and I guess other cool stuff)

Let’s get started!

Installation: I’m a huge fan of homebrew (thanks Max!) and I advise you to install it and work with it. In short, Homebrew is “the missing package manager for OS X”. Installing Homebrew is as easy as running the following command in the terminal prompt:

ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)   

Once you have Homebrew, installing MC is exactly three words:

brew install mc

Side note: You may wish to install bash-completion and take advantage of the Tab key on the terminal prompt. If so, do the following:

brew install bash-completion

… and ensure that your .bash_profile has the following content inside:

if [ -f `brew --prefix`/etc/bash_completion ]; then
    . `brew --prefix`/etc/bash_completion
fi

Note that you have to perform:

source .bash_profile 

or re-open your terminal for the changes to take effect.

Mac OS X – fixing the shortcuts mess: No, I have no idea why the Apple guys have created such a big mess with the keyboard shortcuts. And yes, it’s up to you, my dearest reader, to decide if you want to fix it as I suggest. Here is what I’ve done so that I can use my Functional keys (the F keys):

Go to:

System Preferences -> Keyboard -> Keyboard and Shortcuts

… and make sure you have All controls checked

After that go to:

System Preferences -> Keyboard -> Keyboard

… and make sure you have Use all F1, F2 etc. keys as standard function keys checked

Next open a Terminal and go to:

Terminal -> Preferences ... -> Keyboard

… and make sure you have Use option as meta key unchecked.

Now, every F9 will enable MC menu bar and every F10 button press will exit MC (instead of doing a complex fingers split which may not work but which will certainly hurt your hand).

Playing with MC shortcuts: What about the cool MC shortcuts? Before I present you with some of the shortcuts mapping you should be aware that pressing two times the Esc button will close any MC pop-up or search box, and that there are three types of shortcuts:

  1. Pressing (and releasing) Esc and then pressing another key
  2. Pressing and holding Ctrl and then pressing another key
  3. Using the Functional key

Here are some mappings:

----- Esc -----
Quick change directory: Esc + c
Quick change directory history: Esc + c and then Esc + h
Quick change directory previous entry: Esc + c and then Esc + p
Command line history: Esc + h
Command line previous command: Esc + p
View change: Esc + t (each time you do this shortcut a new directory view will appear)
Print current working directory in command line: Esc + a
Switch between background command line and MC: Ctrl + o
Search/Go to directory in active panel: Esc + s / Ctrl + s then start typing directory name
Open same working directory in the inactive panel: Esc + i
Open parent working directory in the inactive panel: Esc + o
Go to top of directory in active pane: Esc + v / Esc + g
Go to bottom of directory in active pane: Esc + j / Ctrl + c
Go to previous directory: Esc + y
Search pop-up: Esc + ?
----- Ctrl -----
Refresh active panel: Ctrl + r
Selecting files and directories: Ctrl + t
Switch active <-> inactive panels: Ctrl + i
Switch active <-> inactive panels content: Ctrl + u
Execute command / Open a directory: Ctrl + j
----- F -----
F1: help
F2: user menu
F3: read file / open directory
F4: edit file
F5: copy file or direcotry
F6: move file or directory
F7: create directory
F8: delete file / directory
F9: open menu bar
F10: exit MC

Keeping working directory after exiting MC: Now, I find this MC feature really cool but of course it’s up to you to decide if you want to enabled it or not. In case you want, make sure you have the following (or similar, depending on the midnight commander version) line in your .bash_profile:

alias mc=". /usr/local/opt/midnight-commander/libexec/mc/mc-wrapper.sh"

Note that you have to perform:

source .bash_profile 

or re-open your terminal for the changes to take effect.

Advertisements
 
14 Comments

Posted by on September 9, 2012 in bash, homebrew, Mac OS X, Midnight Commander

 

Tags: , ,

14 responses to “Surviving Mac OS X bash terminal with Midnight Commander (MC)

  1. Dan

    May 24, 2013 at 20:01

    Thank you very much for this post! That’s exactly what i’ve been searching for!

     
  2. frankhesse

    June 2, 2013 at 18:28

    Reblogged this on TechStuff and commented:
    Yess, that is the way to get my mc back to mac!

     
  3. Tatiana Ermolaeva

    August 11, 2013 at 13:12

    thanks!

     
  4. Michael Goldhoorn

    November 19, 2013 at 00:02

    Perfect! thanks!

     
  5. Volker Koch

    June 3, 2014 at 20:56

    Followed your instructions but somehow I cannot get tab-completion going in the command line. Neither in item nor in terminal. Any suggestions?

     
    • Ivan

      June 3, 2014 at 21:16

      Hi Volker, I don’t know what do you mean by “in item”. Did you do source .bash_profile or tried completion in a newly opened terminal? An easy way to know if completion works is by testing completion for the “help” command.

       
      • Volker Koch

        June 3, 2014 at 21:29

        Hi Ivan,
        I meant in “iterm”, sorry. I just tried you suggestion. I type “he” in the command line and the try to complete with either or . Does not work! Pressing or moves the “cursor” from the left to right panel back and fourth. Of course If I expose the full terminal via then completion works. But I would like to have it work on the command line with the panels displayed.
        And yes I sourced .bash_profile in the terminal

         
  6. Volker Koch

    June 3, 2014 at 21:32

    Somehow my “tab” and “alt-tab” disappeared because I used “”. I meant:
    Pressing “tab” or “alt-tab” moves the “cursor” from the left to right panel back and fourth. Of course If I expose the full terminal via “ctrl-o” then completion works.

     
    • Ivan

      June 3, 2014 at 21:47

      This is where I need to see your .bash_profile file or other files on you machine like .bashrc, .profile, etc. I don’t know how to help you, I’m sorry. You can try in forums dedicated for Mac OS.

       
      • Volker Koch

        June 3, 2014 at 22:03

        Hi Ivan,
        I removed everything from .bash_profile. So ALL I have there is:

        if [ -f `brew –prefix`/etc/bash_completion ]; then
        . `brew –prefix`/etc/bash_completion
        fi

        HOWEVER, if I DO check “use Option key as meta key” in terminal preferences, “alt-tab” does work!!!
        I am on Mavericks (new from linux) and in Linux “meta-tab” usually does the trick. So why did you suggest to uncheck the “use Option as Meta key” ? Will this have other side-effects?

        Thanks
        Volker

         
      • Ivan

        June 3, 2014 at 22:11

        First let me say : welcome to the Mac world! 🙂 Next, to your question – in MC yours Functional keys will not work if you have the “Use Option as meta key checked”. But of course this is up to your preferences. I can only suggest that you continue searching on the Internet until you configure your system the way you like it.

         
  7. Volker Koch

    June 3, 2014 at 23:51

    Thanks. We will see how long my “love affair” with OSX will last. Macs make nice Linux boxes as well ;-). Anyway, just for the record in case somebody looks at this nice description. I got it to work in using the following:
    a) use iTerm as a terminal
    b) in Profiles – Keys: check Option key acts as: “+Esc”
    this way “alt+tab” does completion in the command line and all the short-cut keys F1-10 and ctrl-… work.
    Thanks for your help

     
  8. Albert H

    April 11, 2015 at 14:58

    What I cannot find is how to make Shift-Fn keys behave correctly. When I press Shift-F6 (rename file), MC understands Shift-F4 (edit new file). Shift-Fn seems to always give me Shift-F(n-2).

     
    • Ivan

      April 13, 2015 at 17:41

      Hi Albert,

      Unfortunately I am not able to replay the problem you have. For me the Shift-F6 works alright.

      Kind regards,
      Ivan

       

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

 
%d bloggers like this: