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

allow specifying regname for GinBrowse ++yank #112

Merged
merged 5 commits into from
Nov 11, 2023
Merged
Show file tree
Hide file tree
Changes from 4 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
12 changes: 8 additions & 4 deletions denops/gin/command/browse/command.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,14 @@ import { yank } from "../../util/yank.ts";

export type ExecOptions = Omit<Options, "cwd" | "aliases"> & {
worktree?: string;
yank?: boolean;
yank: string | boolean;
atusy marked this conversation as resolved.
Show resolved Hide resolved
noBrowser?: boolean;
};

export async function exec(
denops: Denops,
commitish: string,
options: ExecOptions = {},
options: ExecOptions = { yank: false },
): Promise<void> {
const [verbose, aliases] = await batch.collect(denops, (denops) => [
option.verbose.get(denops),
Expand Down Expand Up @@ -56,8 +56,12 @@ export async function exec(
aliases,
});

if (options.yank) {
await yank(denops, url.href);
if (options.yank !== false) {
await yank(
denops,
url.href,
options.yank === true ? undefined : options.yank,
);
}
if (options.noBrowser) {
await denops.cmd("echomsg url", { url: url.href });
Expand Down
2 changes: 1 addition & 1 deletion denops/gin/command/browse/main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ async function command(
);
await exec(denops, commitish ?? "HEAD", {
worktree: opts.worktree,
yank: "yank" in opts,
yank: opts.yank === "" ? true : (opts.yank ?? false),
noBrowser: ("n" in flags || "no-browser" in flags),
remote: ensure(flags.remote, is.OneOf([is.Undefined, is.String]), {
"message": "REMOTE in --remote={REMOTE} must be string",
Expand Down
3 changes: 2 additions & 1 deletion denops/gin/util/yank.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ import { v } from "https://deno.land/x/denops_std@v5.0.1/variable/mod.ts";
export async function yank(
denops: Denops,
value: string,
reg?: string,
): Promise<void> {
const reg = await v.get(denops, "register");
reg = reg ?? await v.get(denops, "register");
await fn.setreg(denops, reg, value);
}
7 changes: 7 additions & 0 deletions denops/gin/util/yank_test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,11 @@ test("all", "yank", async (denops, t) => {
assertEquals(await denops.eval("getreg(v:register)"), "Hello world");
},
});
await t.step({
name: "sets the value to the named register a",
fn: async () => {
await yank(denops, "Hello world", "a");
assertEquals(await denops.eval("getreg('a')"), "Hello world");
},
});
});
5 changes: 4 additions & 1 deletion doc/gin.txt
Original file line number Diff line number Diff line change
Expand Up @@ -177,8 +177,11 @@ COMMANDS *gin-commands*

The following options are valid as {++option}:

++yank
++yank={regname}
Yank the URL to the clipboard.
{regname} is optional and defaults to |v:register|.
If non-empty string is given, the value is passed to the
{regname} argument of |setreg()|.

See |gin-commands-options| for common {++option}.

Expand Down
Loading