GNU Midnight Commander (MC) Documentation

repository·master·Indexed 21 days ago

https://github.com/midnightcommander/mc

A dual-pane, text-mode file manager for POSIX systems. Features include a Virtual File System (VFS) for remote filesystems (FTP, SFTP, SSH) and archives, a built-in text editor with syntax highlighting, a hex editor, and a diff viewer. Supports mouse interaction, command completion, and background operations across various terminal emulators including XTerm.

Tokens
12K
Snippets
26
Records
57
Agent score
75%

What's inside Midnight Commander

  1. Use attributes and aliases in skins

    master

    Attributes

    The third parameter in a color definition specifies attributes. You can combine multiple attributes using a plus sign (+).

    Supported attributes:

    • bold
    • underline
    • italic
    • reverse
    • blink

    Example: yellow;;bold+italic (Yellow foreground, default background, bold and italic attributes).

    To disable all attributes and prevent fallback, use an unrecognized word like none or default.

    Aliases

    The [aliases] section allows you to define reusable color or attribute fragments. Aliases can refer to other aliases as long as they do not form a loop.

    Example:

    [aliases]
    myfavfg = green
    myfavbg = black
    myfavattr = bold+italic
    
    [core]
    _default_ = myfavfg;myfavbg;myfavattr
  2. Create a Midnight Commander skin file

    master

    Midnight Commander (mc) skins are configuration files that define the visual appearance of the interface, including colors, attributes, and character sets.

    Skin Structure

    1. [skin] Header: Defines color support.
    2. Color and Attribute Sections: Define colors for specific UI elements (e.g., [core], [dialog], [editor]).
    3. Character Sections: Define UTF-8 characters for frames and widgets (e.g., [lines], [widget-panel]).
    4. [aliases] (Optional): Define reusable color/attribute fragments.

    Color and Attribute Syntax

    Colors and attributes are defined using the following semicolon-separated format: keyword = foreground_color;background_color;attributes

    If a value is omitted, mc uses a fallback mechanism:

    1. The specific keyword's fallback.
    2. The _default_ value of the current section.
    3. The _default_ value of the [core] section.

    Example Skin Snippet

    [skin]
    truecolors = true
    
    [aliases]
    myfavfg = green
    myfavbg = black
    myfavattr = bold+italic
    
    [core]
    _default_ = myfavfg;myfavbg;myfavattr
    selected = ;black
  3. Overview of GNU Midnight Commander (MC)

    master
    GNU Midnight Commander (MC) is a user shell with a text-mode full-screen interface designed for file management. It can be run on OS consoles, xterm, and other terminal emulators, making it suitable for local use or remote sessions via telnet or SSH. It features a dual-panel layout to provide a clear representation of the filesystem.
  4. Understand the VFS class hierarchy and object model

    master

    VFS uses an object-oriented approach where different data types (archives, remote systems, filesystems) are treated as classes. Individual archives or connections are instances of these classes.

    Class Hierarchy

    • vfs (Base)
      • direntry (Base for archives and remote systems)
        • cpio (Archive)
        • tar (Archive)
        • fish (Remote system)
        • ftpfs (Remote system)
      • extfs (Ext-based archives)
      • localfs (Local filesystem)
        • sfs (SFS archives)

    Core Concepts

    • Multiplexing: vfs.c acts as a multiplexor. It exports POSIX-like functions with an mc_ prefix (e.g., mc_open()). These functions intercept VFS-specific names and route them to the appropriate VFS class.
    • Entries and Inodes: Each VFS object has an associated directory tree. Entries can be associated with nameless inodes, which store metadata like size and timestamps (similar to a POSIX struct stat).
  5. Use Quick Search in Panels

    master

    Quick Search mode allows for fast file searching within panels.

    • Case Sensitivity: The behavior of Quick Search is controlled by the quick_search_case_sensitive option.
    • Wildcards: You can use wildcard characters * and ? during a quick search.
    • Search Types: The unified search/replace engine supports Plain, Wildcard, Regexp, and Hex search types.
  6. Understand the mc event system architecture

    master

    The mc event system is designed to decouple event sources from their handlers. It uses a fast binary tree (GTree) structure to organize events into groups, where each event contains a list of handlers (GPtrArray).

    Key Concepts

    • Decoupling: Instead of calling specific functions (like a VFS message output function), components trigger an event. This allows handlers to be registered, changed, or overridden (e.g., by plugins) without modifying the source of the event.
    • Event Grouping: Events are organized into groups (using GTree) to allow efficient categorization.
    • Handler Execution Order: Handlers are executed in a "Last In, First Out" (LIFO) order: the most recently added handler is the first to execute. This enables plugins to override standard handlers by adding themselves last.
    • Event Propagation Control: A handler returns TRUE to allow subsequent handlers for that event to execute, or FALSE to immediately stop further processing of that event.
  7. Prevent nested Midnight Commander instances via MC_SID

    master
    Midnight Commander uses the MC_SID environment variable to detect if it is being run from within another instance of MC. If MC_SID is present and matches the current session ID, the program identifies itself as running from a parent MC instance. This mechanism is used to manage subshell behavior and prevent conflicting terminal sessions.