-
-
Notifications
You must be signed in to change notification settings - Fork 60
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* Added xclip completer * xclip: use flag functions for long shorthand - shared action --------- Co-authored-by: rsteube <rsteube@users.noreply.github.com>
- Loading branch information
Showing
3 changed files
with
83 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
package cmd | ||
|
||
import ( | ||
"github.com/carapace-sh/carapace" | ||
"github.com/carapace-sh/carapace-bin/pkg/actions/os" | ||
"github.com/carapace-sh/carapace-bin/pkg/actions/tools/xclip" | ||
"github.com/spf13/cobra" | ||
) | ||
|
||
var rootCmd = &cobra.Command{ | ||
Use: "xclip [flags] [FILE]", | ||
Short: "command line interface to X selections", | ||
Long: "https://github.com/astrand/xclip/", | ||
Run: func(cmd *cobra.Command, args []string) {}, | ||
} | ||
|
||
func Execute() error { | ||
return rootCmd.Execute() | ||
} | ||
|
||
func init() { | ||
carapace.Gen(rootCmd).Standalone() | ||
|
||
rootCmd.Flags().StringN("display", "d", "", "X display to use") | ||
rootCmd.Flags().BoolN("filter", "f", false, "Print the text piped to standard in back to standard out") | ||
rootCmd.Flags().BoolN("help", "h", false, "Show quick summary of options") | ||
rootCmd.Flags().BoolN("in", "i", true, "Read text into X selection") | ||
rootCmd.Flags().IntN("loops", "l", 0, "Number of X selection requests to wait before exiting") | ||
rootCmd.Flags().BoolS("noutf8", "noutf8", false, "Operate in legacy mode") | ||
rootCmd.Flags().BoolN("out", "o", true, "Print the X selection to standard out") | ||
rootCmd.Flags().BoolS("quiet", "quiet", false, "Run in the foreground, output information messages") | ||
rootCmd.Flags().BoolN("rmlastnl", "r", false, "Remove any trailing newlines from the selection") | ||
rootCmd.Flags().StringS("selection", "selection", "primary", "Specify which X selection to use") | ||
rootCmd.Flags().BoolS("silent", "silent", true, "Fork into background to wait, output errors only") | ||
rootCmd.Flags().StringN("target", "t", "TEXT", "Specify a specific data format with given target atom") | ||
rootCmd.Flags().BoolS("verbose", "verbose", false, "Verbose output") | ||
rootCmd.Flags().BoolS("version", "version", false, "Show version information") | ||
|
||
rootCmd.MarkFlagsMutuallyExclusive("in", "out") | ||
rootCmd.MarkFlagsMutuallyExclusive("filter", "out") | ||
rootCmd.MarkFlagsMutuallyExclusive("quiet", "silent", "verbose") | ||
|
||
carapace.Gen(rootCmd).FlagCompletion(carapace.ActionMap{ | ||
"display": os.ActionDisplays(), | ||
"selection": carapace.ActionValues("primary", "secondary", "clipboard"), | ||
"target": carapace.Batch( | ||
xclip.ActionTargets(), | ||
carapace.ActionValues("TARGETS"), | ||
).ToA(), | ||
}) | ||
|
||
carapace.Gen(rootCmd).PositionalCompletion( | ||
carapace.ActionFiles(), | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package main | ||
|
||
import "github.com/carapace-sh/carapace-bin/completers/xclip_completer/cmd" | ||
|
||
func main() { | ||
cmd.Execute() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
package xclip | ||
|
||
import ( | ||
"strings" | ||
|
||
"github.com/carapace-sh/carapace" | ||
) | ||
|
||
// ActionTargets completes selection targets | ||
func ActionTargets() carapace.Action { | ||
return carapace.ActionExecCommand("xclip", "-t", "TARGETS", "-o")(func(output []byte) carapace.Action { | ||
lines := strings.Split(string(output), "\n") | ||
values := make([]string, 0) | ||
for _, line := range lines { | ||
if line != "" { | ||
values = append(values, line) | ||
} | ||
} | ||
return carapace.ActionValues(values...) | ||
}) | ||
} |