diff --git a/CHANGELOG.md b/CHANGELOG.md index bcd111b..8f39ec5 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,8 +1,8 @@ # Changelog Dates are given in YYYY-MM-DD format. -## v0.2 -### v0.2.14 (2021-xx-yy) +## v0.3 +### v0.3.0 (2021-xx-yy) #### Features - Added `-x`/`--exclude` flag for excluding file extensions (overrides `-e` or `-E` - `-E images -x jpg` scans all image files, except ".jpg" files) @@ -12,11 +12,13 @@ Dates are given in YYYY-MM-DD format. - `-e` and `-E` no longer conflict with each other, and can now be used together. For example, `-E images -e mp3` will scan all images *and* all MP3 files - It is now possible to specify multiple extension sets at once: `-E images,system` will scan all images and archives +- fif's output now includes the directory it was run from #### Other - Published my fork of ['mime_guess'] as ['new_mime_guess'], allowing it to be used properly with [crates.io](https://crates.io) - The `videos` extension set has been renamed to `video`, in line with `audio`. `fif --help` has actually mistakenly referred to the set as `video` since v0.2.12! 0uo +- CI has been vastly improved ### v0.2.13 (2021-04-26) #### Features diff --git a/src/formats.rs b/src/formats.rs index b57fab7..c9ffd4b 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -130,12 +130,12 @@ pub trait Format { fn no_known_extension(&self, f: &mut W, path: &Path) -> io::Result<()>; fn unreadable(&self, f: &mut W, path: &Path) -> io::Result<()>; fn unknown_type(&self, f: &mut W, path: &Path) -> io::Result<()>; - fn header(&self, entries: &Entries, f: &mut W) -> io::Result<()>; - fn footer(&self, entries: &Entries, f: &mut W) -> io::Result<()>; + fn header(&self, f: &mut W, entries: &Entries) -> io::Result<()>; + fn footer(&self, f: &mut W, entries: &Entries) -> io::Result<()>; - fn write_all(&self, entries: &Entries, f: &mut W) -> io::Result<()> { + fn write_all(&self, f: &mut W, entries: &Entries) -> io::Result<()> { // TODO: clean this up - it's kinda messy - self.header(entries, f)?; + self.header(f, entries)?; // output will be generated in the order: // - files that couldn't be read @@ -170,7 +170,7 @@ pub trait Format { } } - self.footer(entries, f) + self.footer(f, entries) } } @@ -198,22 +198,20 @@ impl Format for Shell { smart_write(f, writables!["# Failed to detect mime type for ", path, Newline]) } - fn header(&self, _: &Entries, f: &mut W) -> io::Result<()> { + fn header(&self, f: &mut W, _: &Entries) -> io::Result<()> { smart_write( f, - writables![ - "#!/usr/bin/env sh", - Newline, - "# ", - (generated_by().as_str()), - Newline, - "set -e", - Newline - ], - ) + writables!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str()), Newline], + )?; + + if let Ok(working_directory) = std::env::current_dir() { + smart_write(f, writables!["# Run from ", (working_directory.as_path()), Newline])?; + } + + smart_write(f, writables![Newline, "set -e", Newline, Newline]) } - fn footer(&self, _: &Entries, f: &mut W) -> io::Result<()> { + fn footer(&self, f: &mut W, _: &Entries) -> io::Result<()> { smart_write(f, writables![Newline, "echo 'Done.'", Newline]) } } @@ -272,7 +270,7 @@ impl Format for PowerShell { ) } - fn header(&self, _: &Entries, f: &mut W) -> io::Result<()> { + fn header(&self, f: &mut W, _: &Entries) -> io::Result<()> { smart_write( f, writables![ @@ -283,10 +281,19 @@ impl Format for PowerShell { " #>", Newline ], - ) + )?; + + if let Ok(working_directory) = std::env::current_dir() { + smart_write( + f, + writables!["<# Run from ", (working_directory.as_path()), " #>", Newline], + )?; + } + + smart_write(f, writables![Newline]) } - fn footer(&self, _: &Entries, f: &mut W) -> io::Result<()> { + fn footer(&self, f: &mut W, _: &Entries) -> io::Result<()> { smart_write(f, writables![Newline, "Write-Output 'Done!'", Newline]) } } diff --git a/src/inspectors.rs b/src/inspectors.rs index 35577ee..ecd4bb8 100644 --- a/src/inspectors.rs +++ b/src/inspectors.rs @@ -63,10 +63,10 @@ pub fn mime_type(db: &T, path: &Path) -> io::Result> { // TODO: avoid cloning mime if possible, although i don't really see how it would be - maybe instead of passing the mime // object, pass a hash of it? + cached! { MIMEXT; fn mime_extension_lookup(mime: Mime) -> Option> = { - // Returns a list of known extensions for this mime type, if any. // ↑ this is supposed to be a doc comment, but the cached! macro doesn't support that... maybe i should switch to // the derive macro diff --git a/src/main.rs b/src/main.rs index 1181b6b..3deb4f1 100644 --- a/src/main.rs +++ b/src/main.rs @@ -143,8 +143,8 @@ fn main() { let mut buffered_stdout = BufWriter::new(stdout()); let result = match args.output_format { - OutputFormat::Sh => Shell::new().write_all(&results, &mut buffered_stdout), - OutputFormat::PowerShell => PowerShell::new().write_all(&results, &mut buffered_stdout), + OutputFormat::Sh => Shell::new().write_all(&mut buffered_stdout, &results), + OutputFormat::PowerShell => PowerShell::new().write_all(&mut buffered_stdout, &results), OutputFormat::Text => todo!(), }; diff --git a/src/parameters.rs b/src/parameters.rs index 766117d..9f08c02 100644 --- a/src/parameters.rs +++ b/src/parameters.rs @@ -17,6 +17,7 @@ cfg_if! { #[derive(Clap, PartialEq, Debug)] pub enum OutputFormat { /// A Bourne shell compatible script. + #[clap(alias = "shell", alias = "bash")] Sh, /// A PowerShell script. #[clap(alias = "powershell")] @@ -229,7 +230,11 @@ impl ExtensionSet { "pdf", "doc", "docx", "ppt", "pptx", "xls", "xlsx", "csv", "tsv", "odt", "ods", "odp", "oda", "rtf", "ps", "pages", "key", "numbers", ], - Self::Text => [mime_guess::get_mime_extensions_str("text/*").unwrap(), &["js", "pl", "csh", "sh", "bash", "zsh", "fish", "bat", "php"]].concat(), + Self::Text => [ + mime_guess::get_mime_extensions_str("text/*").unwrap(), + &["js", "pl", "csh", "sh", "bash", "zsh", "fish", "bat", "php"], + ] + .concat(), // many compressed file types follow the name scheme "application/x.+compressed.*" - maybe this can be used // somehow to extract extensions for compressed files from mime_guess? Self::Archives => vec![ diff --git a/src/tests/mod.rs b/src/tests/mod.rs index 746165d..c97bc14 100644 --- a/src/tests/mod.rs +++ b/src/tests/mod.rs @@ -339,7 +339,7 @@ fn outputs_move_commands() { let mut contents = std::string::String::new(); Shell::new() - .write_all(&entries, &mut cursor) + .write_all(&mut cursor, &entries) .expect("Failed to write to cursor"); cursor.set_position(0); cursor