mirror of
https://github.com/nushell/nushell
synced 2025-01-13 05:38:57 +00:00
Merge branch 'master' of https://github.com/nushell/nushell
This commit is contained in:
commit
c69bf9f46f
9 changed files with 56 additions and 42 deletions
5
Cargo.lock
generated
5
Cargo.lock
generated
|
@ -1911,7 +1911,7 @@ dependencies = [
|
||||||
|
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "nu"
|
name = "nu"
|
||||||
version = "0.7.1"
|
version = "0.7.2"
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"ansi_term 0.12.1",
|
"ansi_term 0.12.1",
|
||||||
"app_dirs",
|
"app_dirs",
|
||||||
|
@ -2973,8 +2973,7 @@ dependencies = [
|
||||||
[[package]]
|
[[package]]
|
||||||
name = "rustyline"
|
name = "rustyline"
|
||||||
version = "5.0.5"
|
version = "5.0.5"
|
||||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
source = "git+https://github.com/kkawakam/rustyline.git#55dcab54fbab0ba0610799291276785e5b31199c"
|
||||||
checksum = "3ae156e2a68be20a3ae95574089b65c188d86291cd5421cc647222b8d1864ffb"
|
|
||||||
dependencies = [
|
dependencies = [
|
||||||
"cfg-if",
|
"cfg-if",
|
||||||
"dirs 2.0.2",
|
"dirs 2.0.2",
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
[package]
|
[package]
|
||||||
name = "nu"
|
name = "nu"
|
||||||
version = "0.7.1"
|
version = "0.7.2"
|
||||||
authors = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
authors = ["Yehuda Katz <wycats@gmail.com>", "Jonathan Turner <jonathan.d.turner@gmail.com>", "Andrés N. Robalino <andres@androbtech.com>"]
|
||||||
description = "A shell for the GitHub era"
|
description = "A shell for the GitHub era"
|
||||||
license = "MIT"
|
license = "MIT"
|
||||||
|
@ -60,7 +60,7 @@ nu-macros = { version = "0.7.0", path = "./crates/nu-macros" }
|
||||||
|
|
||||||
query_interface = "0.3.5"
|
query_interface = "0.3.5"
|
||||||
typetag = "0.1.4"
|
typetag = "0.1.4"
|
||||||
rustyline = "5.0.4"
|
rustyline = { git = "https://github.com/kkawakam/rustyline.git" }
|
||||||
chrono = { version = "0.4.10", features = ["serde"] }
|
chrono = { version = "0.4.10", features = ["serde"] }
|
||||||
derive-new = "0.5.8"
|
derive-new = "0.5.8"
|
||||||
prettytable-rs = "0.8.0"
|
prettytable-rs = "0.8.0"
|
||||||
|
|
|
@ -113,7 +113,7 @@ pub fn format_primitive(primitive: &Primitive, field_name: Option<&String>) -> S
|
||||||
}
|
}
|
||||||
Primitive::Duration(sec) => format_duration(*sec),
|
Primitive::Duration(sec) => format_duration(*sec),
|
||||||
Primitive::Int(i) => i.to_string(),
|
Primitive::Int(i) => i.to_string(),
|
||||||
Primitive::Decimal(decimal) => decimal.to_string(),
|
Primitive::Decimal(decimal) => format!("{:.4}", decimal),
|
||||||
Primitive::Range(range) => format!(
|
Primitive::Range(range) => format!(
|
||||||
"{}..{}",
|
"{}..{}",
|
||||||
format_primitive(&range.from.0.item, None),
|
format_primitive(&range.from.0.item, None),
|
||||||
|
|
|
@ -3,7 +3,7 @@ use futures::executor::block_on;
|
||||||
|
|
||||||
use futures_util::{StreamExt, TryStreamExt};
|
use futures_util::{StreamExt, TryStreamExt};
|
||||||
use heim::process::{self as process, Process, ProcessResult};
|
use heim::process::{self as process, Process, ProcessResult};
|
||||||
use heim::units::{ratio, Ratio};
|
use heim::units::{information, ratio, Ratio};
|
||||||
use std::usize;
|
use std::usize;
|
||||||
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
|
@ -22,12 +22,14 @@ impl Ps {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio)> {
|
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, process::Memory)> {
|
||||||
let usage_1 = process.cpu_usage().await?;
|
let usage_1 = process.cpu_usage().await?;
|
||||||
futures_timer::Delay::new(Duration::from_millis(100)).await;
|
futures_timer::Delay::new(Duration::from_millis(100)).await;
|
||||||
let usage_2 = process.cpu_usage().await?;
|
let usage_2 = process.cpu_usage().await?;
|
||||||
|
|
||||||
Ok((process, usage_2 - usage_1))
|
let memory = process.memory().await?;
|
||||||
|
|
||||||
|
Ok((process, usage_2 - usage_1, memory))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ps(tag: Tag) -> Vec<Value> {
|
async fn ps(tag: Tag) -> Vec<Value> {
|
||||||
|
@ -43,7 +45,7 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||||
|
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
while let Some(res) = processes.next().await {
|
while let Some(res) = processes.next().await {
|
||||||
if let Ok((process, usage)) = res {
|
if let Ok((process, usage, memory)) = res {
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
|
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
|
||||||
if let Ok(name) = process.name().await {
|
if let Ok(name) = process.name().await {
|
||||||
|
@ -53,6 +55,14 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||||
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
|
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
|
||||||
}
|
}
|
||||||
dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::<ratio::percent>()));
|
dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::<ratio::percent>()));
|
||||||
|
dict.insert_untagged(
|
||||||
|
"mem",
|
||||||
|
UntaggedValue::bytes(memory.rss().get::<information::byte>()),
|
||||||
|
);
|
||||||
|
dict.insert_untagged(
|
||||||
|
"virtual",
|
||||||
|
UntaggedValue::bytes(memory.vms().get::<information::byte>()),
|
||||||
|
);
|
||||||
output.push(dict.into_value());
|
output.push(dict.into_value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -170,29 +170,17 @@ pub(crate) async fn run_external_command(
|
||||||
|
|
||||||
let name_tag = command.name_tag.clone();
|
let name_tag = command.name_tag.clone();
|
||||||
if let Ok(mut popen) = popen {
|
if let Ok(mut popen) = popen {
|
||||||
|
popen.detach();
|
||||||
match stream_next {
|
match stream_next {
|
||||||
StreamNext::Last => {
|
StreamNext::Last => {
|
||||||
popen.detach();
|
let _ = popen.wait();
|
||||||
loop {
|
|
||||||
match popen.poll() {
|
|
||||||
None => {
|
|
||||||
std::thread::sleep(std::time::Duration::new(0, 100_000_000));
|
|
||||||
}
|
|
||||||
_ => {
|
|
||||||
let _ = popen.terminate();
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
Ok(ClassifiedInputStream::new())
|
Ok(ClassifiedInputStream::new())
|
||||||
}
|
}
|
||||||
StreamNext::External => {
|
StreamNext::External => {
|
||||||
popen.detach();
|
|
||||||
let stdout = popen.stdout.take().unwrap();
|
let stdout = popen.stdout.take().unwrap();
|
||||||
Ok(ClassifiedInputStream::from_stdout(stdout))
|
Ok(ClassifiedInputStream::from_stdout(stdout))
|
||||||
}
|
}
|
||||||
StreamNext::Internal => {
|
StreamNext::Internal => {
|
||||||
popen.detach();
|
|
||||||
let stdout = popen.stdout.take().unwrap();
|
let stdout = popen.stdout.take().unwrap();
|
||||||
let file = futures::io::AllowStdIo::new(stdout);
|
let file = futures::io::AllowStdIo::new(stdout);
|
||||||
let stream = Framed::new(file, LinesCodec {});
|
let stream = Framed::new(file, LinesCodec {});
|
||||||
|
|
|
@ -505,11 +505,14 @@ impl Command {
|
||||||
let call_info = raw_args
|
let call_info = raw_args
|
||||||
.clone()
|
.clone()
|
||||||
.call_info
|
.call_info
|
||||||
.evaluate(®istry, &Scope::it_value(x.clone()))
|
.evaluate(®istry, &Scope::it_value(x.clone()));
|
||||||
.unwrap();
|
|
||||||
match command.run(&call_info, ®istry, &raw_args, x) {
|
match call_info {
|
||||||
|
Ok(call_info) => match command.run(&call_info, ®istry, &raw_args, x) {
|
||||||
Ok(o) => o,
|
Ok(o) => o,
|
||||||
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]).to_output_stream(),
|
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]).to_output_stream(),
|
||||||
|
},
|
||||||
|
Err(e) => VecDeque::from(vec![ReturnValue::Err(e)]).to_output_stream(),
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
.flatten();
|
.flatten();
|
||||||
|
|
|
@ -140,7 +140,9 @@ impl PrettyDebug for FormatInlineShape {
|
||||||
match &self.shape {
|
match &self.shape {
|
||||||
InlineShape::Nothing => b::blank(),
|
InlineShape::Nothing => b::blank(),
|
||||||
InlineShape::Int(int) => b::primitive(format!("{}", int)),
|
InlineShape::Int(int) => b::primitive(format!("{}", int)),
|
||||||
InlineShape::Decimal(decimal) => b::primitive(format!("{}", decimal)),
|
InlineShape::Decimal(decimal) => {
|
||||||
|
b::description(format_primitive(&Primitive::Decimal(decimal.clone()), None))
|
||||||
|
}
|
||||||
InlineShape::Range(range) => {
|
InlineShape::Range(range) => {
|
||||||
let (left, left_inclusion) = &range.from;
|
let (left, left_inclusion) = &range.from;
|
||||||
let (right, right_inclusion) = &range.to;
|
let (right, right_inclusion) = &range.to;
|
||||||
|
|
|
@ -166,20 +166,20 @@ fn evaluate_reference(
|
||||||
match name {
|
match name {
|
||||||
hir::Variable::It(_) => Ok(scope.it.value.clone().into_value(tag)),
|
hir::Variable::It(_) => Ok(scope.it.value.clone().into_value(tag)),
|
||||||
hir::Variable::Other(inner) => match inner.slice(source) {
|
hir::Variable::Other(inner) => match inner.slice(source) {
|
||||||
x if x == "nu:env" => {
|
x if x == "nu" => {
|
||||||
|
let mut nu_dict = TaggedDictBuilder::new(&tag);
|
||||||
|
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
for v in std::env::vars() {
|
for v in std::env::vars() {
|
||||||
if v.0 != "PATH" && v.0 != "Path" {
|
if v.0 != "PATH" && v.0 != "Path" {
|
||||||
dict.insert_untagged(v.0, UntaggedValue::string(v.1));
|
dict.insert_untagged(v.0, UntaggedValue::string(v.1));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(dict.into_value())
|
nu_dict.insert_value("env", dict.into_value());
|
||||||
}
|
|
||||||
x if x == "nu:config" => {
|
let config = crate::data::config::read(&tag, &None)?;
|
||||||
let config = crate::data::config::read(tag.clone(), &None)?;
|
nu_dict.insert_value("config", UntaggedValue::row(config).into_value(&tag));
|
||||||
Ok(UntaggedValue::row(config).into_value(tag))
|
|
||||||
}
|
|
||||||
x if x == "nu:path" => {
|
|
||||||
let mut table = vec![];
|
let mut table = vec![];
|
||||||
let path = std::env::var_os("PATH");
|
let path = std::env::var_os("PATH");
|
||||||
if let Some(paths) = path {
|
if let Some(paths) = path {
|
||||||
|
@ -187,7 +187,9 @@ fn evaluate_reference(
|
||||||
table.push(UntaggedValue::path(path).into_value(&tag));
|
table.push(UntaggedValue::path(path).into_value(&tag));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Ok(UntaggedValue::table(&table).into_value(tag))
|
nu_dict.insert_value("path", UntaggedValue::table(&table).into_value(&tag));
|
||||||
|
|
||||||
|
Ok(nu_dict.into_value())
|
||||||
}
|
}
|
||||||
x => Ok(scope
|
x => Ok(scope
|
||||||
.vars
|
.vars
|
||||||
|
|
|
@ -3,7 +3,7 @@ use futures::executor::block_on;
|
||||||
|
|
||||||
use futures_util::{StreamExt, TryStreamExt};
|
use futures_util::{StreamExt, TryStreamExt};
|
||||||
use heim::process::{self as process, Process, ProcessResult};
|
use heim::process::{self as process, Process, ProcessResult};
|
||||||
use heim::units::{ratio, Ratio};
|
use heim::units::{information, ratio, Ratio};
|
||||||
use std::usize;
|
use std::usize;
|
||||||
|
|
||||||
use nu_errors::ShellError;
|
use nu_errors::ShellError;
|
||||||
|
@ -22,12 +22,14 @@ impl Ps {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio)> {
|
async fn usage(process: Process) -> ProcessResult<(process::Process, Ratio, process::Memory)> {
|
||||||
let usage_1 = process.cpu_usage().await?;
|
let usage_1 = process.cpu_usage().await?;
|
||||||
futures_timer::Delay::new(Duration::from_millis(100)).await;
|
futures_timer::Delay::new(Duration::from_millis(100)).await;
|
||||||
let usage_2 = process.cpu_usage().await?;
|
let usage_2 = process.cpu_usage().await?;
|
||||||
|
|
||||||
Ok((process, usage_2 - usage_1))
|
let memory = process.memory().await?;
|
||||||
|
|
||||||
|
Ok((process, usage_2 - usage_1, memory))
|
||||||
}
|
}
|
||||||
|
|
||||||
async fn ps(tag: Tag) -> Vec<Value> {
|
async fn ps(tag: Tag) -> Vec<Value> {
|
||||||
|
@ -43,7 +45,7 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||||
|
|
||||||
let mut output = vec![];
|
let mut output = vec![];
|
||||||
while let Some(res) = processes.next().await {
|
while let Some(res) = processes.next().await {
|
||||||
if let Ok((process, usage)) = res {
|
if let Ok((process, usage, memory)) = res {
|
||||||
let mut dict = TaggedDictBuilder::new(&tag);
|
let mut dict = TaggedDictBuilder::new(&tag);
|
||||||
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
|
dict.insert_untagged("pid", UntaggedValue::int(process.pid()));
|
||||||
if let Ok(name) = process.name().await {
|
if let Ok(name) = process.name().await {
|
||||||
|
@ -53,6 +55,14 @@ async fn ps(tag: Tag) -> Vec<Value> {
|
||||||
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
|
dict.insert_untagged("status", UntaggedValue::string(format!("{:?}", status)));
|
||||||
}
|
}
|
||||||
dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::<ratio::percent>()));
|
dict.insert_untagged("cpu", UntaggedValue::decimal(usage.get::<ratio::percent>()));
|
||||||
|
dict.insert_untagged(
|
||||||
|
"mem",
|
||||||
|
UntaggedValue::bytes(memory.rss().get::<information::byte>()),
|
||||||
|
);
|
||||||
|
dict.insert_untagged(
|
||||||
|
"virtual",
|
||||||
|
UntaggedValue::bytes(memory.vms().get::<information::byte>()),
|
||||||
|
);
|
||||||
output.push(dict.into_value());
|
output.push(dict.into_value());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue