I am looking for a CURSES-based way (bash, c, doesn't really matter) of letting a user choose a folder or even a file in roughly the same way that they would do using Midnight Commander.

I envisage using up/down for moving the cursor, esc to cancel, and enter to select the item under the cursor. If the item is a file, then return the full path to that file, if the item is a folder, change into that folder.

Does anyone know of one that exists?

If not, how would I go about writing one? I'm mainly a Java programmer, so I could use JavaCurses, but it feels a bit like overkill.

link|improve this question

63% accept rate
And why not use mc, midnight-commander ? – rems Feb 18 '11 at 15:17
Maybe that will do? I want it to be very locked-down though - they should only be able to choose a file or cancel. Obviously just running mc gives you all sorts of powerful options, far too much for what I want. – Rich Feb 18 '11 at 15:23
feedback

1 Answer

up vote 1 down vote accepted

You can use dialog which has --fselect for choosing file and directory names.

--fselect filepath height width
The fselect (file-selection) dialog displays a text-entry window in which you can type a filename (or directory), and above that two windows with directory names and filenames.

You should note, however, that a script to change directories for the interactive shell would have to be sourced or in a function since changing directories is scoped to the current shell. In other words, when a regular script exits, any cd done within is lost.

link|improve this answer
Thanks for that - I have downloaded dialog and it definitely displays pretty much what I want. What I don't seem to be able to do is actually navigate around the directory hierarchy. I can append a folder or a file to the path, but if I append a directory, it doesn't actually go inside that folder. – Rich Feb 18 '11 at 15:31
@Rich: There's also --dselect, by the way. If you mean in the display of files and directories, you have to process that yourself in a loop. Call dialog --fselect again with the new directory. The functionality is not that much like mc unfortunately. – Dennis Williamson Feb 18 '11 at 16:27
feedback

Your Answer

 
or
required, but never shown

Not the answer you're looking for? Browse other questions tagged or ask your own question.