Take the 2-minute tour ×
Unix & Linux Stack Exchange is a question and answer site for users of Linux, FreeBSD and other Un*x-like operating systems.. It's 100% free, no registration required.

Is there in the linux any program which can represent (via pipe or something like that) results of such commands as, for example, ls, cat, grep, ps etc, by means of curses (for example as listbox)? So by means of such program I would like to select (by means of arrows keys or hjkl) some particular item from the list instead of copy-pasting it?

I need something like dialog. It allows to create custom windows with custom widgets but I need from all these widgets only listbox, and I would like to have possibility to customize it. For example I would like to be able (within config-file or parameters) to change its behavior when press enter (for example, such list may contain list of media files which I can play by pressing on enter). Also I would like to be able to change appearance of such listbox so it may contains different columns, also I would like searchable listbox and colorized.

share|improve this question
2  
Haven't seen such ready-made solutions on Linux; dialog is still your best bet, it seems. –  Deer Hunter Apr 1 '13 at 18:46
add comment

1 Answer

I agree with the comment that dialog is probably where you need to start. To show you how you could use it, here is an example script

#!/bin/bash

#make some temporary files
command_output=$(mktemp)
menu_config=$(mktemp)
menu_output=$(mktemp)

#make sure the temporary files are removed even in case of interruption
trap "rm $command_output;
      rm $menu_output;
      rm $menu_config;" SIGHUP SIGINT SIGTERM

#replace ls with what you want
ls >$command_output

#build a dialog configuration file
cat $command_output |
  awk '{print NR " \"" $0 "\""}' |
  tr "\n" " " >$menu_config

#launch the dialog, get the output in the menu_output file
dialog --no-cancel --title "Put you title here" \
       --menu "Choose the correct entry" 0 0 0 \
       --file $menu_config 2>$menu_output

#revcover the output value
menu_item=$(<$menu_output)

#recover the associated line in the output of the command
entry=$(cat $command_output | sed -n "${menu_item}p" $config_file)

#replace echo with whatever you want to process the chosen entry
echo $entry

#clean the temporary files
[ -f $command_output ] && rm $command_output
[ -f $menu_output ] && rm $menu_output
[ -f $menu_config ] && rm $menu_config

In addition, from your question, it seems that you may also prefer a console file manager. There exists many of them, like ranger or midnight commander. If these are not configurable enough for your needs, their source code could probably prove useful in the design of your own tool.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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