forked from 1Password/shell-plugins
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.go
53 lines (44 loc) · 1.22 KB
/
helpers.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package importer
import (
"context"
"github.com/1Password/shell-plugins/sdk"
)
func TryAll(importers ...sdk.Importer) sdk.Importer {
return func(ctx context.Context, in sdk.ImportInput, out *sdk.ImportOutput) {
for _, imp := range importers {
imp(ctx, in, out)
}
}
}
func MacOnly(importers ...sdk.Importer) sdk.Importer {
return func(ctx context.Context, in sdk.ImportInput, out *sdk.ImportOutput) {
if in.OS == "darwin" {
for _, imp := range importers {
imp(ctx, in, out)
}
}
}
}
func LinuxOnly(importers ...sdk.Importer) sdk.Importer {
return func(ctx context.Context, in sdk.ImportInput, out *sdk.ImportOutput) {
if in.OS == "linux" {
for _, imp := range importers {
imp(ctx, in, out)
}
}
}
}
const maxNameHintLength = 24
// SanitizeNameHint can be used to sanitize the name hint before passing it to the import candidate to
// improve the suggested item title.
func SanitizeNameHint(nameHint string) string {
// Omit the name hint if it's "default", which doesn't add much value in the item name
if nameHint == "default" {
return ""
}
// Avoid name hints that are too long
if len(nameHint) > maxNameHintLength {
nameHint = nameHint[:maxNameHintLength-1] + "…"
}
return nameHint
}