Einer für alle


Quelle Bild: DALL-E „chameleon caspar david friedrich“

Ein sehr interessanter Kommentar eines Lesers beschäftigt sich mit der Frage, ob ChatGPT auch Code von einer Sprache / einem System in ein(e) andere(s) transformieren kann. Das haben wir natürlich gleich einmal ausprobiert und durch ChatGPT den Code unseres Gesundheitstagesbuches von Bash (Linux) nach Powershell (Windows) übersetzen lassen:

„Here’s the PowerShell equivalent of the Bash script you posted:“

$ErrorActionPreference = "Stop"

$editor = "subl"

$defaults = @(
   "Was habe ich heute gegessen?"
   "Gesundheitlicher Zustand?"
   "Welche Aktivitäten durchgeführt?"
   "Für was bin ich heute dankbar?"
)

$homedir = Split-Path -Parent $MyInvocation.MyCommand.Definition
$allfnam = Join-Path $homedir "gesundheitstagebuch.txt"
$tagfnam = New-TemporaryFile
$tmpfnam = New-TemporaryFile
$curdate = Get-Date -Format "dddd dd.MM.yyyy"

##############################################################
## Dieser Block muss an den gewählten Editor angepasst sein ##
##############################################################
if (Get-Process $editor -ErrorAction SilentlyContinue | Where-Object {$_.MainModule.FileName -eq $allfnam}) {
Start-Process -FilePath wmctrl -ArgumentList "-a","$(Split-Path -Leaf $allfnam) - Sublime Text"
   exit 0
}
##############################################################

if ((Get-Content $allfnam -TotalCount 1 -ErrorAction SilentlyContinue) -ne $curdate) {
   "$curdate`n" | Out-File -FilePath $tagfnam -Encoding utf8
   foreach ($entry in $defaults) {
      "$entry ** `n`n" | Out-File -FilePath $tagfnam -Encoding utf8 -Append
   } 
   '=%.0s' * 79 | Out-File -FilePath $tagfnam -Encoding utf8 -Append; "`n" | Out-File -FilePath $tagfnam -Encoding utf8 -Append
   if (!(Test-Path $allfnam)) {
      Copy-Item -Path $tagfnam -Destination $allfnam
   } else {
      Get-Content $tagfnam,$allfnam | Set-Content -Path $tmpfnam -Encoding utf8
      Move-Item -Path $tmpfnam -Destination $allfnam -Force
   }
   Remove-Item $tagfnam
}

Start-Process -FilePath $editor -ArgumentList $allfnam

„Note that some of the functionality in the original Bash script (such as the wmctrl command) may not be available in PowerShell and would need to be replaced with alternative commands or methods.“

Leider reichen meine Powershell-Kenntnisse nicht so weit, dass ich die Qualität des Codes beurteilen könnte, aber das ist mindestens beim Lernen einer Programmiersprache eine sehr interessante Möglichkeit: Man formuliert die Befehle in einer Sprache, die man kennt, und lässt sie in die zu lernende Sprache übersetzen.

Tja. Es wäre schon nett, wenn Menschen so etwas auch könnten. Man lernt eine Programmiersprache und kann gleich alle anderen auch…

Schreibe einen Kommentar

Deine E-Mail-Adresse wird nicht veröffentlicht. Erforderliche Felder sind mit * markiert