mirror of
https://github.com/RGBCube/crash
synced 2025-08-02 03:17:45 +00:00
Compare commits
3 commits
3405a772ba
...
7849872b30
Author | SHA1 | Date | |
---|---|---|---|
7849872b30 | |||
aa1d4f6693 | |||
119c52f090 |
5 changed files with 29 additions and 18 deletions
|
@ -1,10 +1,13 @@
|
|||
.{
|
||||
.name = "crash",
|
||||
.name = .crash,
|
||||
.version = "0.0.1",
|
||||
.fingerprint = 0xd7e8f0df85300b08,
|
||||
|
||||
.minimum_zig_version = "0.12.0",
|
||||
.minimum_zig_version = "0.14.0",
|
||||
|
||||
.paths = .{
|
||||
"",
|
||||
"src/main.zig",
|
||||
"build.zig",
|
||||
"build.zig.zon",
|
||||
},
|
||||
}
|
||||
|
|
6
flake.lock
generated
6
flake.lock
generated
|
@ -2,11 +2,11 @@
|
|||
"nodes": {
|
||||
"nixpkgs": {
|
||||
"locked": {
|
||||
"lastModified": 1715653339,
|
||||
"narHash": "sha256-7lR9tpVXviSccl07GXI0+ve/natd24HAkuy1sQp0OlI=",
|
||||
"lastModified": 1744442362,
|
||||
"narHash": "sha256-i47t4DRIZgwBZw2Osbrp1OJhhO1k/n+QzRx+TrmfE9Y=",
|
||||
"owner": "NixOS",
|
||||
"repo": "nixpkgs",
|
||||
"rev": "abd6d48f8c77bea7dc51beb2adfa6ed3950d2585",
|
||||
"rev": "2349f9de17183971db12ae9e0123dab132023bd7",
|
||||
"type": "github"
|
||||
},
|
||||
"original": {
|
||||
|
|
|
@ -18,7 +18,7 @@
|
|||
in {
|
||||
devShell = forEachSystem (system: with nixpkgs.legacyPackages.${system}; mkShell {
|
||||
packages = [
|
||||
zig_0_12
|
||||
zig_0_14
|
||||
zls
|
||||
zon2nix
|
||||
];
|
||||
|
|
|
@ -2,7 +2,7 @@
|
|||
lib,
|
||||
stdenvNoCC,
|
||||
|
||||
zig,
|
||||
zig_0_14,
|
||||
|
||||
bashInteractive,
|
||||
fallbackShell ? bashInteractive,
|
||||
|
@ -20,7 +20,7 @@ in stdenvNoCC.mkDerivation {
|
|||
dontCheck = true;
|
||||
|
||||
nativeBuildInputs = [
|
||||
zig.hook
|
||||
zig_0_14.hook
|
||||
];
|
||||
|
||||
zigBuildFlags = [
|
||||
|
@ -34,7 +34,6 @@ in stdenvNoCC.mkDerivation {
|
|||
homepage = "https://github.com/RGBCube/crash";
|
||||
license = licenses.mit;
|
||||
mainProgram = "crash";
|
||||
platforms = platforms.linux;
|
||||
maintainers = with maintainers; [ RGBCube ];
|
||||
platforms = platforms.unix;
|
||||
};
|
||||
}
|
||||
|
|
23
src/main.zig
23
src/main.zig
|
@ -1,8 +1,8 @@
|
|||
const std = @import("std");
|
||||
const fallback_shell = @import("build_options").fallback_shell orelse @compileError("fallback shell was not specified");
|
||||
|
||||
pub fn fallback(alloc: std.mem.Allocator) noreturn {
|
||||
const err = std.process.execv(alloc, &[_][]const u8{fallback_shell});
|
||||
pub fn fallback(alloc: std.mem.Allocator, args: []const []const u8) noreturn {
|
||||
const err = std.process.execv(alloc, args);
|
||||
std.process.exit(@intCast(@intFromError(err)));
|
||||
}
|
||||
|
||||
|
@ -10,7 +10,7 @@ pub fn main() noreturn {
|
|||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||
const alloc = gpa.allocator();
|
||||
|
||||
var args = alloc.alloc([]const u8, std.os.argv.len) catch fallback(alloc);
|
||||
var args = alloc.alloc([]const u8, std.os.argv.len) catch fallback(alloc, &[_][]const u8{fallback_shell});
|
||||
defer alloc.free(args);
|
||||
args.len = 0;
|
||||
|
||||
|
@ -20,18 +20,27 @@ pub fn main() noreturn {
|
|||
args[args.len - 1] = arg;
|
||||
}
|
||||
|
||||
const shells = std.posix.getenv("SHELLS") orelse fallback(alloc);
|
||||
const shells = std.posix.getenv("SHELLS") orelse fallback(alloc, args: {
|
||||
args[0] = fallback_shell;
|
||||
break :args args;
|
||||
});
|
||||
|
||||
var it = std.mem.split(u8, shells, ":");
|
||||
var it = std.mem.splitScalar(u8, shells, ':');
|
||||
while (it.next()) |shell| {
|
||||
args[0] = shell;
|
||||
var child = std.process.Child.init(args, alloc);
|
||||
|
||||
switch (child.spawnAndWait() catch fallback(alloc)) {
|
||||
switch (child.spawnAndWait() catch fallback(alloc, args: {
|
||||
args[0] = fallback_shell;
|
||||
break :args args;
|
||||
})) {
|
||||
std.process.Child.Term.Exited => |exit_code| if (exit_code == 0) std.process.exit(0),
|
||||
else => continue,
|
||||
}
|
||||
}
|
||||
|
||||
fallback(alloc);
|
||||
fallback(alloc, args: {
|
||||
args[0] = fallback_shell;
|
||||
break :args args;
|
||||
});
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue