DEV Community

Cover image for มาแต่ง Terminal ให้สวยด้วย ohmyzsh กันเถอะ
Ans for Woxa Coperation

Posted on • Edited on

2

มาแต่ง Terminal ให้สวยด้วย ohmyzsh กันเถอะ

สวัสดีครับนี่เป็น Blog แรกของผมใน dev.to พอดีได้ฤกษ์งามยามดีซื้อเครื่องมาใหม่เลยอยากจะมาเขียนบทความ Set environment style woxa ไว้เป็น handbook ให้อนุชนคนรุ่นหลังซักหน่อย

ขอไม่พูดพร่ำทำเพลงเรามาเริ่มเลยละกัน

1 . ติดตั้ง iterm2 (จริงๆใช้ Terminal ก็ได้นะ แต่เราแนะนำ iterm 😂) ให้ไปที่ iterm2.com โดยจิ้มเบาๆที่ download ตามรูป แล้วติดตั้ง

Image description

2 . หลังจากติดตั้งแล้วให้ไปที่ finder -> เลือก Applications -> คลิ๊กขวาที่ iTerm -> เลือก Get Info แล้วเลือก Open using Rosetta

iTerm Open using Rosetta

3 . ให้เปิด iTerm แล้วจะมี popup เด้งขึ้นมาให้ install Rosetta

Install using Rosetta

4 . ติดตั้ง hamebrew

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Enter fullscreen mode Exit fullscreen mode

5 . ติดตั้ง zsh

sh -c "$(curl -fsSL https://raw.githubusercontent.com/robbyrussell/oh-my-zsh/master/tools/install.sh)"
Enter fullscreen mode Exit fullscreen mode

ติดตั้ง zsh

6 . มาเลือกธีม zsh กันเถอะ
ผมจะใช vim ในการแก้ไข ใครสะดวกอะไรก็ตามสะดวกเลยครับ

 vi ~/.zshrc
Enter fullscreen mode Exit fullscreen mode

เลื่อนลงมาที่ ZSH_THEME เราจะเจอกับธีมครับ และเราสามารถเปลี่ยนธีมได้ที่ตรงนี้เลย สามารถเข้าไปดูธีมเท่ห์ๆได้ที่ ohmyzsh Themes

เมื่อได้ธีมที่ชอบแล้วเราก็แค่เปลี่ยน (เผื่อใครไม่เคยใช้ vim ให้เรากด i แล้วมันจะเปลี่ยนเป็น INSERT mode ครับ และเลื่อนตำแหน่งไปแก้ไขได้เลย เมื่อแก้เสร็จแล้วก็กด esc และพิมพ์ :wq (หมายถึง write & quit) เพื่อออกจาก vim)

ZSH_THEME="agnoster"
Enter fullscreen mode Exit fullscreen mode

หลังจากนั้นปิด iterm แล้วเข้าใหม่ จะพบว่ามันเป็นภาษาต่างดาวไปแล้วววว..!!

Bug font

วิธีแก้ง่ายๆก็แค่ติดตั้ง font ครับ ไปโหลดได้ที่ powerline แล้วก็ติดตั้ง และเปิด iterm แล้วเลือกเมนู iTerm2 ที่มุมบนซ้าย แล้วเลือก preferences... แล้วเลือกที่ profile แล้วเลือกที่ text เพื่อไปเลือก font powerline และ ท่าด้าาาาา สวยงามตามท้องเรื่อง
Fixed font

Bonus

  • เราสามาถเพิ่ม plugins ต่างๆโดยไปที่ส่วนของ plugins และเพิ่ม plugins ได้ตามความต้องการเลย สามารถดู plugins ได้ที่ default Plugins

zsh add plugins

  • Auto Correction ให้ไปที่ส่วนของ ENABLE_CORRECTION และให้เอา # เพื่อเปิดให้ zsh ตรวจคำสั่งว่าเราพิมพ์ถูกมั๊ย

  • auto suggestions ปลั๊กอินตัวนี้จะช่วยแนะนำคำสั่งเดิมที่เราเคยใช้ขึ้นมา และหากเราต้องการคำสั่งนั้นก็แค่กด Tab มันจะเลือกคำสั่งนั้นให้เลย เหมาะสำหรับคนขี้เกียจพิมพ์สุดๆ

git clone https://github.com/zsh-users/zsh-autosuggestions ~/.oh-my-zsh/custom/plugins/zsh-autosuggestions
Enter fullscreen mode Exit fullscreen mode

เมื่อติดตั้งเสร็จแล้วเราก็แค่พิมพ์ zsh-autosuggestions เพิ่มเข้าไปในส่วนของ plugins ก็เป็นอันเรียบร้อย แล้วมันจะ suggestions ให้เราแบบนี้ ถ้าอยากได้คำสั่งนี้เราก็แค่กด Tab
zsh auto suggestions

Postmark Image

Speedy emails, satisfied customers

Are delayed transactional emails costing you user satisfaction? Postmark delivers your emails almost instantly, keeping your customers happy and connected.

Sign up

Top comments (0)

A Workflow Copilot. Tailored to You.

Pieces.app image

Our desktop app, with its intelligent copilot, streamlines coding by generating snippets, extracting code from screenshots, and accelerating problem-solving.

Read the docs