Artificial intelligent assistant

Folding terminal pager Concept: a terminal pager, like `less` for example, that interactively "folds" and "unfolds" the input file (as in emacs outline mode). Folded, a recursive directory listing might show only the directory names. Unfolded, it would show the full contents. As another example git log | pager might allow the user to toggle interactively between seeing the headlines and details of each commit. pager xxx.c might fold/unfold functions, allowing the user to switch between seeing function definitions only and function bodies. Obviously, the pager would need to be told (or to deduce for itself) the type of the content it was dealing with. Does such a program exist?

Put this in an executable file named "pager":


#! /usr/bin/env bash

TEMP=/tmp/file-$$.txt
trap "rm -f $TEMP" EXIT HUP INT TERM

echo '-*- outline -*-' > $TEMP
cat "$@" >> $TEMP
emacs $TEMP 0<&1


The initial line of the temporary text file arranges for emacs to enter outline mode. Then `cat` appends the zero-or-more specified file(s). Finally the editor allows viewing the input text via your favorite mode, then `trap EXIT` cleans the temp file.

Zero files implies reading from stdin.

Ordinarily `git log | pager` would not be well supported, as the pipe can interfere with stdin connected to keyboard. (Diagnostic in that case is: "emacs: standard input is not a tty".) We expect that stdout will be connected to terminal, that is, `pager` is at the end of the pipeline. Given that, `0<&1` is able to recover from the situation by connecting stdin to the same terminal pty that stdout is connected to, allowing for a successful edit session.

xcX3v84RxoQ-4GxG32940ukFUIEgYdPy 2ff8a2a1c2cfbacf410ed1796edb6a54