Compare commits
5 Commits
3d648d7c90
...
main
Author | SHA1 | Date | |
---|---|---|---|
32209ce982 | |||
11a791ed7c | |||
55e9ea9cdf | |||
bd51959bb4 | |||
bfd200f1ec |
2
.gitignore
vendored
Normal file
2
.gitignore
vendored
Normal file
@@ -0,0 +1,2 @@
|
|||||||
|
dist/
|
||||||
|
*.txt
|
44
README.md
44
README.md
@@ -1,3 +1,43 @@
|
|||||||
# clip2snips
|
# Clip2Snips
|
||||||
|
|
||||||
Eine Go-Anwendung, die Text aus der Zwischenablage an snips.sh sendet
|
Eine sehr kleine und wenig sinnvolle Go-Anwendung, die Text aus der Zwischenablage an [snips.sh](https://snips.sh/) sendet und die resultierende URL zurück in die Zwischenablage kopiert.
|
||||||
|
|
||||||
|
## Voraussetzungen
|
||||||
|
|
||||||
|
- Go 1.21 oder höher (für Build)
|
||||||
|
- SSH-Zugang zu snips.sh
|
||||||
|
- SSH Schlüsselpaar - ggf. `ssh-keygen` (alle OS) ausführen
|
||||||
|
- Betriebssystemspezifische Anforderungen:
|
||||||
|
- Windows: PowerShell
|
||||||
|
- Linux: xclip oder xsel (`sudo apt install xclip` oder `sudo apt install xsel`)
|
||||||
|
- macOS: keine zusätzlichen Anforderungen (pbcopy/pbpaste sind vorinstalliert)
|
||||||
|
|
||||||
|
## Installation
|
||||||
|
|
||||||
|
1. Klonen Sie das Repository
|
||||||
|
2. Führen Sie den Build für Ihr Betriebssystem aus:
|
||||||
|
```powershell
|
||||||
|
# Windows (PowerShell)
|
||||||
|
.\build.ps1
|
||||||
|
```
|
||||||
|
Die Binärdateien werden im `dist`-Verzeichnis erstellt:
|
||||||
|
- Windows: `clip2snips.exe`
|
||||||
|
- Linux: `clip2snips-linux`
|
||||||
|
- macOS: `clip2snips-darwin`
|
||||||
|
|
||||||
|
3. Stellen Sie sicher, dass Sie SSH-Zugang zu snips.sh haben (ggf. `ssh snips.sh` ausführen und den SSH-Key akzeptieren)
|
||||||
|
|
||||||
|
## Verwendung
|
||||||
|
|
||||||
|
1. Kopieren Sie Text in die Zwischenablage
|
||||||
|
2. Führen Sie die Anwendung aus
|
||||||
|
3. Die Snips-URL wird automatisch in die Zwischenablage kopiert und in der Konsole angezeigt
|
||||||
|
|
||||||
|
## Fehlerbehebung
|
||||||
|
|
||||||
|
- Stellen Sie sicher, dass Sie eine aktive Internetverbindung haben
|
||||||
|
- Überprüfen Sie Ihre SSH-Konfiguration für snips.sh
|
||||||
|
- Betriebssystemspezifische Probleme:
|
||||||
|
- Windows: Stellen Sie sicher, dass PowerShell verfügbar ist
|
||||||
|
- Linux: Installieren Sie xclip oder xsel
|
||||||
|
- macOS: Keine speziellen Anforderungen
|
32
build.ps1
Normal file
32
build.ps1
Normal file
@@ -0,0 +1,32 @@
|
|||||||
|
# build.ps1
|
||||||
|
|
||||||
|
# Erstelle Ausgabeverzeichnis
|
||||||
|
$outDir = "dist"
|
||||||
|
if (-not (Test-Path $outDir)) {
|
||||||
|
New-Item -ItemType Directory -Path $outDir
|
||||||
|
}
|
||||||
|
|
||||||
|
# Build-Konfigurationen
|
||||||
|
$targets = @(
|
||||||
|
@{OS="windows"; ARCH="amd64"; EXT=".exe"},
|
||||||
|
@{OS="linux"; ARCH="amd64"; EXT=""},
|
||||||
|
@{OS="darwin"; ARCH="amd64"; EXT=""}
|
||||||
|
)
|
||||||
|
|
||||||
|
# Führe Builds aus
|
||||||
|
foreach ($target in $targets) {
|
||||||
|
$outFile = "clip2snips$($target.EXT)"
|
||||||
|
if ($target.OS -ne "windows") {
|
||||||
|
$outFile = "clip2snips-$($target.OS)$($target.EXT)"
|
||||||
|
}
|
||||||
|
$outPath = Join-Path $outDir $outFile
|
||||||
|
|
||||||
|
Write-Host "Building for $($target.OS)/$($target.ARCH)..."
|
||||||
|
$env:GOOS = $target.OS
|
||||||
|
$env:GOARCH = $target.ARCH
|
||||||
|
|
||||||
|
go build -o $outPath
|
||||||
|
}
|
||||||
|
|
||||||
|
Write-Host "`nBuild completed. Binaries in ./$outDir/:"
|
||||||
|
Get-ChildItem $outDir
|
41
clip2snips.ps1
Normal file
41
clip2snips.ps1
Normal file
@@ -0,0 +1,41 @@
|
|||||||
|
# clip2snips.ps1
|
||||||
|
|
||||||
|
# Setze Output-Encoding auf UTF-8
|
||||||
|
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
$OutputEncoding = [System.Text.Encoding]::UTF8
|
||||||
|
|
||||||
|
# Hole Text aus der Zwischenablage
|
||||||
|
$clipText = Get-Clipboard
|
||||||
|
if ([string]::IsNullOrWhiteSpace($clipText)) {
|
||||||
|
Write-Host "die zwischenablage ist leer"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Entferne Zeilenumbrüche am Ende
|
||||||
|
$clipText = $clipText.TrimEnd()
|
||||||
|
|
||||||
|
# Sende Text an snips.sh und hole die Antwort
|
||||||
|
try {
|
||||||
|
# Verwende -rawOutput um Encoding-Probleme zu vermeiden
|
||||||
|
$output = $clipText | ssh -T snips.sh 2>&1 | Out-String
|
||||||
|
# Write-Host "Debug - SSH Antwort:"
|
||||||
|
#Write-Host $output
|
||||||
|
} catch {
|
||||||
|
Write-Host "fehler beim senden an snips.sh: $_"
|
||||||
|
exit 1
|
||||||
|
}
|
||||||
|
|
||||||
|
# Extrahiere die URL mit verbessertem Regex
|
||||||
|
if ($output -match 'f:([_a-zA-Z0-9]+)@snips\.sh') {
|
||||||
|
$id = $matches[1]
|
||||||
|
$url = "https://snips.sh/f/$id"
|
||||||
|
|
||||||
|
# Kopiere URL in die Zwischenablage
|
||||||
|
$url | Set-Clipboard
|
||||||
|
|
||||||
|
# Gib URL aus
|
||||||
|
Write-Host $url
|
||||||
|
} else {
|
||||||
|
Write-Host "keine url in der antwort gefunden"
|
||||||
|
exit 1
|
||||||
|
}
|
118
main.go
Normal file
118
main.go
Normal file
@@ -0,0 +1,118 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"os/exec"
|
||||||
|
"regexp"
|
||||||
|
"runtime"
|
||||||
|
"strings"
|
||||||
|
)
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
// Text aus der Zwischenablage lesen
|
||||||
|
clipText, err := getClipboard()
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("fehler beim lesen der zwischenablage: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Entferne Zeilenumbrüche am ende
|
||||||
|
clipText = strings.TrimSpace(clipText)
|
||||||
|
if clipText == "" {
|
||||||
|
fmt.Println("die zwischenablage ist leer")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// Text an snips.sh senden
|
||||||
|
output, err := sendToSnips(clipText)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("fehler beim senden an snips.sh: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// URL aus der antwort extrahieren
|
||||||
|
url := extractURL(output)
|
||||||
|
if url == "" {
|
||||||
|
fmt.Println("keine url in der antwort gefunden")
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
// URL in die zwischenablage kopieren
|
||||||
|
err = setClipboard(url)
|
||||||
|
if err != nil {
|
||||||
|
fmt.Printf("fehler beim kopieren der url: %v\n", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
|
fmt.Println(url)
|
||||||
|
}
|
||||||
|
|
||||||
|
func getClipboard() (string, error) {
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
cmd = exec.Command("powershell", "-command", "Get-Clipboard")
|
||||||
|
case "linux":
|
||||||
|
// Prüfe, ob xclip installiert ist
|
||||||
|
if _, err := exec.LookPath("xclip"); err == nil {
|
||||||
|
cmd = exec.Command("xclip", "-selection", "clipboard", "-o")
|
||||||
|
} else if _, err := exec.LookPath("xsel"); err == nil {
|
||||||
|
cmd = exec.Command("xsel", "--clipboard", "--output")
|
||||||
|
} else {
|
||||||
|
return "", fmt.Errorf("weder xclip noch xsel sind installiert")
|
||||||
|
}
|
||||||
|
case "darwin": // macOS
|
||||||
|
cmd = exec.Command("pbpaste")
|
||||||
|
default:
|
||||||
|
return "", fmt.Errorf("betriebssystem %s wird nicht unterstützt", runtime.GOOS)
|
||||||
|
}
|
||||||
|
|
||||||
|
output, err := cmd.Output()
|
||||||
|
if err != nil {
|
||||||
|
return "", err
|
||||||
|
}
|
||||||
|
return string(output), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func setClipboard(text string) error {
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
cmd = exec.Command("powershell", "-command", fmt.Sprintf("Set-Clipboard -Value '%s'", text))
|
||||||
|
case "linux":
|
||||||
|
// Prüfe, ob xclip installiert ist
|
||||||
|
if _, err := exec.LookPath("xclip"); err == nil {
|
||||||
|
cmd = exec.Command("xclip", "-selection", "clipboard")
|
||||||
|
} else if _, err := exec.LookPath("xsel"); err == nil {
|
||||||
|
cmd = exec.Command("xsel", "--clipboard", "--input")
|
||||||
|
} else {
|
||||||
|
return fmt.Errorf("weder xclip noch xsel sind installiert")
|
||||||
|
}
|
||||||
|
case "darwin": // macOS
|
||||||
|
cmd = exec.Command("pbcopy")
|
||||||
|
default:
|
||||||
|
return fmt.Errorf("betriebssystem %s wird nicht unterstützt", runtime.GOOS)
|
||||||
|
}
|
||||||
|
|
||||||
|
cmd.Stdin = strings.NewReader(text)
|
||||||
|
return cmd.Run()
|
||||||
|
}
|
||||||
|
|
||||||
|
func sendToSnips(text string) (string, error) {
|
||||||
|
cmd := exec.Command("ssh", "-T", "snips.sh")
|
||||||
|
cmd.Stdin = strings.NewReader(text)
|
||||||
|
output, err := cmd.CombinedOutput()
|
||||||
|
if err != nil {
|
||||||
|
return "", fmt.Errorf("SSH-Fehler: %v\nOutput: %s", err, string(output))
|
||||||
|
}
|
||||||
|
return string(output), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
func extractURL(output string) string {
|
||||||
|
re := regexp.MustCompile(`f:([a-zA-Z0-9]+)@snips\.sh`)
|
||||||
|
matches := re.FindStringSubmatch(output)
|
||||||
|
if len(matches) > 1 {
|
||||||
|
return fmt.Sprintf("https://snips.sh/f/%s", matches[1])
|
||||||
|
}
|
||||||
|
return ""
|
||||||
|
}
|
Reference in New Issue
Block a user