mirror of
https://github.com/schollz/croc.git
synced 2025-10-11 05:11:06 +02:00
Merge pull request #822 from elliot40404/feature/copy-to-clipboard
Added copy to clipboard functionality for windows,linux and mac
This commit is contained in:
commit
0d48e346ad
1 changed files with 26 additions and 5 deletions
|
@ -12,22 +12,23 @@ import (
|
||||||
"math"
|
"math"
|
||||||
"net"
|
"net"
|
||||||
"os"
|
"os"
|
||||||
|
"os/exec"
|
||||||
"path"
|
"path"
|
||||||
"path/filepath"
|
"path/filepath"
|
||||||
|
"runtime"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
"sync"
|
"sync"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"golang.org/x/term"
|
|
||||||
"golang.org/x/time/rate"
|
|
||||||
|
|
||||||
"github.com/denisbrodbeck/machineid"
|
"github.com/denisbrodbeck/machineid"
|
||||||
ignore "github.com/sabhiram/go-gitignore"
|
ignore "github.com/sabhiram/go-gitignore"
|
||||||
log "github.com/schollz/logger"
|
log "github.com/schollz/logger"
|
||||||
"github.com/schollz/pake/v3"
|
"github.com/schollz/pake/v3"
|
||||||
"github.com/schollz/peerdiscovery"
|
"github.com/schollz/peerdiscovery"
|
||||||
"github.com/schollz/progressbar/v3"
|
"github.com/schollz/progressbar/v3"
|
||||||
|
"golang.org/x/term"
|
||||||
|
"golang.org/x/time/rate"
|
||||||
|
|
||||||
"github.com/schollz/croc/v10/src/comm"
|
"github.com/schollz/croc/v10/src/comm"
|
||||||
"github.com/schollz/croc/v10/src/compress"
|
"github.com/schollz/croc/v10/src/compress"
|
||||||
|
@ -307,7 +308,6 @@ func isChild(parentPath, childPath string) bool {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return !strings.HasPrefix(relPath, "..")
|
return !strings.HasPrefix(relPath, "..")
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// This function retrieves the important file information
|
// This function retrieves the important file information
|
||||||
|
@ -330,7 +330,7 @@ func GetFilesInfo(fnames []string, zipfolder bool, ignoreGit bool) (filesInfo []
|
||||||
paths = append(paths, fname)
|
paths = append(paths, fname)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
var ignoredPaths = make(map[string]bool)
|
ignoredPaths := make(map[string]bool)
|
||||||
if ignoreGit {
|
if ignoreGit {
|
||||||
wd, wdErr := os.Stat(".gitignore")
|
wd, wdErr := os.Stat(".gitignore")
|
||||||
if wdErr == nil {
|
if wdErr == nil {
|
||||||
|
@ -659,6 +659,7 @@ On the other computer run:
|
||||||
(For Linux/OSX)
|
(For Linux/OSX)
|
||||||
CROC_SECRET=%[1]q croc %[2]s
|
CROC_SECRET=%[1]q croc %[2]s
|
||||||
`, c.Options.SharedSecret, flags.String())
|
`, c.Options.SharedSecret, flags.String())
|
||||||
|
copyToClipboard(c.Options.SharedSecret)
|
||||||
if c.Options.Ask {
|
if c.Options.Ask {
|
||||||
machid, _ := machineid.ID()
|
machid, _ := machineid.ID()
|
||||||
fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid)
|
fmt.Fprintf(os.Stderr, "\rYour machine ID is '%s'\n", machid)
|
||||||
|
@ -2123,3 +2124,23 @@ func (c *Client) sendData(i int) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func copyToClipboard(str string) {
|
||||||
|
var cmd *exec.Cmd
|
||||||
|
switch runtime.GOOS {
|
||||||
|
case "windows":
|
||||||
|
cmd = exec.Command("cmd", "/c", "clip")
|
||||||
|
case "darwin":
|
||||||
|
cmd = exec.Command("pbcopy")
|
||||||
|
case "linux":
|
||||||
|
cmd = exec.Command("xclip", "-selection", "clipboard")
|
||||||
|
default:
|
||||||
|
return
|
||||||
|
}
|
||||||
|
cmd.Stdin = bytes.NewReader([]byte(str))
|
||||||
|
if err := cmd.Run(); err != nil {
|
||||||
|
log.Debugf("error copying to clipboard: %v", err)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
fmt.Fprintf(os.Stderr, "Code copied to clipboard")
|
||||||
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue