Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(*): add noclip options and vim motion for windows #65

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,10 @@ WEBSITE:
Aliases: []string{"c"},
Usage: "Select only items with given category",
},
&ucli.BoolFlag{
Name: "noclip",
Usage: "Disable clipboard",
},
}

// default command to get password
Expand Down
7 changes: 3 additions & 4 deletions pkg/action/default.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ func (s *Action) Default(c *ucli.Context) error {
return err
}

if ctxutil.IsQuickSelect(ctx) {
if ctxutil.IsQuickSelect(ctx) && !ctxutil.IsNoClip(ctx) {
// disable notifications for quick select
if err = clipboard.CopyTo(ctxutil.WithNotifications(ctx, false), "", []byte(credential.Username)); err != nil {
return ExitError(ExitIO, err, "failed to copy to clipboard: %s", err)
Expand All @@ -60,18 +60,17 @@ func (s *Action) Default(c *ucli.Context) error {
return err
}

if ctxutil.IsAutoClip(ctx) {
if ctxutil.IsAutoClip(ctx) && !ctxutil.IsNoClip(ctx) {
identifier := out.BuildIdentifier(name, credential.Username)
if err = clipboard.CopyTo(ctx, identifier, []byte(credential.Password)); err != nil {
return ExitError(ExitIO, err, "failed to copy to clipboard: %s", err)
}
if ctxutil.IsAutoClip(ctx) && !c.Bool("print") {
if !c.Bool("print") {
out.SuccessfulCopiedToClipboard(name, credential.Username)
return nil
}
}

out.DisplayCredential(credential)
out.SuccessfulCopiedToClipboard(name, credential.Username)
return nil
}
8 changes: 8 additions & 0 deletions pkg/cli/selection/selection_windows.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,14 @@ func Default(message string, items []string) (int, error) {
case keys.Down:
list.Next()
update = true
case keys.RuneKey:
if key.String() == "j" {
list.Next()
update = true
} else if key.String() == "k" {
list.Prev()
update = true
}
}

if update {
Expand Down
12 changes: 12 additions & 0 deletions pkg/ctxutil/ctxutil.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ const (
ctxKeyQuickSelect
ctxKeyCategory
ctxKeyPhoneNumber
ctxNoClip
)

// WithGlobalFlags parses any global flags from the cli context and returns
Expand All @@ -39,6 +40,9 @@ func WithGlobalFlags(c *cli.Context) context.Context {
if c.IsSet("category") {
ctx = WithCategory(ctx, c.String("category"))
}
if c.IsSet("noclip") {
ctx = WithNoClip(ctx, true)
}

return ctx
}
Expand Down Expand Up @@ -350,3 +354,11 @@ func GetPhoneNumber(ctx context.Context) string {
}
return sv
}

func WithNoClip(ctx context.Context, value bool) context.Context {
return context.WithValue(ctx, ctxNoClip, value)
}

func IsNoClip(ctx context.Context) bool {
return is(ctx, ctxNoClip, false)
}
Loading