0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

mwedアドベントカレンダー15日目の記事です。

treeコマンドの結果がチカチカしたらxmas_tree:christmas_tree:なのでは?!

image.png

perl版

xmas_tree_perl.sh
function xmas_tree () {
  tree $* | perl -ne '
  binmode(STDOUT, ":utf8");
  utf8::decode($_);
  @string = split //, $_;
  foreach $char(@string) {
    $r = int(rand(15)) ;
    if($r == 1){
      $s = "\e[5m\e[37m";
      $e = "\e[m\e[m";
    } elsif ($r == 2) {
      $s = "\e[5m\e[35m";
      $e = "\e[m\e[m";
    } elsif ($r == 3) {
      $s = "\e[5m\e[33m";
      $e = "\e[m\e[m";
    } elsif ($r == 4) {
      $s = "\e[5m\e[31m";
      $e = "\e[m\e[m";
    } else {
      $s = "\e[32m";
      $e = "\e[m";
    }
    print "$s$char$e";
  }
  '
}

ruby版

xmas_tree_ruby.sh
function xmas_tree {
  tree $* | ruby -ne '
    string = $_.split ""
    string.each do |char|
      case rand(15)
  	when 1 then
  	  s = "\e[5m\e[37m"
        e = "\e[m\e[m"
      when 2 then
        s = "\e[5m\e[35m"
        e = "\e[m\e[m"
      when 3 then
        s = "\e[5m\e[33m"
        e = "\e[m\e[m"
      when 4 then
        s = "\e[5m\e[31m"
        e = "\e[m\e[m"
      else
        s = "\e[32m"
        e = "\e[m"
  	end
      print "#{s}#{char}#{e}"
    end
  '
}

使い方

コンソールにペタッ!
実行!

動かない?

treeコマンドがない?

Macにはデフォルトでインストールされてないので、適宜インストールしてくださいまし。便利ですよ。
homebrewを使っていればbrew install treeでインストールできます。

チカチカしない?

コンソールの設定でBLINKしないようになっているものもありますので、適宜設定を変えてくださいまし。

最後に

くだらなくてすみません :bow: :bow: :bow:

明日は@HamaguchiRyosukeさんの「新卒同期5人でHackDayのハッカソンに参加してみた」です。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?