diff --git a/src/formats.rs b/src/formats.rs index c9ffd4b..96002a1 100644 --- a/src/formats.rs +++ b/src/formats.rs @@ -41,6 +41,14 @@ macro_rules! writables { } } +#[macro_export] +/// Does the same thing as [writables], but adds a Newline to the end. +macro_rules! writablesln { + [$($args:tt),+] => { + &[$(writables!(@do $args),)* writables!(@do Newline)] + }; +} + /// The current version of fif, as defined in Cargo.toml. const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION"); @@ -183,36 +191,36 @@ impl Format for Shell { } fn rename(&self, f: &mut W, from: &Path, to: &Path) -> io::Result<()> { - smart_write(f, writables!("mv -v -i -- ", from, Space, to, Newline)) + smart_write(f, writablesln!("mv -v -i -- ", from, Space, to)) } fn no_known_extension(&self, f: &mut W, path: &Path) -> io::Result<()> { - smart_write(f, writables!["echo No known extension for ", path, Newline]) + smart_write(f, writablesln!["echo No known extension for ", path]) } fn unreadable(&self, f: &mut W, path: &Path) -> io::Result<()> { - smart_write(f, writables!["# Failed to read", path, Newline]) + smart_write(f, writablesln!["# Failed to read", path]) } fn unknown_type(&self, f: &mut W, path: &Path) -> io::Result<()> { - smart_write(f, writables!["# Failed to detect mime type for ", path, Newline]) + smart_write(f, writablesln!["# Failed to detect mime type for ", path]) } fn header(&self, f: &mut W, _: &Entries) -> io::Result<()> { smart_write( f, - writables!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str()), Newline], + writablesln!["#!/usr/bin/env sh", Newline, "# ", (generated_by().as_str())], )?; if let Ok(working_directory) = std::env::current_dir() { - smart_write(f, writables!["# Run from ", (working_directory.as_path()), Newline])?; + smart_write(f, writablesln!["# Run from ", (working_directory.as_path())])?; } - smart_write(f, writables![Newline, "set -e", Newline, Newline]) + smart_write(f, writablesln![Newline, "set -e", Newline]) } fn footer(&self, f: &mut W, _: &Entries) -> io::Result<()> { - smart_write(f, writables![Newline, "echo 'Done.'", Newline]) + smart_write(f, writablesln![Newline, "echo 'Done.'"]) } } @@ -232,13 +240,7 @@ impl Format for PowerShell { // there doesn't seem to be a way to rename the file, prompting only if the target already exists. smart_write( f, - writables![ - "Rename-Item -Path ", - from, - " -NewName ", - (to.file_name().unwrap()), - Newline - ], + writablesln!["Rename-Item -Path ", from, " -NewName ", (to.file_name().unwrap())], ) } @@ -264,36 +266,23 @@ impl Format for PowerShell { } fn unknown_type(&self, f: &mut W, path: &Path) -> io::Result<()> { - smart_write( - f, - writables!["<# Failed to detect mime type for ", path, " #>", Newline], - ) + smart_write(f, writablesln!["<# Failed to detect mime type for ", path, " #>"]) } fn header(&self, f: &mut W, _: &Entries) -> io::Result<()> { smart_write( f, - writables![ - "#!/usr/bin/env pwsh", - Newline, - "<# ", - (generated_by().as_str()), - " #>", - Newline - ], + writablesln!["#!/usr/bin/env pwsh", Newline, "<# ", (generated_by().as_str()), " #>"], )?; if let Ok(working_directory) = std::env::current_dir() { - smart_write( - f, - writables!["<# Run from ", (working_directory.as_path()), " #>", Newline], - )?; + smart_write(f, writablesln!["<# Run from ", (working_directory.as_path()), " #>"])?; } smart_write(f, writables![Newline]) } fn footer(&self, f: &mut W, _: &Entries) -> io::Result<()> { - smart_write(f, writables![Newline, "Write-Output 'Done!'", Newline]) + smart_write(f, writablesln![Newline, "Write-Output 'Done!'"]) } } diff --git a/src/main.rs b/src/main.rs index 3deb4f1..2a07ded 100644 --- a/src/main.rs +++ b/src/main.rs @@ -348,7 +348,7 @@ fn scan_directory( } } -/// Initialises [MIMEDB] with a value dependent on the current backend. +/// Initialises [`MIMEDB`] with a value dependent on the current backend. fn init_db() { cfg_if! { if #[cfg(any(all(unix, feature = "infer-backend"), all(not(unix), not(feature = "xdg-mime-backend"))))] {