You are here: PSPad forum > English discussion forum > VB script to handle github integration Desktop

VB script to handle github integration Desktop

#1 VB script to handle github integration Desktop

Posted by: peterle | Date: 2025-08-24 13:39 | IP: IP Logged

we lieber den github Desktop verwendet dann geht es damit

' GitHubDesktop.vbs – Repo im GitHub Desktop öffnen + Status in PSPad
Option Explicit
Dim module_name, fso
Set fso = CreateObject("Scripting.FileSystemObject")
module_name = "PB GitHub Desktop"

' --- Menüeintrag ---
Sub Init
Dim menuName
menuName = "&" & module_name
addMenuItem "Open in GitHub Desktop", menuName, "OpenInGHDesktop", "ALT+F8", "github.ico"
End Sub

Sub OpenInGHDesktop
Dim editor, FileDir, RepoDir, WshShell, ghPath, cmd
Dim exec, output, line, text, shell

Set editor = NewEditor()
editor.assignActiveEditor()

If editor.FileName = "" Then
MsgBox "Keine Datei geöffnet!", vbExclamation, "GitHub Desktop"
Exit Sub
End If

FileDir = fso.GetParentFolderName(editor.FileName)
RepoDir = FindGitRepo(FileDir)

If RepoDir = "" Then
MsgBox "Kein Git-Repository gefunden!", vbExclamation, "GitHub Desktop"
Exit Sub
End If

' --- 1. Git Status im PSPad anzeigen ---
Set WshShell = CreateObject("WScript.Shell")
Set exec = WshShell.Exec("cmd /c cd /d """ & RepoDir & """ && git status")

output = ""
Do Until exec.StdOut.AtEndOfStream
line = exec.StdOut.ReadLine()
output = output & line & vbCrLf
Loop
Do Until exec.StdErr.AtEndOfStream
line = exec.StdErr.ReadLine()
output = output & line & vbCrLf
Loop

text = "Git Status für: " & RepoDir & vbCrLf & String(60, "-") & vbCrLf & output
ShowInNewEditor text, "Git Status"

' --- 2. GitHub Desktop starten (direkt mit Repo-Pfad) ---
Set shell = CreateObject("WScript.Shell")
ghPath = """" & shell.ExpandEnvironmentStrings("%LocalAppData%") & "\GitHubDesktop\GitHubDesktop.exe" & """"

cmd = ghPath & " """ & RepoDir & """"
WshShell.Run cmd, 1, False
End Sub

' --- Hilfsroutine: sucht vom Startverzeichnis nach .git-Ordner ---
Function FindGitRepo(startDir)
Dim currentDir
currentDir = startDir

Do Until currentDir = ""
If fso.FolderExists(currentDir & "\.git") Then
FindGitRepo = currentDir
Exit Function
End If
currentDir = fso.GetParentFolderName(currentDir)
Loop

FindGitRepo = ""
End Function

' --- Hilfsfunktion: Text in neuem PSPad-Fenster anzeigen ---
Sub ShowInNewEditor(text, title)
Dim tempFile, f, ed
tempFile = GetTempName() & ".txt"

' Inhalt in temporäre Datei schreiben
Set f = fso.CreateTextFile(tempFile, True, True)
f.Write text
f.Close

' Datei in PSPad öffnen
Set ed = NewEditor()
ed.OpenFile tempFile
ed.assignActiveEditor()
'ed.setCaption title ' nicht unterstützt
End Sub

Function GetTempName()
Dim tempPath
tempPath = fso.GetSpecialFolder(2) ' 2 = TemporaryFolder
GetTempName = fso.BuildPath(tempPath, fso.GetTempName)
End Function

Options: Reply | Quote | Up ^






Editor PSPad - freeware editor, © 2001 - 2025 Jan Fiala, Hosted by Webhosting TOJEONO.CZ, design by WebDesign PAY & SOFT, code Petr Dvořák, Privacy policy and GDPR