mirror of
https://github.com/fish-shell/fish-shell
synced 2024-12-28 13:53:10 +00:00
fish_indent: Allow multiple file arguments
Allows `fish_indent -w **.fish` to restyle all fish files under the current directory. (This also has the sideeffect of reducing style.fish time by ~10s, as we only need to invoke `fish_indent` once, instead of once per-file)
This commit is contained in:
parent
8e640cdcc5
commit
c2b7e9b2e6
3 changed files with 58 additions and 69 deletions
|
@ -95,16 +95,7 @@ if set -q fish_files[1]
|
||||||
set PATH . $PATH
|
set PATH . $PATH
|
||||||
end
|
end
|
||||||
echo === Running "$green"fish_indent"$normal"
|
echo === Running "$green"fish_indent"$normal"
|
||||||
for file in $fish_files
|
fish_indent -w -- $fish_files
|
||||||
cp $file $file.new # preserves mode bits
|
|
||||||
fish_indent <$file >$file.new
|
|
||||||
if cmp --quiet $file $file.new
|
|
||||||
rm $file.new
|
|
||||||
else
|
|
||||||
echo $file was NOT correctly formatted
|
|
||||||
mv $file.new $file
|
|
||||||
end
|
|
||||||
end
|
|
||||||
end
|
end
|
||||||
|
|
||||||
if set -q python_files[1]
|
if set -q python_files[1]
|
||||||
|
|
|
@ -6,13 +6,13 @@ fish_indent - indenter and prettifier
|
||||||
Synopsis
|
Synopsis
|
||||||
--------
|
--------
|
||||||
|
|
||||||
fish_indent [OPTIONS]
|
fish_indent [OPTIONS] [FILE...]
|
||||||
|
|
||||||
|
|
||||||
Description
|
Description
|
||||||
-----------
|
-----------
|
||||||
|
|
||||||
``fish_indent`` is used to indent a piece of fish code. ``fish_indent`` reads commands from standard input and outputs them to standard output or a specified file.
|
``fish_indent`` is used to indent a piece of fish code. ``fish_indent`` reads commands from standard input or the given filenames and outputs them to standard output or a specified file (if `-w` is given).
|
||||||
|
|
||||||
The following options are available:
|
The following options are available:
|
||||||
|
|
||||||
|
|
|
@ -629,69 +629,67 @@ int main(int argc, char *argv[]) {
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
src = read_file(stdin);
|
src = read_file(stdin);
|
||||||
} else if (argc == 1) {
|
|
||||||
FILE *fh = fopen(*argv, "r");
|
|
||||||
if (fh) {
|
|
||||||
src = read_file(fh);
|
|
||||||
fclose(fh);
|
|
||||||
output_location = *argv;
|
|
||||||
} else {
|
|
||||||
std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), *argv, std::strerror(errno));
|
|
||||||
exit(1);
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
std::fwprintf(stderr, _(L"Too many arguments\n"));
|
ret = EXIT_SUCCESS;
|
||||||
exit(1);
|
for (int i; i < argc; i++) {
|
||||||
}
|
FILE *fh = fopen(argv[i], "r");
|
||||||
|
|
||||||
if (output_type == output_type_pygments_csv) {
|
|
||||||
std::string output = make_pygments_csv(src);
|
|
||||||
fputs(output.c_str(), stdout);
|
|
||||||
return EXIT_SUCCESS;
|
|
||||||
}
|
|
||||||
|
|
||||||
const wcstring output_wtext = prettify(src, do_indent);
|
|
||||||
|
|
||||||
// Maybe colorize.
|
|
||||||
std::vector<highlight_spec_t> colors;
|
|
||||||
if (output_type != output_type_plain_text) {
|
|
||||||
highlight_shell_no_io(output_wtext, colors, output_wtext.size(), NULL,
|
|
||||||
env_stack_t::globals());
|
|
||||||
}
|
|
||||||
|
|
||||||
std::string colored_output;
|
|
||||||
switch (output_type) {
|
|
||||||
case output_type_plain_text: {
|
|
||||||
colored_output = no_colorize(output_wtext);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
case output_type_file: {
|
|
||||||
FILE *fh = fopen(output_location, "w");
|
|
||||||
if (fh) {
|
if (fh) {
|
||||||
std::fputws(output_wtext.c_str(), fh);
|
src = read_file(fh);
|
||||||
fclose(fh);
|
fclose(fh);
|
||||||
exit(0);
|
output_location = argv[i];
|
||||||
} else {
|
} else {
|
||||||
std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), output_location,
|
std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), *argv, std::strerror(errno));
|
||||||
std::strerror(errno));
|
|
||||||
exit(1);
|
exit(1);
|
||||||
}
|
}
|
||||||
break;
|
|
||||||
}
|
if (output_type == output_type_pygments_csv) {
|
||||||
case output_type_ansi: {
|
std::string output = make_pygments_csv(src);
|
||||||
colored_output = ansi_colorize(output_wtext, colors);
|
fputs(output.c_str(), stdout);
|
||||||
break;
|
}
|
||||||
}
|
|
||||||
case output_type_html: {
|
const wcstring output_wtext = prettify(src, do_indent);
|
||||||
colored_output = html_colorize(output_wtext, colors);
|
|
||||||
break;
|
// Maybe colorize.
|
||||||
}
|
std::vector<highlight_spec_t> colors;
|
||||||
case output_type_pygments_csv: {
|
if (output_type != output_type_plain_text) {
|
||||||
DIE("pygments_csv should have been handled above");
|
highlight_shell_no_io(output_wtext, colors, output_wtext.size(), NULL,
|
||||||
break;
|
env_stack_t::globals());
|
||||||
|
}
|
||||||
|
|
||||||
|
std::string colored_output;
|
||||||
|
switch (output_type) {
|
||||||
|
case output_type_plain_text: {
|
||||||
|
colored_output = no_colorize(output_wtext);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case output_type_file: {
|
||||||
|
FILE *fh = fopen(output_location, "w");
|
||||||
|
if (fh) {
|
||||||
|
std::fputws(output_wtext.c_str(), fh);
|
||||||
|
fclose(fh);
|
||||||
|
} else {
|
||||||
|
std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), output_location,
|
||||||
|
std::strerror(errno));
|
||||||
|
exit(1);
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case output_type_ansi: {
|
||||||
|
colored_output = ansi_colorize(output_wtext, colors);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case output_type_html: {
|
||||||
|
colored_output = html_colorize(output_wtext, colors);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
case output_type_pygments_csv: {
|
||||||
|
DIE("pygments_csv should have been handled above");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
std::fputws(str2wcstring(colored_output).c_str(), stdout);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0;
|
||||||
std::fputws(str2wcstring(colored_output).c_str(), stdout);
|
|
||||||
return ret;
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue