mirror of
https://github.com/RGBCube/crash
synced 2025-08-02 19:37: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",
|
.version = "0.0.1",
|
||||||
|
.fingerprint = 0xd7e8f0df85300b08,
|
||||||
|
|
||||||
.minimum_zig_version = "0.12.0",
|
.minimum_zig_version = "0.14.0",
|
||||||
|
|
||||||
.paths = .{
|
.paths = .{
|
||||||
"",
|
"src/main.zig",
|
||||||
|
"build.zig",
|
||||||
|
"build.zig.zon",
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
|
|
6
flake.lock
generated
6
flake.lock
generated
|
@ -2,11 +2,11 @@
|
||||||
"nodes": {
|
"nodes": {
|
||||||
"nixpkgs": {
|
"nixpkgs": {
|
||||||
"locked": {
|
"locked": {
|
||||||
"lastModified": 1715653339,
|
"lastModified": 1744442362,
|
||||||
"narHash": "sha256-7lR9tpVXviSccl07GXI0+ve/natd24HAkuy1sQp0OlI=",
|
"narHash": "sha256-i47t4DRIZgwBZw2Osbrp1OJhhO1k/n+QzRx+TrmfE9Y=",
|
||||||
"owner": "NixOS",
|
"owner": "NixOS",
|
||||||
"repo": "nixpkgs",
|
"repo": "nixpkgs",
|
||||||
"rev": "abd6d48f8c77bea7dc51beb2adfa6ed3950d2585",
|
"rev": "2349f9de17183971db12ae9e0123dab132023bd7",
|
||||||
"type": "github"
|
"type": "github"
|
||||||
},
|
},
|
||||||
"original": {
|
"original": {
|
||||||
|
|
|
@ -18,7 +18,7 @@
|
||||||
in {
|
in {
|
||||||
devShell = forEachSystem (system: with nixpkgs.legacyPackages.${system}; mkShell {
|
devShell = forEachSystem (system: with nixpkgs.legacyPackages.${system}; mkShell {
|
||||||
packages = [
|
packages = [
|
||||||
zig_0_12
|
zig_0_14
|
||||||
zls
|
zls
|
||||||
zon2nix
|
zon2nix
|
||||||
];
|
];
|
||||||
|
|
|
@ -2,7 +2,7 @@
|
||||||
lib,
|
lib,
|
||||||
stdenvNoCC,
|
stdenvNoCC,
|
||||||
|
|
||||||
zig,
|
zig_0_14,
|
||||||
|
|
||||||
bashInteractive,
|
bashInteractive,
|
||||||
fallbackShell ? bashInteractive,
|
fallbackShell ? bashInteractive,
|
||||||
|
@ -20,7 +20,7 @@ in stdenvNoCC.mkDerivation {
|
||||||
dontCheck = true;
|
dontCheck = true;
|
||||||
|
|
||||||
nativeBuildInputs = [
|
nativeBuildInputs = [
|
||||||
zig.hook
|
zig_0_14.hook
|
||||||
];
|
];
|
||||||
|
|
||||||
zigBuildFlags = [
|
zigBuildFlags = [
|
||||||
|
@ -34,7 +34,6 @@ in stdenvNoCC.mkDerivation {
|
||||||
homepage = "https://github.com/RGBCube/crash";
|
homepage = "https://github.com/RGBCube/crash";
|
||||||
license = licenses.mit;
|
license = licenses.mit;
|
||||||
mainProgram = "crash";
|
mainProgram = "crash";
|
||||||
platforms = platforms.linux;
|
platforms = platforms.unix;
|
||||||
maintainers = with maintainers; [ RGBCube ];
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
23
src/main.zig
23
src/main.zig
|
@ -1,8 +1,8 @@
|
||||||
const std = @import("std");
|
const std = @import("std");
|
||||||
const fallback_shell = @import("build_options").fallback_shell orelse @compileError("fallback shell was not specified");
|
const fallback_shell = @import("build_options").fallback_shell orelse @compileError("fallback shell was not specified");
|
||||||
|
|
||||||
pub fn fallback(alloc: std.mem.Allocator) noreturn {
|
pub fn fallback(alloc: std.mem.Allocator, args: []const []const u8) noreturn {
|
||||||
const err = std.process.execv(alloc, &[_][]const u8{fallback_shell});
|
const err = std.process.execv(alloc, args);
|
||||||
std.process.exit(@intCast(@intFromError(err)));
|
std.process.exit(@intCast(@intFromError(err)));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -10,7 +10,7 @@ pub fn main() noreturn {
|
||||||
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
var gpa = std.heap.GeneralPurposeAllocator(.{}){};
|
||||||
const alloc = gpa.allocator();
|
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);
|
defer alloc.free(args);
|
||||||
args.len = 0;
|
args.len = 0;
|
||||||
|
|
||||||
|
@ -20,18 +20,27 @@ pub fn main() noreturn {
|
||||||
args[args.len - 1] = arg;
|
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| {
|
while (it.next()) |shell| {
|
||||||
args[0] = shell;
|
args[0] = shell;
|
||||||
var child = std.process.Child.init(args, alloc);
|
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),
|
std.process.Child.Term.Exited => |exit_code| if (exit_code == 0) std.process.exit(0),
|
||||||
else => continue,
|
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