writablesln!

This commit is contained in:
Lynne Megido 2021-04-28 21:39:56 +10:00
parent a05af12352
commit 8cca5097d4
Signed by: lynnesbian
GPG key ID: F0A184B5213D9F90
2 changed files with 22 additions and 33 deletions

View file

@ -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<W: Write>(&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<W: Write>(&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<W: Write>(&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<W: Write>(&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<W: Write>(&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<W: Write>(&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<W: Write>(&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<W: Write>(&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<W: Write>(&self, f: &mut W, _: &Entries) -> io::Result<()> {
smart_write(f, writables![Newline, "Write-Output 'Done!'", Newline])
smart_write(f, writablesln![Newline, "Write-Output 'Done!'"])
}
}

View file

@ -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"))))] {