LoginSignup
1
0

More than 1 year has passed since last update.

ChatGPT にお願いして、PowerShell でGitからソースコードを取得してZip化&treeっぽいテキストファイルを作ってもらった

Posted at

背景

Bat で同様のコードがあったが、Windows の文字コード関連のUpdateによって文字化けが発生してた。
修正しようと思ったら手こずったので・・

いっそ AI さんに最初から作ってもらおうって試した記録

会話の結果

# Create the directory "source"
New-Item -ItemType Directory -Path source

# Set the working directory to "source"
Set-Location source

# Clone the repository
git clone https://github.com/m-radzikowski/aws-sdk-client-mock.git

# Set the working directory to the repository directory
Set-Location aws-sdk-client-mock

# Get the Git hash
$gitHash = git rev-parse --short HEAD

# Get the current date
$date = Get-Date -Format "yyyyMMdd"

# Create the zip file name
$zipFileName = "src_$date($gitHash).zip"

# Get the current working directory
$currentDirectory = Get-Location

# Create the destination path
$destination = "$currentDirectory\..\$zipFileName"

# Zip the sources
Compress-Archive -Path "$PWD\*" -DestinationPath $destination

# Print the zip file name
Write-Output "Zip file created: $destination"

# Custom function to display the file tree
function Get-Tree {
  param (
    [string]$Path,
    [int]$Indentation = 0
  )

  Get-ChildItem $Path | ForEach-Object {
    $prefix = "  " * $Indentation
    if ($_.PsIsContainer) {
      Write-Output "$prefix|-- $($_.Name)"
    } else {
      Write-Output "$prefix|-- $($_.Name)"
    }

    if ($_.PsIsContainer) {
      Get-Tree -Path $_.FullName -Indentation ($Indentation + 1)
    }
  }
}

# Get the file list and write to a file
Get-Tree -Path "$PWD" | Set-Content "$currentDirectory\..\sourceList.txt"

あとがき

何がすごいのか

  • 問題点を指摘すると修正してくれる
  • おかしいところを聞くと、理由を教えてくれる
  • 例を見せると、取り入れてくれる
  • 平均以上の知識を期待できるので、苦手な部分の補助や初学者の支援には最適

ちょうどいま、新しい業務に切り替わって技術全般初学者に戻ってるので、頼っていこうと思う。

1
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
0