Home > Perl6 > Thinking about a Perl6Shell

Thinking about a Perl6Shell

I’m thinking about the CLI in general right now and how it has stopped to move forward years ago. Neither the bash nor xterm using the rich capabilities of GUIs to make talking to a computer more comfortable. Beside C&P the clickyness of GUIs is mostly ignored. As we learned yesterday in #perl6 on freenode, perl6 got so much momentum right now that it’s pretty much unstoppable. I would like to take perl6 the shell with it, rushing into the future.

Before there will be any working code, that I indeed intend to write, I will need clutter bindings and quite a lot thinking …

About the wrongness of the Shell

dex@goethe:~$ cd ~/pics
dex@goethe:~/pics$ ls|head -5
002bhk7x.jpg
0124cc5b6ec228c199eeebda411ccf19.jpg
067e0f3ddf2705bb3724a166d61370c2.jpg
06e7b6185ee8ad7368f7c53b8ad804b7.jpg
06e7b6185ee8ad7368f7c53b8ad804b7.jpg.1

Well done shell! Now I know that there are lots of pics with unreasonable file names. The point of those pics lies in the pixels that are not shown to me. Clutter (or with what way to display stuff I will end up) can help here.

The right way to handle the problem would look like.

dex@goethe:~$ cd ~/pics
dex@goethe:~/pics$ ls ::image --thumbs|head -5
[imagine thumbnails of 5 pictures right here]

Yes, I could start any of those fancy photo management software thingies. Those would even provide me with lots of buttons to click on, what I rarely ever do. On top of that I have to choose a piece of software out of 50 or so. That number shows that there is something wrong anyway.

You might have guessed by now that ::image means all types of images, but only images. Well close, it means the mimetype image/*. Not sure about :: yet. It could even mean type in general. The shell we are used to has no real concept of file types. Our trusty file can help us. Can it?

dex@goethe:~/pics$ file --mime-type *|head -5
002bhk7x.jpg:                                                                   image/jpeg
0124cc5b6ec228c199eeebda411ccf19.jpg:                                           image/jpeg
067e0f3ddf2705bb3724a166d61370c2.jpg:                                           image/jpeg
06e7b6185ee8ad7368f7c53b8ad804b7.jpg:                                           image/jpeg
06e7b6185ee8ad7368f7c53b8ad804b7.jpg.1:                                         image/jpeg
dex@goethe:~/pics$

Now you only have to grep what you want, forward the result to ls. Easy!

dex@goethe:~/pics$ ls *|wc -l
329
dex@goethe:~/pics$ time file --mime-type * > /dev/null

real    0m2.564s
user    0m0.196s
sys    0m0.040s
dex@goethe:~/pics$

Those first blocks of just 330 files where in memory already but file still took 2.5s to work down the list. Not impressive.

Here comes a butterfly

Programming the bash is not overly awesome. That’s the reason why we have perl -n -e 'your_code_here'for. For most tasks you do with files, a full powered general purpose programming language is a bit over the top and would steal characters out of file names. Here is what I came up with so far.

dex@goethe:~/pics$ ls *.png | { .say if *.size > 1024KiB and *.height >= 1000 }

I’m quite confident I can make that happen with Rakudo in the next few days.

Advertisements
Categories: Perl6 Tags:
  1. No comments yet.
  1. No trackbacks yet.

Leave a Reply

Please log in using one of these methods to post your comment:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: