Khởi động
- Nhấn
Win+R
để mở hộp thoại Run, nhậpwt
, nhấn Enter để mở Windows Terminal. - Nhấn
Win+X
để mở menu chuột phải của nút Start, nhấnI
(hoặcAlt+I
) để mở Windows Terminal.
PowerShell
Cài đặt sudo
Nếu bạn chưa nâng cấp lên Windows 24H2, bạn có thể cài đặt gsudo
để thêm hỗ trợ sudo.
- Cài đặt
gsudo
PS>
winget install gsudo
Trên hệ thống mới, lệnh sudo
có thể không thực thi đúng các lệnh PowerShell. Để chạy lệnh với quyền admin trong cùng thư mục:
- Mở terminal mới với quyền admin trong thư mục hiện tại:
PS>
sudo wt -d $(pwd)
Nếu sử dụng Windows PowerShell
Theo tài liệu chính thức của Microsoft, PowerShell và Windows PowerShell là hai sản phẩm khác nhau.
Module PSReadLine
cung cấp tính năng tự động hoàn thành. Windows PowerShell sử dụng phiên bản cũ của PSReadLine
, cần cập nhật thủ công.
- Cài đặt phiên bản mới của
PSReadLine
PS(Administrator)>
Nếu lần đầu chạy lệnh gặp thông báo cần cài đặtInstall-Module PSReadLine -ForceNuGet
, có thể cần chạy lại lệnh trên một lần nữa.
Bật tính năng tự động hoàn thành
- Tạo thư mục cấu hình PowerShell (nếu chưa có thể bỏ qua bước này)
PS>
mkdir $PROFILE/.. - Mở file cấu hình PowerShell
PS>
notepad $PROFILE- Hoặc chỉnh sửa cấu hình toàn hệ thống
PS>
sudo notepad $PROFILE.AllUsersAllHosts - Thêm nội dung sau vào file cấu hình:
$PROFILEpowershell Set-PSReadlineKeyHandler -Key Tab -Function MenuComplete Set-PSReadLineOption -PredictionSource History Set-PSReadLineKeyHandler -Chord "Ctrl+RightArrow" -Function ForwardWord
Mẹo nhỏ
- Chuyển nhanh sang terminal quyền admin (cần bật OpenSSH Service)
PS>
ssh localhost - Thêm lệnh chạy Git Bash vào cấu hình PowerShell
$PROFILE
Set-Alias bash $env:ProgramFiles\Git\bin\bash - Gán tổ hợp
Ctrl+D
để thoát PowerShell$PROFILE
Set-PSReadlineKeyHandler -Chord Ctrl+d -Function DeleteCharOrExit
Oh My Posh
- Cài đặt
oh-my-posh
PS>
winget install JanDeDobbeleer.OhMyPosh - Thay đổi chính sách thực thi PowerShell
PS>
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned -Scope CurrentUser - Cấu hình
oh-my-posh
- Mở file cấu hình PowerShell
PS>
notepad $PROFILE- Thêm dòng sau vào file
$PROFILEpowershell oh-my-posh init pwsh | Invoke-Expression
- Cài đặt font từ Nerd Fonts
Git Bash
Sau khi cài đặt Git for Windows, có thể thêm Git Bash vào Windows Terminal.
- Mở cài đặt Windows Terminal
- Thêm cấu hình mới:
Tên
Git BashLệnh
%ProgramFiles%\Git\bin\bash.exe --login -iThư mục khởi động
%USERPROFILE%Icon
%ProgramFiles%\Git\mingw64\share\git\git-for-windows.ico
Tùy chỉnh giao diện
Chỉnh sửa tại: Windows Terminal Settings - Profile - Defaults - Appearance
- Văn bản
- Scheme màu: One Half Dark
- Font:
Cascadia Code, Symbols Nerd Font
- Độ trong suốt
- Mức trong suốt: 75%
- Bật hiệu ứng Acrylic
Tìm kiếm lịch sử lệnh
Sau khi cập nhật PSReadLine
, có thể dùng F2
để chuyển giữa tự động hoàn thành và danh sách gợi ý.
Ctrl + R
: Tìm kiếm lệnh đã chạy trước đó.Ctrl + S
: Tìm kiếm xuôi theo lịch sử lệnh.Ctrl + G
hoặcEsc
: Thoát chế độ tìm kiếm.
Dùng Fastfetch để hiển thị thông tin hệ thống
Cài đặt bằng Scoop
:
PS>scoop install fastfetch
- Hiển thị thông tin hệ thống
PS>
fastfetch - Ẩn logo, hiển thị chi tiết
PS>
fastfetch -c all -l none
Một số lệnh hữu ích
- Xem lịch sử lệnh
PS>
Get-Content (Get-PSReadlineOption).HistorySavePath - Kiểm tra đường dẫn lệnh
PS>
(Get-Command <command>).DefinitionPS>
where.exe <command> - Mở File Explorer trong thư mục hiện tại
PS>
explorer . - Bật điểm phát Wi-Fi khi không có mạng
PS>
[Windows.Networking.NetworkOperators.NetworkOperatorTetheringManager,...]::CreateFromConnectionProfile([Windows.Networking.Connectivity.NetworkInformation,...]::GetInternetConnectionProfile()).StartTetheringAsync()