指令
Dotnet
dotnet run –project ./MyWebApp/ dotnet run –p ./MyWebApp/
dotnet build
確定程式沒改,可以執行這指令 dotnet run –no-build
dotnet rebuild
launchSettings.json 指定profiles dotnet run –launch-profile ‘http’
Docker
docker ps -a --format "table {{.Image}}\t{{.Names}}\t{{.Status}}"
Windows
1.測試 port 連線(內建) Test-NetConnection mydomain.com -Port 443 telnet
2.
3.客製化window 指令
※用管理員身分執行power shell,再執行以下指令 Set-ExecutionPolicy RemoteSigned -Scope CurrentUser
※確認檔案路徑 $PROFILE
※如果檔案不存在就建立他 if (!(Test-Path $PROFILE)) { New-Item -ItemType File -Path $PROFILE -Force }; notepad $PROFILE
※確認 devenv 路徑(後續會用來開解決方案) & ‘$env:ProgramFiles(x86)Microsoft Visual StudioInstallervswhere.exe’ -latest -property installationPath
※實作指令
—全域變數—
$global:VSPath = ‘C:/Program Files/Microsoft Visual Studio/2022/Community/Common7/IDE/devenv.exe’ $global:MyVsWorkDir = ‘C:/Users/shilvain/Desktop/shilvain/gitRepository’
— 常用指令縮寫 —
Git指令
function gs { git status } function gb { git branch } function gbvv { git branch -vv } function gaa { git add . } function gct { git commit -m $args[0] } # 支援參數:gct ‘update’ function gph { git push } function gpl { git pull } function gf { git fetch } function gsw { git switch $args[0] } function glog { git log –pretty=format:’%C(bold yellow)%h%Creset %C(green)%ad%Creset | %C(auto)%d%Creset%s <%C(white)%an%Creset>’ –decorate –graph –all –date=short –author-date-order }
function br { cd .. } function cdgitrepo { cd D:shilvainGitRepository }
— 複合型指令 (自動化) —
git diff 指定索引的檔案
function gd { param( [Parameter(Mandatory=$true)] [int]$index ) $files = git status –porcelain | Where-Object { $_ -match ‘^[ MADRCU?]{1,2}s+’ } | ForEach-Object { $_.Substring(3) }
if ($index -lt 0 -or $index -ge $files.Count) {
Write-Host '索引超出範圍 (0 ~ $($files.Count - 1))' -ForegroundColor Red
return
}
$target = $files[$index]
git diff $target }
git add 指定索引的檔案
function ga { param( [Parameter(Mandatory=$true)] [int]$index ) $files = git status –porcelain | Where-Object { $_ -match ‘^[ MARC?]{1,2}s+’ } | ForEach-Object { $_.Substring(3) }
if ($index -lt 0 -or $index -ge $files.Count) {
Write-Host '索引超出範圍 (0 ~ $($files.Count - 1))' -ForegroundColor Red
return
}
$target = $files[$index]
Write-Host 'git add -> $target' -ForegroundColor Green
git add $target }
在地端從特定分支切一個新分支出來
function gck { param( [string]$ori_branch, [string]$new_branch ) git switch $ori_branch git checkout -b $new_branch }
開啟資料夾
function open-folder { param( [Parameter(Mandatory=$true)] [string]$folder_name )
# 指定資料夾
$folder = $global:MyFolderBaseDir + '' + $folder_name
# 開啟檔案總管
Start-Process $folder }
用VS 開啟資料夾
function open-folder { param( [Parameter(Mandatory=$true)] [string]$repo_name )
$fullPath = $global:MyVsWorkDir + '' + $repo_name
if (-Not (Test-Path $repo_name)) {
Write-Host '資料夾不存在: $fullPath' -ForegroundColor Red
return
}
& $global:VSPath $fullPath }
用VS 開解決方案
function open-sln { param( [Parameter(Mandatory=$true)] [string]$repo_name )
$fullPath = $global:MyVsWorkDir + '' + $repo_name
if (-Not (Test-Path $fullPath)) {
Write-Host '資料夾不存在: $fullPath' -ForegroundColor Red
return
}
$sln = Get-ChildItem -Path $fullPath -Filter *.sln | Select-Object -First 1
if ($sln -eq $null) {
Write-Host '找不到 .sln 檔案於資料夾: $fullPath' -ForegroundColor Red
return
}
& $global:VSPath $sln.FullName }
自定義的command ,參數設定自動補文字 (test跟oo)
Register-ArgumentCompleter -Native -CommandName open-sln -ScriptBlock { param($wordToComplete)
'test','oo' |
Where-Object { $_ -like '*$wordToComplete*' } |
ForEach-Object {
[System.Management.Automation.CompletionResult]::new(
$_, $_, 'ParameterValue', $_
)
} }
Bash
sh檔
a文檔開頭必放 #!/bin/bash
更改文字顏色,ANSI色碼
FONT_BLACK=’033[30m’ BG_LIGHT_GREEN=’033[102m’ RESET=’033[0m’
printf ‘$FONT_BLACK$BG_LIGHT_GREEN 測試 $RESET’
二、 1.用chrome 開網頁 start chrome.exe http://mydomain/test
2.註解 REM 這是註解
3.終端機印文字 echo Waiting for Docker to start…
4.啟動特定exe start c:/myprogram.exe
5.每5秒檢查docker 是否有開啟,有開就啟動特定container,沒開就繼續等待 REM 啟動Docker以及Sql Container echo Waiting for Docker to start…
goto CHECK
:CHECK docker info >nul 2>&1
if %errorlevel%==0 ( goto DO_ACTION )
echo Docker not ready, retry in 5 seconds… timeout /t 5 >nul goto CHECK
:DO_ACTION echo Docker is ready,Start Local Sql Server Container…
REM start container docker start mycontainer