mirror of
https://github.com/oven-sh/bun
synced 2026-02-10 10:58:56 +00:00
* Prepare to upgrade zig
* zig fmt
* AllocGate
* Update data_url.zig
* wip
* few files
* just headers now?
* I think everything works?
* Update mimalloc
* Update hash_map.zig
* Perf improvements to compensate for Allocgate
* Bump
* 📷
* Update bun.lockb
* Less branching
* [js parser] Slightly reduce memory usage
* Update js_parser.zig
* WIP remove unused
* [JS parser] WIP support for `with` keyword
* Remove more dead code
* Fix all the build errors!
* cleanup
* Move `network_thread` up
* Bump peechy
* Update README.md
77 lines
2.3 KiB
Zig
77 lines
2.3 KiB
Zig
const std = @import("std");
|
|
const _global = @import("../global.zig");
|
|
const string = _global.string;
|
|
const Output = _global.Output;
|
|
const Global = _global.Global;
|
|
const Environment = _global.Environment;
|
|
const strings = _global.strings;
|
|
const MutableString = _global.MutableString;
|
|
const stringZ = _global.stringZ;
|
|
const default_allocator = _global.default_allocator;
|
|
const C = _global.C;
|
|
|
|
pub const Shell = enum {
|
|
unknown,
|
|
bash,
|
|
zsh,
|
|
fish,
|
|
|
|
const bash_completions = @embedFile("../../completions/bun.bash");
|
|
const zsh_completions = @embedFile("../../completions/bun.zsh");
|
|
const fish_completions = @embedFile("../../completions/bun.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;
|
|
}
|
|
}
|
|
}
|
|
}
|