8

Let's say that I want the output of ls viewed in nano or tilde.

I would do the following:

ls >> tmp
nano tmp
rm tmp

I don't like this because it creates a dumpfile that I sometimes forget to delete. Some people suggest this:

ls | less

or

ls | more

But I cannot do:

ls | nano

So how to solve this? I would need this especially when it comes to huge terminal outputs like the current processes where I would like to do a search afterwards.

  • 1
    @steeldriver because I like the text editor tilde and the way all the hotkeys are layed out. I can work quickly with that. I have not gotten used to less and don't feel the the need to ... – Paul Erlenmeyer Nov 30 '19 at 14:42
11

Many programs conventionally use - to mean standard input or standard output. Thus, you can open the screen output of a command in nano using - as the file name, as in:

ls | nano -

This will only work if your program does support that convention. This includes nano and vi on the terminal. Even the graphical text editor gedit supports it. However, pluma or mousepad do not support it, and instead will be instructed to create a regular file named -. In other cases, you cannot get around creating a regular intermediate file first.

| improve this answer | |
  • This works for me with nano. But when I try it with tilde I get "No such option -" – Paul Erlenmeyer Nov 30 '19 at 17:31
  • 3
    This only works if the consuming command explicitly supports it; it's common but far from universal. – chrylis -cautiouslyoptimistic- Dec 1 '19 at 0:33
5

If viewing with tilde is really needed, you may script your idea
Create a function in your .bashrc

function tildeIt () {
  tmpfile=$(mktemp)
  "$@" > $tmpfile
  tilde $tmpfile
  rm $tmpfile
}

# $@ is all words typed after tildeIt
# mktemp creates a temp file and returns his fullname

Reload .bashrc

source ~/.bashrc

Usage

tildeIt command -option
| improve this answer | |
  • 1
    This is pretty cool. Thanks! +1 – Paul Erlenmeyer Nov 30 '19 at 17:27
  • 1
    Please, teach people to use mktemp instead of creating temp filenames with just $$. – Guntram Blohm supports Monica Dec 1 '19 at 6:03
  • @Guntram Blohm supports Monica : ok, more elegant, i edit – cmak.fr Dec 1 '19 at 6:06
2

If you have vipe, you can do

ls | vipe >/dev/null

The program vipe (which I believe stands for either vi pipe or view pipe) reads standard in, opens $EDITOR on it, and writes whatever is left when you save-and-quit to standard out.

| improve this answer | |
0

On *nix, everything is a file. Thus, you can read the standard input from a file. In theory that is. Some programs get a bit iffy.

Depending on the editor, you can read /dev/stdin. For example, cat works, but gedit complains that /dev/stdin is a special file and can't be edited.

ls | cat /dev/stdin #works
ls | nano /dev/stdin #doesn't work.
ls | vim /dev/stdin #doesn't work
ls | gvim /dev/stdin #works

What works with this method and what doesn't seem to be easily distinguished. So just try it with what you want, and it will either work, or not.

| improve this answer | |
  • geany works too with both geany <(ls -1) and ls | geany /dev/stdin. – Hermann Dec 1 '19 at 17:54
0

If you're using bash, you might try tilde <( ls ).

See Process Substitution in bash(1).

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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