リストからアイテムを選択するための呪いベースのプログラム

リストからアイテムを選択するための呪いベースのプログラム

ls、cat、grep、psなどのコマンドの結果を、呪い(リストボックスなど)を介して(パイプや類似のものを介して)表現できるプログラムはLinuxにありますか?それでは、このようなプログラムを使用してコピーして貼り付けるのではなく、リストから特定の項目を選択します(矢印キーまたはhjklを介して)。

似たようなものが必要ですdialog。カスタムウィジェットを使用してカスタムウィンドウを作成できますが、すべてのウィジェットにリストボックスが必要であり、それをカスタマイズできるようにしたいです。たとえば、(設定ファイルまたはパラメータ内で)Enterキーを押したときに動作を変更できるようにしたいとします。たとえば、これらのリストには、Enterキーを押して再生できるメディアファイルのリストを含めることができます。また、他の列を含めるようにリストボックスの外観を変更したり、リストボックスを検索して色を指定したりすることもできます。

ベストアンサー1

dialogここから始めなければならないという意見に同意します。使用方法を示すために、ここにサンプルスクリプトがあります。

#!/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

また、あなたの質問によると、コンソールファイルマネージャを好むようです。それらの多くがあります。森林または真夜中司令官。これらの設定がお客様の要件に十分でない場合、そのソースコードはあなたのツール設計に役立ちます。

おすすめ記事