DEV Community

Cover image for บันทึกการติดตั้ง oh-my-posh
Somprasong Damyos
Somprasong Damyos

Posted on • Edited on

บันทึกการติดตั้ง oh-my-posh

สิ่งที่ต้องมีก่อน

เริ่มการติดตั้ง

  • ใช้ PowerShell เพื่อติดตั้ง Posh-Git และ Oh-My-Posh
 Install-Module posh-git -Scope CurrentUser Install-Module oh-my-posh -Scope CurrentUser 
Enter fullscreen mode Exit fullscreen mode
  • ทำการอนุญาตให้รัน script ที่เพิ่งติดตั้งลงไปได้
 Set-ExecutionPolicy Unrestricted -Scope CurrentUser 
Enter fullscreen mode Exit fullscreen mode
  • สร้าง PowerShell profile เอาไว้รันทุกครั้งที่เริ่มการใช้งาน โดยใช้คำสั่ง notepad $PROFILE แล้วเพิ่มข้อความตามนี้
 Import-Module posh-git Import-Module oh-my-posh Set-Theme Paradox 
Enter fullscreen mode Exit fullscreen mode
  • เปลี่ยน font เป็น Cascadia Code PL หรือ Cascadia Mono PL ใน Setting ของ Windows Terminal โดยเพิ่ม fontFace
 { // Make changes here to the powershell.exe profile. "guid": "{61c54bbd-c2c6-5271-96e7-009a87ff44bf}", "name": "Windows PowerShell", "commandline": "powershell.exe", "fontFace": "Cascadia Code PL", "fontSize": 14, "hidden": false }, 
Enter fullscreen mode Exit fullscreen mode

หรือจะกำหนดที่ default เพื่อให้ใช้งาน font เดียวกันทั้งหมดก็ได้

 "defaults": { "fontFace": "Cascadia Code PL", "fontSize": 14 }, 
Enter fullscreen mode Exit fullscreen mode
  • ทดสอบโดยการเปิด Windows terminal ใหม่อีกรอบ

ใช้ Dracula Dark theme

  • (Download)[https://draculatheme.com/windows-terminal/]

  • ติดตั้งโดยการแก้ไขที่ Setting ของ Windows Terminal โดยการเพิ่ม schemes ใหม่ลงไป ซึ่งให้ไป copy จาก dracula.json จาก zip ไฟล์ที่โหลดมา ตัวอย่าง

 "schemes": [ { "name": "Dracula", "cursorColor": "#F8F8F2", "selectionBackground": "#44475A", "background": "#282A36", "foreground": "#F8F8F2", "black": "#21222C", "blue": "#BD93F9", "cyan": "#8BE9FD", "green": "#50FA7B", "purple": "#FF79C6", "red": "#FF5555", "white": "#F8F8F2", "yellow": "#F1FA8C", "brightBlack": "#6272A4", "brightBlue": "#D6ACFF", "brightCyan": "#A4FFFF", "brightGreen": "#69FF94", "brightPurple": "#FF92DF", "brightRed": "#FF6E6E", "brightWhite": "#FFFFFF", "brightYellow": "#FFFFA5" } ] 
Enter fullscreen mode Exit fullscreen mode
  • เปิดใช้งาน โดยการระบุ colorScheme ที่ profiles
 "profiles": { "defaults": { "colorScheme" : "Dracula" } } 
Enter fullscreen mode Exit fullscreen mode

เปลี่ยน Directory เริ่มต้น เมื่อเปิด PowerShell

จะต้องไปแก้ไข PowerShell profile โดยใช้คำสั่ง notepad $PROFILE แล้วเพิ่มข้อความนี้ Set-Location C:\your-start-dir ลงไป

 Import-Module posh-git Import-Module oh-my-posh Set-Theme Paradox Set-Location D:\workspaces 
Enter fullscreen mode Exit fullscreen mode

เสร็จแล้วจะได้ออกมาแบบนี้

Alt Text

ใช้งาน PowerShell ใน Visual Studio Code

  • ให้แก้ไขการตั้งค่าใน settings.json โดยเพิ่มการตั้งค่า ดังนี้
 { "terminal.integrated.fontFamily": "Cascadia Code PL", "terminal.integrated.fontSize": 14, "terminal.integrated.shell.windows": "C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe", "terminal.external.windowsExec": "C:\\Users\\sompr\\AppData\\Local\\Microsoft\\WindowsApps\\wt.exe", } 
Enter fullscreen mode Exit fullscreen mode

Alt Text

เรียบร้อย 🎉🎉🎉

Top comments (3)

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt

ควรจะบอก หรือใส่ Tag นะ ว่า for PowerShell.

Collapse
 
somprasongd profile image
Somprasong Damyos

ขอบคุณครับที่แนะนำ

Collapse
 
patarapolw profile image
Pacharapol Withayasakpunt • Edited

MesloLGS NF ที่ใช้ใน Powerlevel10k ใช้ได้มั้ย

พอดีมี WSL ด้วย