mirror of
https://github.com/ouch-org/ouch.git
synced 2025-06-08 04:25:31 +00:00
Change display of current directory (#119)
This commit is contained in:
parent
49a9740e42
commit
5f7d777342
@ -19,6 +19,7 @@ use crate::{
|
|||||||
CompressionFormat::{self, *},
|
CompressionFormat::{self, *},
|
||||||
},
|
},
|
||||||
info, oof,
|
info, oof,
|
||||||
|
utils::nice_directory_display,
|
||||||
utils::to_utf,
|
utils::to_utf,
|
||||||
utils::{self, dir_is_empty},
|
utils::{self, dir_is_empty},
|
||||||
Error,
|
Error,
|
||||||
@ -318,7 +319,7 @@ fn decompress_file(
|
|||||||
utils::create_dir_if_non_existent(output_folder)?;
|
utils::create_dir_if_non_existent(output_folder)?;
|
||||||
let zip_archive = zip::ZipArchive::new(reader)?;
|
let zip_archive = zip::ZipArchive::new(reader)?;
|
||||||
let _files = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?;
|
let _files = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?;
|
||||||
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
|
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -352,31 +353,31 @@ fn decompress_file(
|
|||||||
let mut writer = fs::File::create(&output_path)?;
|
let mut writer = fs::File::create(&output_path)?;
|
||||||
|
|
||||||
io::copy(&mut reader, &mut writer)?;
|
io::copy(&mut reader, &mut writer)?;
|
||||||
info!("Successfully decompressed archive in '{}'.", to_utf(output_path));
|
info!("Successfully decompressed archive in {}.", nice_directory_display(output_path));
|
||||||
}
|
}
|
||||||
Tar => {
|
Tar => {
|
||||||
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
||||||
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
|
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
|
||||||
}
|
}
|
||||||
Tgz => {
|
Tgz => {
|
||||||
let reader = chain_reader_decoder(&Gzip, reader)?;
|
let reader = chain_reader_decoder(&Gzip, reader)?;
|
||||||
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
||||||
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
|
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
|
||||||
}
|
}
|
||||||
Tbz => {
|
Tbz => {
|
||||||
let reader = chain_reader_decoder(&Bzip, reader)?;
|
let reader = chain_reader_decoder(&Bzip, reader)?;
|
||||||
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
||||||
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
|
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
|
||||||
}
|
}
|
||||||
Tlzma => {
|
Tlzma => {
|
||||||
let reader = chain_reader_decoder(&Lzma, reader)?;
|
let reader = chain_reader_decoder(&Lzma, reader)?;
|
||||||
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
||||||
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
|
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
|
||||||
}
|
}
|
||||||
Tzst => {
|
Tzst => {
|
||||||
let reader = chain_reader_decoder(&Zstd, reader)?;
|
let reader = chain_reader_decoder(&Zstd, reader)?;
|
||||||
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
let _ = crate::archive::tar::unpack_archive(reader, output_folder, flags)?;
|
||||||
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
|
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
|
||||||
}
|
}
|
||||||
Zip => {
|
Zip => {
|
||||||
eprintln!("Compressing first into .zip.");
|
eprintln!("Compressing first into .zip.");
|
||||||
@ -392,7 +393,7 @@ fn decompress_file(
|
|||||||
|
|
||||||
let _ = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?;
|
let _ = crate::archive::zip::unpack_archive(zip_archive, output_folder, flags)?;
|
||||||
|
|
||||||
info!("Successfully decompressed archive in '{}'.", to_utf(output_folder));
|
info!("Successfully decompressed archive in {}.", nice_directory_display(output_folder));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -55,6 +55,15 @@ pub fn to_utf(os_str: impl AsRef<OsStr>) -> String {
|
|||||||
text.trim_matches('"').to_string()
|
text.trim_matches('"').to_string()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
pub fn nice_directory_display(os_str: impl AsRef<OsStr>) -> String {
|
||||||
|
let text = to_utf(os_str);
|
||||||
|
if text == "." {
|
||||||
|
"current directory".to_string()
|
||||||
|
} else {
|
||||||
|
format!("'{}'", text)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
pub struct Bytes {
|
pub struct Bytes {
|
||||||
bytes: f64,
|
bytes: f64,
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user