Upgrade to Pro — share decks privately, control downloads, hide ads and more …

入門Cureutils

greymd
June 18, 2016

 入門Cureutils

2016/06/18に開催された「jus共催、第5回初心者向けとは言うものの午前のシェル勉強会/第23回梅雨でモワッとしたシェル芸勉強会」で発表したLT資料です。

greymd

June 18, 2016
Tweet

More Decks by greymd

Other Decks in Programming

Transcript

  1. ೖ໳Cureutils
    @grethlen

    View full-size slide

  2. ~$ whoami
    Yasuhiro Yamada (HN: ͙Ε͞Μ)
    Twitter: @grethlen
    ϋΠύʔγΣϧܳΩϡΞΤϯδχΞ
    ओͳલՊ
    • γΣϧܳ x WebεΫϨΠϐϯά (໿120stock)

    http://qiita.com/greymd/items/368faf898c161165fee7
    • γΣϧܳ x ଟݴޠϚογϡΞοϓ (͸ͯͿҰҐʣ

    http://qiita.com/greymd/items/a4ecf8e70f11eb1e5f7
    • γΣϧܳ x IoT (͋Γ͕ͪͳIoTܥهࣄ)

    http://www.slideshare.net/YasuhiroYamada1/arduino-52210988
    • γΣϧܳ x Egison (໿270stock)

    https://github.com/greymd/egzact
    ྉཧͰ͖·ͤΜ

    View full-size slide

  3. ϓϩάϥϛϯάڭҭ
    *1 https://twitter.com/13Mzawa2/status/741902695712182272/photo/1
    2020೥ΑΓখֶߍ͔Βϓϩάϥϛϯά͕ඞमԽݟࠐΈ
    γΣϧεΫϦϓτ΋෼͔Δখֶੜ *1

    View full-size slide

  4. ݒ೦.1 ಓ۩͸ద੾͔ʁ
    • ΞϧΰϦζϜ͚ͩڭ͑ͯҝʹͳΔͷ͔ʁ
    • γΣϧܳͷڭҭ༻πʔϧͱͯ͠ͷ

    ແବʹߴ͍ϙςϯγϟϧ
    1. σʔλߏ଄ͷେ੾͞΋ֶ΂Δɻ

    ΞϧΰϦζϜ͚ͩͰ͸ͳ͍ɻ
    2. ௚ײ͞ɻωετ͠ʹ͍͘ɺ

    ੵΈ໦ΛੵΈ্͛Δײ֮ɻ
    3. ෦඼Խͷେ੾͞ɻ

    Ұͭͷ෦඼͸Ұͭͷ͜ͱΛ͏·͘ɻ
    → S○ratch͸Φϫίϯɻ࣌୅͸γΣϧܳ!? vs
    γΣϧܳͷྫ
    ڭҭ༻ιϑτͷྫ

    View full-size slide

  5. ݒ೦.2 ۤखҙࣝ΁ͷέΞ
    ଟ͘ͷڞײʢˢ200RTʣΛੜΜͩ

    ࠃຽͷ੠Λ୅หͨ͠πΠʔτ*1
    *1 https://twitter.com/grethlen/status/722066098758111232

    View full-size slide

  6. ʲิ଍ࢿྉʳϓϦΩϡΞ
    • ೔ຊ͕ੈքʹތΔ

    ࠃຽతΞχϝͷҰͭ
    • 13೥໨ઈࢍ์өதʂ

    ʮຐ๏͔͍ͭϓϦΩϡΞʯ
    • ςϨϏே೔ܥྻ

    ೔༵ே8:30ʙ

    γΣϧܳษڧձͷ࣍ͷ೔͸

    ૣ͘ى͖ͯ؍Α͏
    *1 http://www.toei-anim.co.jp/tv/precure/
    ఱ࢖ୡ *1

    View full-size slide

  7. ݒ೦3. ڭһ͸଍Γ͍ͯΔͷ͔ʁ
    ্͕Δٕज़ऀͷٻਓഒ཰*1 Լ͕ΔϓϦΩϡΞͷࢹௌ཰*2
    *1 http://doda.jp/guide/kyujin_bairitsu/#03
    *2 http://prehyou2015.hatenablog.com/entry/shichourituichiran
    → ਂࠁԽ͢ΔएऀͷΩϡΞΤϯδχΞ཭Εɻ

    View full-size slide

  8. ʲ݁࿦ʳࠓͷ೔ຊʹඞཁͳࣄ
    ʮγΣϧܳ & ϓϦΩϡΞʯ
    ͳ
    ٕज़ऀΛ૿΍͢ɻ

    View full-size slide

  9. ~$ man Cureutils
    Cureutils ʲ͖Ύ͋ΏʔͪΔͣʳ
    • ࣍ੈ୅ߴ౓ΩϡΞITਓࡐཆ੒༻ίϚϯυूɻ
    • UNIXॳֶऀͷֶश༻ʹɻ
    • ΋ͪΖΜۀ຿ʹ΋໾ཱͭɻ
    • Github: https://github.com/greymd/cureutils
    • Ruby੡ίϚϯυ
    • rubicure*1ΛґଘϥΠϒϥϦͱͯ͠࠾༻ɻ
    *1 https://github.com/sue445/rubicure

    View full-size slide

  10. ಋೖํ๏
    Rubygemsొ࿥ࡁΈ *1
    • gemͰೖΕΒΕΔɻ
    $ sudo gem install cureutils
    Πϯετʔϧ͢ΔͱcureίϚϯυ͕࢖͑Δɻ
    • ࢖͍ํͷදࣔɻ
    $ cure help
    *1 https://rubygems.org/gems/cureutils

    View full-size slide

  11. ~$ cure precures
    $ cure precures
    • ϓϦΩϡΞͷ໊લΛશһग़ྗ *1
    *1 ݱࡏ·ͰͷςϨϏγϦʔζͷϝΠϯώϩΠϯͱΩϡΞΤίʔΛؚΊ46ਓɻ

    ʮΩϡΞʯ͕͔ͭͳ͍΋ͷ΋ؚΉɻΩϡΞ{ϒϥΠτ, ϒϧʔϜ}ͳͲͷ

    ಉҰਓ෺Ͱҟ໊ͷϓϦΩϡΞʹͳΔ΋ͷ͸ഉআɻ࢒೦ͳ͕Βຬͱ܆͸ؚ·ͣɻ

    View full-size slide

  12. ~$ cure girls
    $ cure girls
    • ม਎લͷঁͷࢠͷ໊લΛશһग़ྗ

    View full-size slide

  13. ~$ cure {precures,girls}

    # ׆༻৔໘
    • ςετ༻μϛʔσʔλ࡞੒ʹɻ
    • ৬৔/ֶߍͰͷ࿩୊࡞Γʹɻ

    ʮणݶແݴ͑ΔΜͩɺ͍͢͝Ͷɻ͡Ό͋ϓϦΩϡΞ͸ʁʯ
    • ࠾༻໘઀ରࡦʹɻ

    ʮFizzBuzzͩͤΔΑͶʁ͡Ό͋ϓϦΩϡΞͩͤΔʁʯ

    ʮ$ cure precuresʯ

    ʮ͛͐ͬɺγΣϧܳਓʂʯ

    View full-size slide

  14. $ cure grep (1)
    $ cat text | cure grep
    ࢲ͸ΩϡΞϒϥοΫͰ͢ɻ
    • ϓϦΩϡΞͷ໊લͷΈΛநग़͢Δɻ
    $ curl -Lso- goo.gl/L3Fp6h | cure grep | head -n 1

    ΩϡΞϒϥοΫ͸ౖܹͨ͠ɻඞͣɺ…
    • ύΠϓͰͭͳ͙ͱண৭Λ͸ͣ͢ɻ

    View full-size slide

  15. $ cure grep (2)
    • ਖ਼نදݱ಺ͰPBE͕ར༻Մೳʂ
    $ cat txt | cure grep ‘ࢲ͸[:precure_name:]Ͱ͢ɻ’
    ͜Μʹͪ͸ɺ ࢲ͸ΩϡΞϨϞωʔυͰ͢ɻ
    • ௨ৗͷBE (Bracket Expression)

    [:alnum:], [:lower:], [:upper:], [:space:] …
    • PBE (Precure Bracket Expressin)

    [:precure_name:] — ϓϦΩϡΞ໊ʹϚον 

    [:human_name:] — ঁͷࢠ໊ʹϚον

    [:cast_name:] — ੠༏໊ʹϚον

    ͳͲ

    View full-size slide

  16. ~$ cure grep (3)
    γΣϧܳਓ͓ೃછΈͷίϚϯυϥΠϯΦϓγϣϯ΋ʂ
    • -o : Ϛον෦෼ͷΈग़ྗɻ
    • -E : ͨͩͷ֦ுਖ਼نදݱΛ࢖͏ɻ

    PBEແޮԽɻීஈͷgrepίϚϯυʹม਎ʂ
    $ cat access.log | cure grep -E '192.168.1.1'

    View full-size slide

  17. ~$ cure grep #׆༻৔໘
    • จষ͔ΒεϜʔζʹϓϦΩϡΞΛநग़ɻ
    • ࢓ࣄͷใࠂॻ΍ɺֶߍͷϨϙʔτͳͲɻ
    • Rubyͷਖ਼نදݱ͕࢖͑Δgrepͱׂͯ͠ͱศར
    • ෦෼ࣜݺͼग़͠*1ͱ͔࢖͑Δ
    $ echo "aaaa\naabb" | \
    cure grep '^(?aa)\g$'
    aaaa
    *1 http://docs.ruby-lang.org/ja/1.9.3/doc/spec=2fregexp.html

    View full-size slide

  18. ~$ cure transform
    • ϓϦΩϡΞΛม਎ͤ͞Δɻ
    $ echo ‘ࢲͷ໊લ͸े࿡໷ϦίͰ͢ɻ’ | cure transform
    ࢲͷ໊લ͸ΩϡΞϚδΧϧͰ͢ɻ

    View full-size slide

  19. ~$ cure humanize
    • ϓϦΩϡΞͷม਎Λղআ͢Δɻ
    $ echo ΩϡΞ{ϋʔτ,Τʔε} | cure humanize
    ૬ాϚφ ԁѥٱཬ

    View full-size slide

  20. ~$ cure {humanize,transform}

    # ׆༻৔໘
    • ৘ใͷਖ਼نԽɻ
    • Ұ୴શͯͷϓϦΩϡΞΛม਎ͤ͞Δɻ
    • grepΛ͔͚΍͘͢͢Δɻ

    View full-size slide

  21. ~$ cure date (1)
    $ cure date
    2016-06-17 21:28:42 ຐ๏͔͍ͭϓϦΩϡΞʂ์өظؒ
    • ݱࡏͷ೔࣌Λදࣔ͢Δɻ
    • ͦͷ࣌ͷϓϦΩϡΞؔ࿈ͷΠϕϯτ΋දࣔɻ
    • ౰࣌์өதͷϓϦΩϡΞɻ
    • ॳճɾ࠷ऴճ์ө೔
    • ϓϦΩϡΞͷ஀ੜ೔
    • өըͷެ։೔ ͳͲ

    View full-size slide

  22. ~$ cure date (2)
    • -d ΦϓγϣϯରԠ
    $ cure date -d ‘1 years ago’
    • “+”ʹଓ͍ͯ೔෇ͷग़ྗϑΥʔϚοτΛࢦఆՄೳɻ
    $ cure date ‘+%Y-%m-%d @p’
    • %Y : ੢ྐྵ
    • %m : ݄ 01 - 12
    • %d : ೔ 01 - 31
    • @P : ϓϦΩϡΞؔ࿈ͷΠϕϯτ
    • ଞͷه๏΋ରԠ

    View full-size slide

  23. ~$ cure date #׆༻৔໘
    • dateಉ༷ɺϩάͷग़ྗ࣌ࠁͱͯ͠ɻ
    • ϥΠϑϩάͷΤοηϯεͱͯ͠ɻ
    • ௨ৗͷdateίϚϯυͱҧ͍

    YYYY-mm-dd HH:MM:SS

    ϑΥʔϚοτͰσϑΥϧτͰग़ྗɻ

    ͪΐͬͱ͋Γ͕͍ͨɻ

    View full-size slide

  24. ~$ cure echo (1)
    • ΩϡΞΤίʔͷม਎ޱ্Λग़ྗ͢Δɻ
    • Φϓγϣϯ
    • -a : ߈ܸͷޱ্Λ௥Ճ
    • -q : ޱ্Λ͙͢ʹදࣔͤ͞Δɻ
    $ cure echo
    ΈΜͳͷࢥ͍ΛकΔͨΊʹ
    # ҎԼུ
    *1 http://cocoa08.com/anime/4287/
    ܶ৔൛ݶఆͷϓϦΩϡΞ *1

    View full-size slide

  25. ~$ cure echo (2)
    • ΋ͪΖΜଞͷϓϦΩϡΞʹ΋ରԠ
    • -p ϓϦΩϡΞΛࢦఆͰ͖Δɻ
    $ cure echo -p sword
    ϓϦΩϡΞϥϒϦϯΫʂ
    # ҎԼུ

    View full-size slide

  26. ~$ cure echo #׆༻৔໘
    • ςετ༻μϛʔจষͷੜ੒ʹɻ
    • ҰൠϢʔβ͕rootʹͳΔ࣌ͷܯࠂͱͯ͠ɻ
    $ echo “cure echo” >> /root/.bashrc
    • େ͖ͳྗʢݖݶʣΛ࣋ͬͨ͜ͱΛ֮ࣗͤ͞Δɻ
    • దٓམͪண࣌ؒ͘Λઃ͚ΒΕΔɻ

    → Φϖϛεͷ௿ݮ

    View full-size slide

  27. ~$ cure janken
    $ cure janken
    • ϐΧϦϯδϟϯέϯ͕Ͱ͖Δ
    • উഊʹΑΓ

    ऴྃεςʔλε͕มԽɻ
    • উར: 0
    • ഊ๺: 1
    • ͍͋͜: 2
    ϐΧϦϯ͡ΌΜ͚Μ by ΩϡΞϐʔε

    View full-size slide

  28. ~$ cure janken #׆༻৔໘
    • ࢓ࣄதͷଉൈ͖ʹɻ
    • উෛڧ͍ਓ͚͕࣮ͩߦͰ͖ΔεΫϦϓτ࡞੒ʹɻ
    • ެฏͳ࡞ۀ෼୲ʹɻ
    $ cure janken && mysql -u user
    ʮ࠷ॳʹউͬͨਓ͕drop table͠·͠ΐ͏Αɻʯ

    View full-size slide

  29. ͦͷଞ
    GithubͰZsh༻ೖྗิ׬εΫϦϓτΛެ։தʂ
    • Github: https://github.com/greymd/cureutils/blob/
    master/etc/cure-completion.zsh
    ൒෼͸RubyΛֶͿͨΊʹ࡞ͬͨ΋ͷɻ
    • RubylistͷํͷϑΟʔυόοΫ΋଴ͬͯ·͢ʂ

    View full-size slide