1

I try to automate some things for my Midnight Commander setup and want to call an internal Midnight Commander command from menu entries or key bindings.

For example, I have a large number of ssh sites defined in .ssh/config,

# ssh (secure shell) configuration file
Host test1
    HostName 123.456.789.0
    Port 980
    User MyUserName

Host test2
    HostName test.mynet.local
    User test
    CheckHostIP no
    ..
  1. I want to filter and sort the aliases from .ssh/config (for example with):

    grep '^Host ' .ssh/config | cut -d ' ' -f 2 | sort
    
  2. Store the resulting list in a Midnight Commander internal list box or selection panel.

  3. Select one of the entries and call the remote shell for the right file panel (like mc sh://%s...).

At least I want to store the procedure to a key binding or a Midnight Commander menu entry.

Could this be done with Midnight Commander board tools or configuration files?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
huckfinn
  • 644
  • 6
  • 23

1 Answers1

1

What you're trying is impossible as mc is not a scriptable file manager. It doesn't even have keyboard macros.

But I can think of a few weaker alternatives.

  1. Use F2-called menu (see the manpage for format, section "Menu File Edit"). In the menu run your grep command, pass the list of hosts to a program like dialog to select a host and run mc sh://$host. The problems with the approach: you need to learn dialog; there will be a second copy of mc which detects presence of the first and asks if you really wants to run the second. Ouch!

  2. Alternatively write a script that will run the grep command, get the lists of hosts and programmatically edit ~/.cache/mc/history. The file is ini-like file. You need to edit section [inp:fishlink_cmd: Shell link to machine ]. The keys are just consecutive numbers, the values are host names. Example:


[inp:fishlink_cmd: Shell link to machine ]
0=Host1
1=Host2

Now press F9, R[ight], h (for Shell command) — in the opened dialog there will be the list of hosts. Press Alt-p/Alt-n for previous/next host or open the list with mouse.

phd
  • 82,685
  • 13
  • 120
  • 165