Skip to content

Pipe last response to command #1466

@pinusc

Description

@pinusc

Describe the solution you'd like
A custom command such as .pipe, which takes the contents of the last reply and pipes them to its argument; then it displays the output in less or $PAGER or $AICHAT_PAGER or whatever.

For example, I ask a question and want to edit it and save it, or just overwrite a file:

.pipe nvim or .pipe tee somefile.md

or if I want better markdown highlighting: .pipe glow. Incidentally, this would also fix #801: you get the streaming response as usual, and if that is not good enough (I am particularly annoyed by tables), it's easy to .pipe glow. I see that there is a PR #1450 which adds a .format; this could be implemented trivially as an alias of .pipe glow instead.

This can also be used to easily copy the laste response to clipboard: .pipe wl-copy for wayland or .pipe xclip for X11.

Really there are a billion use cases because there are a ton of UNIX utilities that deal with text. It's what makes CLI aichat incredibly powerful, but we could have some of that power in interactive mode as well. For a bit of case history, vim also has this feature with :!r somecommand, which filters selected lines through somecommand and replaces them. That is just to say that there is precedent in TUI interfaces to facilitate interaction with pipes.

Describe alternatives you've considered
There are no real alternatives IMHO; the only option so far is to copy-paste the text (if I wanted to use my mouse I would not be using a TUI llm client) or save the session and then use the command below. Neither is very ergonomic and it would make sense to allow aichat to integrate better with the rest of the UNIX ecosystem.

Additional context
I see this as mainly useful in interactive mode, where output is not easily parsable by other programs. It would however also be nice to add a cli-mode flag to print the last output; this is not as important as it can be achieved by

aichat --session $SESSION_NAME --info | yq '.messages[-1] | .content' | some-program 

Additionally, it could be nice to allow an optional numerical argument to pipe the previous responses too, for example pipe -2 nvim would open the second-to-last response in nvim.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions