aboutsummaryrefslogtreecommitdiff
path: root/src/cli/shell_completions.zig
blob: 6a4b2128fe03fd7093745ac1acef94b877e192bf (plain) (blame)
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const std = @import("std");
const bun = @import("bun");
const string = bun.string;
const Output = bun.Output;
const Global = bun.Global;
const Environment = bun.Environment;
const strings = bun.strings;
const MutableString = bun.MutableString;
const stringZ = bun.stringZ;
const default_allocator = bun.default_allocator;
const C = bun.C;

pub const Shell = enum {
    unknown,
    bash,
    zsh,
    fish,

    const bash_completions = @import("root").completions.bash;
    const zsh_completions = @import("root").completions.zsh;
    const fish_completions = @import("root").completions.fish;

    pub fn completions(this: Shell) []const u8 {
        return switch (this) {
            .bash => std.mem.span(bash_completions),
            .zsh => std.mem.span(zsh_completions),
            .fish => std.mem.span(fish_completions),
            else => "",
        };
    }

    pub fn fromEnv(comptime Type: type, SHELL: Type) Shell {
        const basename = std.fs.path.basename(SHELL);
        if (strings.eqlComptime(basename, "bash")) {
            return Shell.bash;
        } else if (strings.eqlComptime(basename, "zsh")) {
            return Shell.zsh;
        } else if (strings.eqlComptime(basename, "fish")) {
            return Shell.fish;
        } else {
            return Shell.unknown;
        }
    }
};

commands: []const []const u8 = &[_][]u8{},
descriptions: []const []const u8 = &[_][]u8{},
flags: []const []const u8 = &[_][]u8{},
shell: Shell = Shell.unknown,

pub fn print(this: @This()) void {
    defer Output.flush();
    var writer = Output.writer();

    if (this.commands.len == 0) return;
    const delimiter = if (this.shell == Shell.fish) " " else "\n";

    writer.writeAll(this.commands[0]) catch return;

    if (this.descriptions.len > 0) {
        writer.writeAll("\t") catch return;
        writer.writeAll(this.descriptions[0]) catch return;
    }

    if (this.commands.len > 1) {
        for (this.commands[1..]) |cmd, i| {
            writer.writeAll(delimiter) catch return;

            writer.writeAll(cmd) catch return;
            if (this.descriptions.len > 0) {
                writer.writeAll("\t") catch return;
                writer.writeAll(this.descriptions[i]) catch return;
            }
        }
    }
}
file/index.ts?h=ciro/gc-tests&id=3c7b9353e10d56327223b1a4abfa812ebacea696&follow=1'>Fix rendering of bun.lockb in vscode extensionGravatar Ashcon Partovi 5-114/+4 2023-09-20Run bun fmtGravatar Ashcon Partovi 2-12/+9 2023-09-20Update quickstartGravatar Colin McDonnell 1-0/+19 2023-09-20Update prisma guideGravatar Colin McDonnell 1-0/+6 2023-09-20Update env docGravatar Colin McDonnell 1-1/+1 2023-09-20Clarify hot modeGravatar Colin McDonnell 1-10/+9 2023-09-20[bun install] Add `-E` as alias of `--exact` (#5104)Gravatar Jonah Snider 2-2/+57 * [bun install] Add `-E` as alias of `--exact` * Add test for -E flag 2023-09-20feat: switch disableTelemetry to bunfig (#5690)Gravatar Lucas Coratger 3-1/+14 * feat: switch disableTelemetry to bunfig * feat: zig fmt * revert: the env variable and invert the logic of telemetry --------- Co-authored-by: MrPalixir <73360179+MrPalixir@users.noreply.github.com> 2023-09-20Treat `undefined` value as empty in expect.toThrow (#5788)Gravatar LongYinan 1-3/+3 Fix: https://github.com/napi-rs/napi-rs/blob/main/examples/napi/__tests__/test.framework.js#L16-L19 2023-09-20Fix various bugs in vscode extension (#5772)Gravatar JeremyFunk 3-9/+85 * Fix bugs * Fix bugs * Revert "Fix bugs" This reverts commit 608639eb2214fdf4310477051ce47d20702b5dd0. 2023-09-20add `emitDecoratorMetadata` (#5777)Gravatar Dylan Conway 19-110/+1884 * some progess * needs more tests * make tests easier to debug * get metadata for constructor arg decorators * fix some things * merge `emitDecoratorMetadata` option * remove `^` * bundler tests and get option from tsconfig earlier * remove spaces * fix tests 2023-09-20fix(doc): correct `server.reload` (#5799)Gravatar Ai Hoshino 1-1/+1 2023-09-20Call `Error.prepareStackTrace` on `new Error().stack` (#5802)Gravatar Jarred Sumner 6-155/+277 * Always call `Error.prepareStackTrace` * Support node:vm * Remove this * Handle more cases --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-09-20Fixes #5800Gravatar Jarred Sumner 1-1/+1 Fixes #5800 2023-09-20Fix path used in bunx (#5785)Gravatar Jarred Sumner 2-26/+51 * Fix path used in bunx * Add test * Use a different package --------- Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-09-20Fix RedirectURLTooLong errors (#5786)Gravatar ggobbe 1-1/+1 The URL to download the manifest for Artifact Registry in Google is larger than 4092 bytes. cf. issue #4748 2023-09-19Show when a newer version is available in the install screen (#5780)Gravatar Jarred Sumner 3-14/+95 Co-authored-by: Jarred Sumner <709451+Jarred-Sumner@users.noreply.github.com> 2023-09-19Fix broken linksGravatar Colin McDonnell 4-4/+4