Drawing bounding boxes in command snips

10 views
Skip to first unread message

Munyoki Kilyungi

unread,
Jul 22, 2022, 6:22:33 AM7/22/22
to nairo...@googlegroups.com

This is interesting. Some one shared a really
cool way of displaying the results of a command
output in a bounding box. Enjoy!

-------------------- Start of forwarded message --------------------
Date: Thu, 21 Jul 2022 15:00:25 +0200
Subject: Re: Drawing bounding boxes in command snips [WAS: Re: repl macro
(metacommand?) for guix CLI (sub)commands]

boxit
bash-c-box
signature.asc

Munyoki Kilyungi

unread,
Jul 22, 2022, 6:30:18 AM7/22/22
to nairo...@googlegroups.com

I think google-groups truncates mail in the
web-interface. That said, here's the full text:
hopefully it gets displayed well:

The surrounding box is actually created by a bash script
that reads text from stdin, sanitizes and neasures, and
has some more opts, e.g. -title which will create a split box
with a centered title in the top half. It writes to stdout.

It's not very pretty, and it doesn't know what to do with
tabs, and measuring max width could now be done with wc -L
but that option didn't exist AFAIK when I wrote boxit.

Wide boxes don't wrap very well, so it needs an option to
leave the right side open, like I have seen posted.
But it works fine for box sizes mail readers show unwrapped.

You are right that I use emacs, but I invoke boxit from
emacs to insert the result of a shell command (boxit)

I also have a little two-liner bash script (bash-c-box)
which accepts a command and puts the command in the title,
prefixed with '# $ ' and uses bash -c to execute the command
string, whose result it boxes.

E.g., if I now type
Esc 1 Esc ! bash-c-box cat ~/bin/bash-c-box
I get the following inserted:
┌──────────────────────────────────────┐
│ # $ cat /home/bokr/bin/bash-c-box │
├──────────────────────────────────────┤
│ #! /usr/bin/bash │
│ bash -c "$*"|boxit -title '# $ '"$*" │
└──────────────────────────────────────┘
Well, I typed it without quoting, so ~/bin got expanded :)

BTW, the bash-c-box and boxit commands can wrap their own
output, since it's just filtering, e.g., if I now type
Esc 1 Esc ! bash-c-box "bash-c-box cat ~/bin/bash-c-box|boxit -title boxit-itle"
I get the following inserted:
┌─────────────────────────────────────────────────────────────┐
│ # $ bash-c-box cat ~/bin/bash-c-box|boxit -title boxit-itle │
├─────────────────────────────────────────────────────────────┤
│ ┌──────────────────────────────────────────┐ │
│ │ boxit-itle │ │
│ ├──────────────────────────────────────────┤ │
│ │ ┌──────────────────────────────────────┐ │ │
│ │ │ # $ cat /home/bokr/bin/bash-c-box │ │ │
│ │ ├──────────────────────────────────────┤ │ │
│ │ │ #! /usr/bin/bash │ │ │
│ │ │ bash -c "$*"|boxit -title '# $ '"$*" │ │ │
│ │ └──────────────────────────────────────┘ │ │
│ └──────────────────────────────────────────┘ │
└─────────────────────────────────────────────────────────────┘

Have fun :)

I tried to attach boxit and bash-c-box. Let me know if problem.

Esc 1 Esc ! bash-c-box sha1sum ~/bin/{boxit,bash-c-box} produces:
┌─────────────────────────────────────────────────────────────────────┐
│ # $ sha1sum /home/bokr/bin/boxit /home/bokr/bin/bash-c-box │
├─────────────────────────────────────────────────────────────────────┤
│ 8f360325d7fad4406bdd6e55986f4daff85da9e6 /home/bokr/bin/boxit │
│ 453df327dd6bf5c24b6fffdce4740a53e97d0b0b /home/bokr/bin/bash-c-box │
└─────────────────────────────────────────────────────────────────────┘
Hm, I ought to left-justify the command in the title. Never ends :)

--
(Life is like a pencil that will surely run out,
but will leave the beautiful writing of life.)
(D4F09EB110177E03C28E2FE1F5BBAE1E0392253F
(hkp://keys.gnupg.net))
signature.asc
Reply all
Reply to author
Forward
0 new messages