知ってるとお得な iTerm2 と zsh/bash の小技

知ってるとお得な iTerm2 と zsh/bash の小技

LT for M3 Tech Talk #118

4cae187d836abc4428abdfb9cd448098?s=128

Taiju Aoki

June 14, 2019
Tweet

Transcript

  1. ஌ͬͯΔͱ͓ಘͳ iTerm2 ͱ zsh/bash ͷখٕ @blue_1617

  2. ࢲ͸୭ʁ blue (@blue_1617) 2 ࠷ۙͷͰ͖͝ͱ ‣ Nintendo Switch ങ͍·ͨ͠ ‣

    Chromecastɺ40 inch ϞχλΛߪೖݕ౼த ‣ ϓϩόΠμΛ so-net ʹมߋ ‣ νʔϜτοϓ3ͷ࣮ྗऀʢϝϯό਺: 3ʣ ‣ ਺গͳ͍ Emacs Ϣʔβ ‣ θϧμɺΉ͔ͣ͘͠ͳ͍͔ʁ
  3. ͜ͷൃද͸Կʁ 3 ΤσΟλ ΍ λʔϛφϧ ͸ΤϯδχΞͷ෢ث

  4. ͜ͷൃද͸Կʁ 4 ΤσΟλ ΍ λʔϛφϧ ͸ΤϯδχΞͷ෢ث ఻આڃͷ෢ث͕ͩɺ࢖͍͜ͳͤͳ͚Ε͹ҙຯ͕ͳ͍

  5. ఻આڃͷ෢ث͕ͩɺ࢖͍͜ͳͤͳ͚Ε͹ҙຯ͕ͳ͍ ͜ͷൃද͸Կʁ 5 ΤσΟλ ΍ λʔϛφϧ ͸ΤϯδχΞͷ෢ث খٕΛຏ͖ͬ͘Όͳ͍

  6. ͜ͷൃද͸Կʁ 6 ΤσΟλͷখٕ λʔϛφϧͷখٕ ‣ iTerm2 ͷখٕ ‣ zsh/bash ͷখٕ

    ‣ package ͷ࢖͍ํ ‣ package ͷ࡞Γํ
  7. ͜ͷൃද͸Կʁ 7 ΤσΟλͷখٕ λʔϛφϧͷখٕ ‣ iTerm2 ͷখٕ ‣ zsh/bash ͷখٕ

    ‣ package ͷ࢖͍ํ ‣ package ͷ࡞Γํ
  8. iTerm2 ͷখٕ

  9. 1. Hotkey 9 ‣ HotkeyΛొ࿥͢Δ ‣ Ͳͷը໘Ͱ΋ॠ࣌ʹλʔϛφϧΛදࣔͤ͞ΒΕΔ ϙοϓΞοϓ͢Δ

  10. 1-1. ઃఆͱࢫຯ 10 ‣ ΤσΟλૢ࡞தͰ΋ը໘ΛҠಈͤͣλʔϛφϧૢ࡞Ͱ͖Δ ‣ ͳΜ͔ݟͨ໨͕Χοί͍͍ https://www.iterm2.com/documentation-hotkey.html ઃఆ ࢫຯ

    ‣ ެࣜDocΛಡΉ ‣ " iTerm2 Hotkey ઃఆ " ͱ͔ͰάάΔ
  11. 2. Triggers 11 ‣ ൓Ԡ͢ΔจࣈྻΛొ࿥͢Δ ‣ จࣈྻ͕ඳը͞ΕΔͱɺ௨஌Λඈ͹ͤΔ ௨஌͕ඈΜͰ͘Δ

  12. 2-1. ઃఆͱࢫຯ 12 ‣ Ϗϧυऴྃ΍ϒϨʔΫϙΠϯτൃՐͷλΠϛϯάΛ஌ΕΔ ‣ Ͳͷը໘ʹ͍ͯ΋௨஌Λड͚औΕΔ https://www.iterm2.com/documentation-triggers.html ઃఆ ࢫຯ

    ‣ ެࣜDocΛಡΉ ‣ " iTerm2 Trigger ઃఆ " ͱ͔ͰάάΔ
  13. 3. Maximize Active Pane 13 ‣ λʔϛφϧͷPaneΛϫϯίϚϯυͰ࠷େԽͰ͖Δ ΊͬͪΌ֦େ͢Δ

  14. 3-1. ઃఆͱࢫຯ 14 ‣ େ͖ͳը໘ͰϩάͳͲΛݟΒΕΔ ‣ ϖΞϓϩͷ࣌ʹಉ྅ʹը໘Λݟͤ΍͘͢ͳΔ ઃఆ ࢫຯ ‣

    Cmd + Shift + Enter Ͱ͍͚Δ
  15. 4. change color by ssh 15 ‣ ϗετ໊Λࢦఆ͓ͯ͘͠ ‣ sshͨ͠ઌͷϗετ໊ʹΑΓɺഎܠ৭͕มΘΔ

  16. 4-1. ઃఆͱࢫຯ 16 ‣ ssh ͨ͠/͍ͯ͠Δઌ͕ҰൃͰΘ͔Δ ‣ ຊ൪؀ڥʹ ssh ͨ͠ͱ͖ʹࣄނΒͳ͍

    ઃఆʢͲͪΒ͔ʣ ࢫຯ ‣ iTerm2 ͷ "Automatic Profile Switching" Λ࢖͏ ‣ ssh ίϚϯυΛϑοΫͯ͠ iTerm2 ͷ Profile Λ੾Γସ͑Δ https://www.iterm2.com/documentation-escape-codes.html https://www.iterm2.com/documentation-automatic-profile-switching.html
  17. zsh/bash ͷখٕ

  18. 5. peco 18 ‣ ΠϯΫϦϝϯλϧͳߜΓࠐΈΛ࣮ݱ͢Δ `root nt` ͱ͍͏จࣈྻΛߜΓࠐΊΔ

  19. 5-1. ઃఆͱࢫຯ 19 ‣ ΠϯΫϦϝϯλϧαʔν͕࢖͑ΔΑ͏ʹͳΔ ‣ ༷ʑͳίϚϯυͱ૊Έ߹ΘͤΒΕΔʢޙड़ʣ ઃఆ ࢫຯ ‣

    ެࣜREADMEΛಡΉ ‣ " peco Πϯετʔϧ ํ๏" ͱ͔ͰάάΔ https://github.com/peco/peco
  20. 5-2. peco Ͱ history Λݕࡧ͢Δ 20 ‣ history͔ΒΠϯΫϦϝϯλϧʹίϚϯυΛݕࡧͰ͖Δ ‣ "

    peco history search " ͱ͔ͰάάΔͱઃఆͰ͖Δ
  21. 5-3. peco Ͱ git checkout ઌΛબ୒͢Δ 21 ‣ branchͷத͔ΒΠϯΫϦϝϯλϧʹcheckoutઌΛ୳ͤΔ ‣

    " peco git checkout " ͱ͔ͰάάΔͱઃఆͰ͖Δ
  22. 6. enhancd 22 ‣ աڈʹ cd ͨ͠σΟϨΫτϦʹඈ΂Δ ‣ peco Λ࢖ͬͯΠϯΫϦϝϯλϧʹબ୒Ͱ͖Δ

  23. 6-1. ઃఆͱࢫຯ 23 ‣ ΠϯΫϦϝϯλϧαʔν͕ cd Ͱ΋࢖͑ΔΑ͏ʹͳΔ ‣ ҰॠͰผσΟϨΫτϦʹඈ΂Δ ઃఆ

    ࢫຯ ‣ ެࣜREADMEΛಡΉ ‣ " enhancd Πϯετʔϧ ํ๏" ͱ͔ͰάάΔ https://github.com/peco/peco
  24. 7. zsh-autosuggestions 24 ‣ ཤྺ͔ΒίϚϯυͷࣗಈิ׬Λͯ͘͠ΕΔ աڈͷೖྗ͕ิ׬͞ΕΔ

  25. 7-1. ઃఆͱࢫຯ 25 ‣ աڈͷίϚϯυཤྺΛݩʹࣗಈิ׬͕ޮ͘Α͏ʹͳΔ ‣ λΠϓྔ͕͔ͳΓݮΔ ઃఆ ࢫຯ ‣

    ެࣜREADMEΛಡΉ ‣ " zsh-auto-suggestions Πϯετʔϧ " ͱ͔ͰάάΔ https://github.com/zsh-users/zsh-autosuggestions
  26. 8. zsh-history-substring-search 26 ‣ historyத͔ΒɺೖྗதͷίϚϯυʹྨࣅͨ͠΋ͷΛ୳ͤΔ Ctrl + p Ctrl +

    p
  27. 8-1. ઃఆͱࢫຯ 27 ‣ աڈͷίϚϯυཤྺ͔Βಉ͡Α͏ͳίϚϯυΛ୳ͤΔ ‣ peco ʹΑΔݕࡧΑΓ΋ϫϯΞΫγϣϯগͳ͘ಈ࡞͢Δ ઃఆ ࢫຯ

    ‣ ެࣜREADMEΛಡΉ ‣ "zsh-history-substring-search Πϯετʔϧ" ͰάάΔ https://github.com/zsh-users/zsh-history-substring-search
  28. 9. zsh-git-prompt 28 ‣ ݱࡏͷbranchͱstatusΛϓϩϯϓτʹදࣔͰ͖Δ

  29. 9-1. ઃఆͱࢫຯ 29 ‣ ॠ࣌ʹ branch ໊ͱ git status ͕Θ͔Δ

    ઃఆ ࢫຯ ‣ ެࣜREADMEΛಡΉ ‣ "zsh git status prompt" ͱ͔ͰάάΔ https://github.com/olivierverdier/zsh-git-prompt
  30. ͓·͚: Enter ͚ͩͰ git status ͯ͠΍Δ 30 ‣ Enter Λଧͭͱɺݱࡏͷ

    git status ΛදࣔͰ͖Δ
  31. ͓·͚: ઃఆͱࢫຯ 31 ‣ ศརؔ਺Λࣗ෼ͰఆٛͰ͖Δ͜ͱΛ࣮ײͰ͖Δ ઃఆ ࢫຯ ‣ zshrc ʹࣗ෼Ͱؔ਺Λఆٛ͢Δ

    ‣ " zsh enter git status " ͱ͔ͰάάΕ͹ͳΜͱ͔ͳΔ
  32. ·ͱΊ

  33. ࠷ޙʹ ‣ ΤσΟλ΍λʔϛφϧ͸ڧ͘Ͱ͖Δ ‣ ΤσΟλ΍λʔϛφϧ͸ϓϩάϥϚͷ෢ث ‣ ෢ثΛຏ͘ͷ͸౰વͱͯ͠ɺ࢖͍͜ͳ͢খٕ΋େࣄ 33 ‣ ΋ͬͱศརʹʂ΋ͬͱڧ͘ʂ

    ‣ ෆศͩͳͱࢥͬͨ఺͸୭͔͕ղফ͍ͯ͠Δέʔε͕ଟ͍ ‣ ͦΕͰ΋ͳ͚Ε͹ࣗ࡞͢Ε͹OK ‣ ެ։͞Ε͍ͯΔ repository ʹ issue ΛཱͯΔͷ΋OK ‣ ͓͢͢ΊػೳΛͥͻڭ͑ͯ͘Εʂ