未加星标

Plan your own holiday calendar at the Linux command line

字体大小 | |
[系统(linux) 所属分类 系统(linux) | 发布者 店小二05 | 时间 2018 | 作者 红领巾 ] 0人收藏点击收藏

Welcome to today's installment of the linux command-line toys advent calendar. If this is your first visit to the series, you might be asking yourself, what’s a command-line toy. Even I'm not quite sure, but generally, it could be a game or any simple diversion that helps you have fun at the terminal.

It's quite possible that some of you will have seen various selections from our calendar before, but we hope there’s at least one new thing for everyone.

We've somehow made it to the seventh day of our series without creating an actual calendar tocelebrate with, so let's use a command-line tool to do that today: cal . By itself, cal is perhaps not the most amazing of tools, but we can use a few other utilities to spice it up a bit.

Chances are, cal is installed on your system already. To use it in this instance, just type cal .

$ cal

December 2018

Su Mo Tu We Th Fr Sa

1

2 3 4 5 6 7 8

9 10 11 12 13 14 15

16 17 18 19 20 21 22

23 24 25 26 27 28 29

30 31

We aren't going to go into advanced usage in this article, so if you want to learn more about cal , go check out Opensource.com Community Moderator Don Watkin's excellent overview of the date and cal commands .

Now, let's spice it up with a pretty box, as we covered in our previous Linux toy article. I'll use the diamonds box, and use a little bit of padding to get it nicely aligned.

$cal | boxes -d diamonds -p a1l4t2

/\ /\ /\

/\//\\/\ /\//\\/\ /\//\\/\

/\//\\\///\\/\//\\\///\\/\//\\\///\\/\

//\\\//\/\\///\\\//\/\\///\\\//\/\\///\\

\\//\/ \/\\//

\/ \/

/\ December 2018 /\

//\\ Su Mo Tu We Th Fr Sa //\\

\\// 1 \\//

\/ 2 3 4 5 6 7 8 \/

/\ 9 10 11 12 13 14 15 /\

//\\ 16 17 18 19 20 21 22 //\\

\\// 23 24 25 26 27 28 29 \\//

\/ 30 31 \/

/\ /\

//\\/\ /\//\\

\\///\\/\//\\\///\\/\//\\\///\\/\//\\\//

\/\\///\\\//\/\\///\\\//\/\\///\\\//\/

\/\\//\/ \/\\//\/ \/\\//\/

\/ \/ \/

That looks nice, but for good measure, let's put the whole thing in a second box, just for fun. We'll use the scoll design this time.

cal | boxes -d diamonds -p a1t2l3 | boxes -a c -d scroll

/ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ \

| /~~\ /~~\ |

|\ \ | /\ /\ /\ | / /|

| \ /| /\//\\/\ /\//\\/\ /\//\\/\ |\ / |

| ~~ | /\//\\\///\\/\//\\\///\\/\//\\\///\\/\ | ~~ |

| | //\\\//\/\\///\\\//\/\\///\\\//\/\\///\\ | |

| | \\//\/ \/\\// | |

| | \/ \/ | |

| | /\ December 2018 /\ | |

| | //\\ Su Mo Tu We Th Fr Sa //\\ | |

| | \\// 1 \\// | |

| | \/ 2 3 4 5 6 7 8 \/ | |

| | /\ 9 10 11 12 13 14 15 /\ | |

| | //\\ 16 17 18 19 20 21 22 //\\ | |

| | \\// 23 24 25 26 27 28 29 \\// | |

| | \/ 30 31 \/ | |

| | /\ /\ | |

| | //\\/\ /\//\\ | |

| | \\///\\/\//\\\///\\/\//\\\///\\/\//\\\// | |

| | \/\\///\\\//\/\\///\\\//\/\\///\\\//\/ | |

| | \/\\//\/ \/\\//\/ \/\\//\/ | |

| | \/ \/ \/ | |

| | | |

\ |~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~| /

\ / \ /

~~~ ~~~

Perfect. Now, here's where things get a little crazy. I like our design, but, I'd like to go all out. So I'm going to colorize it. But here in the Raleigh, NC office where Opensource.com's staff are based, there's a good chance for snow this weekend. So let's enjoy our colorized advent calendar, and then wipe it out with snow.

For the snow, I'm grabbing a nifty snippet of Bash and Gawk goodness I found over on CLIMagic. If you're not familiar with CLIMagic, go check out their website and follow them on Twitter . You'll be glad you did.

So here we go. Let's clear the screen, throw up our boxy calendar, colorize it, wait a few seconds, then snowstorm it away. All here at the terminal, in one line.

$ clear;cal|boxes -d diamonds -p a1t2l3|boxes -a c -d scroll|lolcat;sleep 3;while :;do echo $LINES $COLUMNS $(($RANDOM%$COLUMNS)) $(printf "\u2744\n");sleep 0.1;done|gawk '{a[$3]=0;for(x in a) {o=a[x];a[x]=a[x]+1;printf "\033[%s;%sH ",o,x;printf "\033[%s;%sH%s \033[0;0H",a[x],x,$4;}}'

And there we go.

animated_calendar
Plan your own holiday calendar at the Linux command line

For this to work on your system, you'll need all of the referenced utilities (boxes, lolcat, cal, gawk, etc.), and you'll need to use a terminal emulator that supportsUnicode.

Do you have a favorite command-line toy that you think I ought to profile? The calendar for this series is mostly filled out but I've got a few spots left. Let me know in the comments below, and I'll check it out. If there's space, I'll try to include it. If not, but I get some good submissions, I'll do a round-up of honorable mentions at the end.

Check out yesterday's toy, Take a break at the Linux command line with Nyan Cat , and check back tomorrow for another!

本文系统(linux)相关术语:linux系统 鸟哥的linux私房菜 linux命令大全 linux操作系统

分页:12
转载请注明
本文标题:Plan your own holiday calendar at the Linux command line
本站链接:https://www.codesec.net/view/620831.html


1.凡CodeSecTeam转载的文章,均出自其它媒体或其他官网介绍,目的在于传递更多的信息,并不代表本站赞同其观点和其真实性负责;
2.转载的文章仅代表原创作者观点,与本站无关。其原创性以及文中陈述文字和内容未经本站证实,本站对该文以及其中全部或者部分内容、文字的真实性、完整性、及时性,不作出任何保证或承若;
3.如本站转载稿涉及版权等问题,请作者及时联系本站,我们会及时处理。
登录后可拥有收藏文章、关注作者等权限...
技术大类 技术大类 | 系统(linux) | 评论(0) | 阅读(11)