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

Enable command color for shebang recipes #1911

Merged
Merged
Show file tree
Hide file tree
Changes from all 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
5 changes: 5 additions & 0 deletions justfile
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,11 @@ _sh:
hello='Yo'
echo "$hello from a shell script!"

_nu:
#!/usr/bin/env nu
let hellos = ["Greetings", "Yo", "Howdy"]
$hellos | each {|el| print $"($el) from a nushell script!" }

_ruby:
#!/usr/bin/env ruby
puts "Hello from ruby!"
Expand Down
9 changes: 8 additions & 1 deletion src/recipe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -310,7 +310,14 @@ impl<'src, D> Recipe<'src, D> {

if config.verbosity.loud() && (config.dry_run || self.quiet) {
for line in &evaluated_lines {
eprintln!("{line}");
eprintln!(
"{}",
config
.color
.command(config.command_color)
.stderr()
.paint(line)
);
}
}

Expand Down
31 changes: 31 additions & 0 deletions tests/shebang.rs
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,37 @@ fn simple() {
.run();
}

#[test]
fn echo() {
Test::new()
.justfile(
"
@baz:
#!/bin/sh
echo fizz
",
)
.stdout("fizz\n")
.stderr("#!/bin/sh\necho fizz\n")
.run();
}

#[test]
fn echo_with_command_color() {
Test::new()
.justfile(
"
@baz:
#!/bin/sh
echo fizz
",
)
.args(["--color", "always", "--command-color", "purple"])
.stdout("fizz\n")
.stderr("\u{1b}[1;35m#!/bin/sh\u{1b}[0m\n\u{1b}[1;35mecho fizz\u{1b}[0m\n")
.run();
}

// This test exists to make sure that shebang recipes run correctly. Although
// this script is still executed by a shell its behavior depends on the value of
// a variable and continuing even though a command fails, whereas in plain
Expand Down