writablesln!
This commit is contained in:
parent
a05af12352
commit
8cca5097d4
2 changed files with 22 additions and 33 deletions
|
@ -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.
|
/// The current version of fif, as defined in Cargo.toml.
|
||||||
const VERSION: Option<&'static str> = option_env!("CARGO_PKG_VERSION");
|
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<()> {
|
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<()> {
|
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<()> {
|
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<()> {
|
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<()> {
|
fn header<W: Write>(&self, f: &mut W, _: &Entries) -> io::Result<()> {
|
||||||
smart_write(
|
smart_write(
|
||||||
f,
|
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() {
|
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<()> {
|
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.
|
// there doesn't seem to be a way to rename the file, prompting only if the target already exists.
|
||||||
smart_write(
|
smart_write(
|
||||||
f,
|
f,
|
||||||
writables![
|
writablesln!["Rename-Item -Path ", from, " -NewName ", (to.file_name().unwrap())],
|
||||||
"Rename-Item -Path ",
|
|
||||||
from,
|
|
||||||
" -NewName ",
|
|
||||||
(to.file_name().unwrap()),
|
|
||||||
Newline
|
|
||||||
],
|
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,36 +266,23 @@ impl Format for PowerShell {
|
||||||
}
|
}
|
||||||
|
|
||||||
fn unknown_type<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
|
fn unknown_type<W: Write>(&self, f: &mut W, path: &Path) -> io::Result<()> {
|
||||||
smart_write(
|
smart_write(f, writablesln!["<# Failed to detect mime type for ", path, " #>"])
|
||||||
f,
|
|
||||||
writables!["<# Failed to detect mime type for ", path, " #>", Newline],
|
|
||||||
)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn header<W: Write>(&self, f: &mut W, _: &Entries) -> io::Result<()> {
|
fn header<W: Write>(&self, f: &mut W, _: &Entries) -> io::Result<()> {
|
||||||
smart_write(
|
smart_write(
|
||||||
f,
|
f,
|
||||||
writables![
|
writablesln!["#!/usr/bin/env pwsh", Newline, "<# ", (generated_by().as_str()), " #>"],
|
||||||
"#!/usr/bin/env pwsh",
|
|
||||||
Newline,
|
|
||||||
"<# ",
|
|
||||||
(generated_by().as_str()),
|
|
||||||
" #>",
|
|
||||||
Newline
|
|
||||||
],
|
|
||||||
)?;
|
)?;
|
||||||
|
|
||||||
if let Ok(working_directory) = std::env::current_dir() {
|
if let Ok(working_directory) = std::env::current_dir() {
|
||||||
smart_write(
|
smart_write(f, writablesln!["<# Run from ", (working_directory.as_path()), " #>"])?;
|
||||||
f,
|
|
||||||
writables!["<# Run from ", (working_directory.as_path()), " #>", Newline],
|
|
||||||
)?;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
smart_write(f, writables![Newline])
|
smart_write(f, writables![Newline])
|
||||||
}
|
}
|
||||||
|
|
||||||
fn footer<W: Write>(&self, f: &mut W, _: &Entries) -> io::Result<()> {
|
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!'"])
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -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() {
|
fn init_db() {
|
||||||
cfg_if! {
|
cfg_if! {
|
||||||
if #[cfg(any(all(unix, feature = "infer-backend"), all(not(unix), not(feature = "xdg-mime-backend"))))] {
|
if #[cfg(any(all(unix, feature = "infer-backend"), all(not(unix), not(feature = "xdg-mime-backend"))))] {
|
||||||
|
|
Loading…
Reference in a new issue