8

Does someone know of a GUI application (X/GTK+/Qt/whatever) that can be used instead of less or more for viewing text, specifically one piped in from standard input? Ideally looking for something that can also run on Mac OSX (or maybe even just on Mac).

I'm looking to introduce UNIX newbies to the wonderful world of command line text processing (with awk, sed, grep and even some perl) and it would be useful to show them the text using a nice GUI that allows interactive search, scrolling with the mouse (I know most Linux terminals support mouse scrolling with less, but Mac terminals do not), etc.

The best thing I found so far was to pipe input into zenity --text-info, but that viewer is very limited and does not even allow searching.

Guss
  • 12,628
  • 1
    If you're on gnome: command | gedit - (note the trailing dash) – don_crissti Mar 15 '16 at 12:10
  • You can pipe with command | gvim -, if that counts. – Sparhawk Mar 15 '16 at 12:16
  • There's not much point in using GUI apps if you're piping. Why not just redirect to a temp file instead? – terdon Mar 15 '16 at 12:16
  • @terdon - I'm not sure why you say there isn't much point. The main problem with a temp file is that they're not that temporary, you have to remember to delete them. Also when you run multiple things at the same time - messing with files easily gets out of hand. – Guss Mar 15 '16 at 12:24
  • @don_crissti: cool, I didn't think of using - as the input specification for gedit. It works nicely, though I think the leafpad solution is cleaner for about the same capabilities. Other editors I've tried using - with didn't work well :-( – Guss Mar 15 '16 at 12:25
  • @Sparhawk - but then again, gvim is not much different than less: except being its own window, it has basically the same features and the same "non user interface" ;-) – Guss Mar 15 '16 at 12:26
  • 1
    I mean that piping stuff is primarily a CLI thing. If you put a GUI viewer into the loop you sort of break continuity. Then again, I am very used to the CLI so it might be just me. As for dealing with them, just use file=$(mktemp) and that will i) create a different file per process so you don't have to worry about name collisions and ii) create it in /tmp where they will be deleted automatically on the next reboot (depending on how your system is setup). – terdon Mar 15 '16 at 12:28
  • 1
    Or kate with command | kate -i. – Sparhawk Mar 15 '16 at 12:28
  • @terdon: meh, looks like too much scripting for just running some greps. – Guss Mar 15 '16 at 12:29
  • @Sparhawk - now that's something I can get behind! I need to try man <some gui app> more: Kate is my preferred editor and I wasn't even aware it had all those useful flags :-) . It does basically everything I need, even running on Mac (with some fiddling). If only you'd post it as an answer... – Guss Mar 15 '16 at 12:31
  • @Guss yes, that's why I said "if that counts" for gvim :) I'll post the kate answer up. – Sparhawk Mar 15 '16 at 13:13
  • 4
    @Guss, if you "introduce UNIX newbies to the wonderful world of command line text processing" ... then why you should use graphical tools? maybe you just need to change your approach to the "introduction" and start by introducing UNIX newbies to editor available in from command line where mouse is pointless? – Scantlight Mar 15 '16 at 13:33
  • @Scantlight: to "ease their pain" ;-) – Guss Mar 15 '16 at 14:03
  • @don_crissti It appears the - option isn't available in all versions of gedit; I have 3.4.2 (from Debian 7), and that option appears not to work. – Kyle Strand Aug 11 '16 at 17:27
  • @KyleStrand - yes, most likely a bug - I can't remember exactly whether it was this one or another one... – don_crissti Aug 11 '16 at 17:41
  • Good question. Have you run across a lightweight pager-only (not editor) ? By "lightweight" I mean: doc < 5 pages, builds on a Mac with no Qt in < 10 minutes. – denis Aug 21 '16 at 13:55
  • I found "trowser", its is a GUI application built using tcl/tk - which isn't really a modern UI toolkit, but should still work find on Mac. It has some useful capabilities but after looking at if for a few minutes I decided not to use it because it looks like a refugee from 80s IBM workstations. – Guss Sep 08 '16 at 07:36

2 Answers2

3

You can pipe into leafpad. I don't know if there's a Mac port though.

L. Levrel
  • 1,503
  • Nice, I wasn't familiar with leafpad. I think its the only text editor that does this. The only downside I can see, compared to less, is that it supports BiDi "too well" and if my log lines start with Hebrew dates then the entire log line is right aligned. its worse if only some lines start with Hebwer. I found no way to disable that. – Guss Mar 15 '16 at 12:13
3

Kate

You can pipe into kate, using command | kate -i.

From $ man kate:

   -i, --stdin
       Read the contents of stdin

Kwrite

You can pipe into kwrite with command | kwrite -i.

From $ kwrite --help:

-i, --stdin                Read the contents of stdin.

Gvim

Somewhat facetiously, you can also pipe into gvim with command | gvim -.

Sparhawk
  • 19,941
  • How exactly is that facetious? Gvim is perfectly appropriate for moments when you need w̶a̶f̶f̶l̶e̶s̶ a graphical text editor. That's the whole point. – Braden Best May 11 '18 at 22:20
  • @BradenBest Facetiously, because gvim isn't a "normal" GUI program. IMO there's not a massive amount of difference between piping to gvim or vim. – Sparhawk May 12 '18 at 02:43
  • Except gvim doesn't need a terminal. I can open my dmenu launcher and type ls | gvim - and get a gvim window with the results. No terminal emulator necessary. I could also do this from an ssh or TTY with the appropriate $DISPLAY setting. – Braden Best May 13 '18 at 02:09
  • @BradenBest Agreed, but I still wouldn't call gvim a "nice GUI" for "UNIX newbies", as per the question. – Sparhawk May 13 '18 at 05:13
  • I dunno, the GUI looks reasonably user-friendly to me. Sure the menu has like a billion functions and it isn't as simple as gedit or sublime, but if my first vim experience was with GVim, I'd at least have been able to exit the editor without Google's help :P Besides, you don't need any vim knowledge to use it as a pager. Can scroll with arrow keys, page up/down and mouse wheel no problem. I get what you're saying, though. – Braden Best May 13 '18 at 07:30