diff --git a/build_tools/style.fish b/build_tools/style.fish index 721a1fb98..e3da235ae 100755 --- a/build_tools/style.fish +++ b/build_tools/style.fish @@ -95,16 +95,7 @@ if set -q fish_files[1] set PATH . $PATH end echo === Running "$green"fish_indent"$normal" - for file in $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 + fish_indent -w -- $fish_files end if set -q python_files[1] diff --git a/sphinx_doc_src/cmds/fish_indent.rst b/sphinx_doc_src/cmds/fish_indent.rst index 081265f87..f5f7cdc0e 100644 --- a/sphinx_doc_src/cmds/fish_indent.rst +++ b/sphinx_doc_src/cmds/fish_indent.rst @@ -6,13 +6,13 @@ fish_indent - indenter and prettifier Synopsis -------- -fish_indent [OPTIONS] +fish_indent [OPTIONS] [FILE...] 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: diff --git a/src/fish_indent.cpp b/src/fish_indent.cpp index df3ac1e14..29f3334ef 100644 --- a/src/fish_indent.cpp +++ b/src/fish_indent.cpp @@ -629,69 +629,67 @@ int main(int argc, char *argv[]) { exit(1); } 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 { - std::fwprintf(stderr, _(L"Too many arguments\n")); - exit(1); - } - - 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 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"); + ret = EXIT_SUCCESS; + for (int i; i < argc; i++) { + FILE *fh = fopen(argv[i], "r"); if (fh) { - std::fputws(output_wtext.c_str(), fh); + src = read_file(fh); fclose(fh); - exit(0); + output_location = argv[i]; } else { - std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), output_location, - std::strerror(errno)); + std::fwprintf(stderr, _(L"Opening \"%s\" failed: %s\n"), *argv, 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; + + if (output_type == output_type_pygments_csv) { + std::string output = make_pygments_csv(src); + fputs(output.c_str(), stdout); + } + + const wcstring output_wtext = prettify(src, do_indent); + + // Maybe colorize. + std::vector 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) { + 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); } } - - std::fputws(str2wcstring(colored_output).c_str(), stdout); - return ret; + return 0; }