PowerShell 스크립트로 빠르게 gist 생성하기 본문

ETC

PowerShell 스크립트로 빠르게 gist 생성하기

miensoap 2024. 7. 15. 22:05

 

실사용 영상

 

 

param(
    [int]$DayNumber
)

# Day00 형식의 폴더 이름 생성
$folderName = "Day{0:00}" -f $DayNumber

# template.md 파일에서 내용 읽기
$templatePath = "E:\User\your\template.md"
$templateContent = Get-Content -Path $templatePath -Raw

# README.md 파일 생성 및 내용 작성
$readmeContent = $templateContent -replace "# Day", "# $folderName"
$readmePath = "README.md"
Set-Content -Path $readmePath -Value $readmeContent

# Gist 생성
$gistDescription = "your description - $folderName"
$gistOutput = gh gist create $readmePath -d "$gistDescription"

# Gist URL 추출
$gistUrl = $gistOutput | Select-String -Pattern "https://gist.github.com/.*" | ForEach-Object { $_.Matches[0].Value }

if ($gistUrl) {
    Write-Host "Gist 생성 성공 : $gistUrl"
   
    # Gist URL을 Chrome에서 열기
    Open-URLInChrome -URL $gistUrl

    # Gist를 같은 폴더명으로 클론
    git clone $gistUrl $folderName

    # 원래의 파일 삭제
    Remove-Item -Path $readmePath -Force

    # 클론한 폴더로 이동
    Set-Location $folderName

    # VSCode 열기
    code .
   
    Write-Host "$folderName Gist 클론 성공!"
} else {
    Write-Host "Gist URL을 찾을 수 없습니다."
}
1. template.md 파일의 내용에서, Day 부분을 인자로 받은 일자로 수정해 새 README 파일을 만든다.
2. `github cli`를 이용해 gist를 업로드 한 후, 크롬으로 링크를 연다.
3. 해당 gist를 클론한 후, vscode 프로젝트로 폴더를 연다.

 

 

부스트캠프 챌린지 미션 진행 중, 매일 gist를 만들고, 클론하는 것이 번거로워서 만들어 보았습니다.

이제 파워쉘에 `CreateGist n` 입력만으로 오늘의 미션을 시작할 수 있게 되었습니다!  😮😮

 

 

(수정) gist를 secret으로 만들려면

 `gh gist create {path} -d {description} -p` 명령어에서 `-p` 제외하고 사용

 

'ETC' 카테고리의 다른 글

Oh-my-posh 테마 랜덤으로 사용하기  (2) 2024.07.05
소중단 배포  (4) 2024.06.03