mirror of
https://github.com/nushell/nushell.git
synced 2025-08-17 18:41:53 +02:00
A few ls improvements. New welcome message (#1195)
This commit is contained in:
@ -24,11 +24,11 @@ impl WholeStreamCommand for Version {
|
||||
args: CommandArgs,
|
||||
registry: &CommandRegistry,
|
||||
) -> Result<OutputStream, ShellError> {
|
||||
date(args, registry)
|
||||
version(args, registry)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn date(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||
pub fn version(args: CommandArgs, registry: &CommandRegistry) -> Result<OutputStream, ShellError> {
|
||||
let args = args.evaluate_once(registry)?;
|
||||
let tag = args.call_info.name_tag.clone();
|
||||
|
||||
|
@ -1,6 +1,5 @@
|
||||
use crate::prelude::*;
|
||||
use chrono::{DateTime, Utc};
|
||||
use chrono_humanize::Humanize;
|
||||
use indexmap::IndexMap;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::RangeInclusion;
|
||||
@ -188,7 +187,7 @@ impl PrettyDebug for FormatInlineShape {
|
||||
}
|
||||
.to_owned(),
|
||||
),
|
||||
InlineShape::Date(date) => b::primitive(date.humanize()),
|
||||
InlineShape::Date(date) => b::primitive(nu_protocol::format_date(date)),
|
||||
InlineShape::Duration(duration) => {
|
||||
b::description(format_primitive(&Primitive::Duration(*duration), None))
|
||||
}
|
||||
|
@ -2,13 +2,6 @@ use crate::prelude::*;
|
||||
use nu_errors::ShellError;
|
||||
use nu_protocol::{TaggedDictBuilder, UntaggedValue, Value};
|
||||
|
||||
#[derive(Debug)]
|
||||
pub enum FileType {
|
||||
Directory,
|
||||
File,
|
||||
Symlink,
|
||||
}
|
||||
|
||||
pub(crate) fn dir_entry_dict(
|
||||
filename: &std::path::Path,
|
||||
metadata: &std::fs::Metadata,
|
||||
@ -18,16 +11,14 @@ pub(crate) fn dir_entry_dict(
|
||||
let mut dict = TaggedDictBuilder::new(tag);
|
||||
dict.insert_untagged("name", UntaggedValue::string(filename.to_string_lossy()));
|
||||
|
||||
let kind = if metadata.is_dir() {
|
||||
FileType::Directory
|
||||
if metadata.is_dir() {
|
||||
dict.insert_untagged("type", UntaggedValue::string("Dir"));
|
||||
} else if metadata.is_file() {
|
||||
FileType::File
|
||||
dict.insert_untagged("type", UntaggedValue::string("File"));
|
||||
} else {
|
||||
FileType::Symlink
|
||||
dict.insert_untagged("type", UntaggedValue::string("Symlink"));
|
||||
};
|
||||
|
||||
dict.insert_untagged("type", UntaggedValue::string(format!("{:?}", kind)));
|
||||
|
||||
if full {
|
||||
dict.insert_untagged(
|
||||
"readonly",
|
||||
@ -36,23 +27,37 @@ pub(crate) fn dir_entry_dict(
|
||||
|
||||
#[cfg(unix)]
|
||||
{
|
||||
use std::os::unix::fs::MetadataExt;
|
||||
use std::os::unix::fs::PermissionsExt;
|
||||
let mode = metadata.permissions().mode();
|
||||
dict.insert_untagged(
|
||||
"mode",
|
||||
UntaggedValue::string(umask::Mode::from(mode).to_string()),
|
||||
);
|
||||
|
||||
if let Some(user) = users::get_user_by_uid(metadata.uid()) {
|
||||
dict.insert_untagged("uid", UntaggedValue::string(user.name().to_string_lossy()));
|
||||
}
|
||||
|
||||
if let Some(group) = users::get_group_by_gid(metadata.gid()) {
|
||||
dict.insert_untagged(
|
||||
"group",
|
||||
UntaggedValue::string(group.name().to_string_lossy()),
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
dict.insert_untagged("size", UntaggedValue::bytes(metadata.len() as u64));
|
||||
|
||||
if let Ok(c) = metadata.created() {
|
||||
dict.insert_untagged("created", UntaggedValue::system_date(c));
|
||||
}
|
||||
if full {
|
||||
if let Ok(c) = metadata.created() {
|
||||
dict.insert_untagged("created", UntaggedValue::system_date(c));
|
||||
}
|
||||
|
||||
if let Ok(a) = metadata.accessed() {
|
||||
dict.insert_untagged("accessed", UntaggedValue::system_date(a));
|
||||
if let Ok(a) = metadata.accessed() {
|
||||
dict.insert_untagged("accessed", UntaggedValue::system_date(a));
|
||||
}
|
||||
}
|
||||
|
||||
if let Ok(m) = metadata.modified() {
|
||||
|
@ -65,6 +65,10 @@ fn main() -> Result<(), Box<dyn Error>> {
|
||||
|
||||
builder.try_init()?;
|
||||
|
||||
println!(
|
||||
"Welcome to Nushell {} (type 'help' for more info)",
|
||||
clap::crate_version!()
|
||||
);
|
||||
futures::executor::block_on(nu::cli())?;
|
||||
Ok(())
|
||||
}
|
||||
|
Reference in New Issue
Block a user