From e3e1d81f48579dc65cf528ae6655022b047cb619 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 2 Jun 2019 06:26:04 +1200 Subject: [PATCH 01/17] Add to_toml export --- src/cli.rs | 1 + src/commands.rs | 1 + src/commands/to_toml.rs | 9 +++++++++ src/object/desc.rs | 19 ++++++++++++++++++- src/object/dict.rs | 27 +++++++++++++++++++++++++-- 5 files changed, 54 insertions(+), 3 deletions(-) create mode 100644 src/commands/to_toml.rs diff --git a/src/cli.rs b/src/cli.rs index c5a4beac56..00a47b3944 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -60,6 +60,7 @@ pub async fn cli() -> Result<(), Box> { command("trim", trim::trim), command("to-array", to_array::to_array), command("to-json", to_json::to_json), + command("to-toml", to_toml::to_toml), Arc::new(Where), Arc::new(Config), command("sort-by", sort_by::sort_by), diff --git a/src/commands.rs b/src/commands.rs index fc3d915829..9aca425f7d 100644 --- a/src/commands.rs +++ b/src/commands.rs @@ -19,6 +19,7 @@ crate mod split_row; crate mod take; crate mod to_array; crate mod to_json; +crate mod to_toml; crate mod trim; crate mod view; crate mod where_; diff --git a/src/commands/to_toml.rs b/src/commands/to_toml.rs new file mode 100644 index 0000000000..ac0fe05a6d --- /dev/null +++ b/src/commands/to_toml.rs @@ -0,0 +1,9 @@ +use crate::object::{Primitive, Value}; +use crate::prelude::*; + +pub fn to_toml(args: CommandArgs) -> Result { + let out = args.input; + Ok(out + .map(|a| ReturnValue::Value(Value::Primitive(Primitive::String(toml::to_string(&a).unwrap())))) + .boxed()) +} diff --git a/src/object/desc.rs b/src/object/desc.rs index 4768262386..80d1ac4dc4 100644 --- a/src/object/desc.rs +++ b/src/object/desc.rs @@ -1,6 +1,7 @@ use crate::object::types::Type; use derive_new::new; use serde_derive::{Deserialize, Serialize}; +use serde::{Serialize, Serializer}; #[derive(Debug, Clone, Eq, PartialEq, Ord, PartialOrd, Serialize, Deserialize, Hash)] pub enum DescriptorName { @@ -31,13 +32,29 @@ impl DescriptorName { } } -#[derive(Debug, Serialize, Deserialize, Clone, Eq, PartialEq, Hash, new)] +#[derive(Debug, Deserialize, Clone, Eq, PartialEq, Hash, new)] pub struct DataDescriptor { crate name: DescriptorName, crate readonly: bool, crate ty: Type, } +impl Serialize for DataDescriptor { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + match self.name { + DescriptorName::String(ref s) => { + serializer.serialize_str(s) + } + DescriptorName::ValueOf => { + serializer.serialize_str("value") + } + } + } +} + impl From<&str> for DataDescriptor { fn from(input: &str) -> DataDescriptor { DataDescriptor { diff --git a/src/object/dict.rs b/src/object/dict.rs index 36216564f1..22167698c6 100644 --- a/src/object/dict.rs +++ b/src/object/dict.rs @@ -4,10 +4,11 @@ use crate::object::DataDescriptor; use crate::object::{Primitive, Value}; use derive_new::new; use indexmap::IndexMap; -use serde_derive::{Deserialize, Serialize}; +use serde_derive::Deserialize; +use serde::ser::{Serialize, Serializer, SerializeMap}; use std::cmp::{Ordering, PartialOrd}; -#[derive(Debug, Default, Eq, PartialEq, Serialize, Deserialize, Clone, new)] +#[derive(Debug, Default, Eq, PartialEq, Deserialize, Clone, new)] pub struct Dictionary { entries: IndexMap, } @@ -19,6 +20,28 @@ impl PartialOrd for Dictionary { } } +impl Serialize for Dictionary { + fn serialize(&self, serializer: S) -> Result + where + S: Serializer, + { + let mut map = serializer.serialize_map(Some(self.entries.len()))?; + for (k, v) in self.entries.iter() { + match v { + Value::Object(_) => {}, + _ => map.serialize_entry(k, v)? + } + } + for (k, v) in self.entries.iter() { + match v { + Value::Object(_) => map.serialize_entry(k, v)?, + _ => {} + } + } + map.end() + } +} + impl From> for Dictionary { fn from(input: IndexMap) -> Dictionary { let mut out = IndexMap::default(); From 2cf0d8d13c6d00eb7515107357b41b5deddfea3c Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 2 Jun 2019 06:27:56 +1200 Subject: [PATCH 02/17] Update README.md --- README.md | 1 + 1 file changed, 1 insertion(+) diff --git a/README.md b/README.md index bd2cda4953..98786a8d92 100644 --- a/README.md +++ b/README.md @@ -23,6 +23,7 @@ Nu currently has the following built-in commands: - first amount - to-array - to-json +- to-toml - from-json - from-toml - open filename From a62de9356c24813b5064c9af36bca503e861f8c0 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 2 Jun 2019 07:20:48 +1200 Subject: [PATCH 03/17] Add support for magic open --- src/commands/from_json.rs | 8 ++++++-- src/commands/from_toml.rs | 8 ++++++-- src/commands/open.rs | 22 +++++++++++++++++++--- src/evaluate/evaluator.rs | 6 ++---- 4 files changed, 33 insertions(+), 11 deletions(-) diff --git a/src/commands/from_json.rs b/src/commands/from_json.rs index f64fc031a7..3a984bac6d 100644 --- a/src/commands/from_json.rs +++ b/src/commands/from_json.rs @@ -18,13 +18,17 @@ fn convert_json_value_to_nu_value(v: &serde_json::Value) -> Value { } } +pub fn from_json_string_to_value(s: String) -> Value { + let v: serde_json::Value = serde_json::from_str(&s).unwrap(); + convert_json_value_to_nu_value(&v) +} + pub fn from_json(args: CommandArgs) -> Result { let out = args.input; Ok(out .map(|a| match a { Value::Primitive(Primitive::String(s)) => { - let v: serde_json::Value = serde_json::from_str(&s).unwrap(); - ReturnValue::Value(convert_json_value_to_nu_value(&v)) + ReturnValue::Value(from_json_string_to_value(s)) } _ => ReturnValue::Value(Value::Primitive(Primitive::String("".to_string()))), }) diff --git a/src/commands/from_toml.rs b/src/commands/from_toml.rs index 38c87409fa..59610a8ffd 100644 --- a/src/commands/from_toml.rs +++ b/src/commands/from_toml.rs @@ -20,13 +20,17 @@ fn convert_toml_value_to_nu_value(v: &toml::Value) -> Value { } } +pub fn from_toml_string_to_value(s: String) -> Value { + let v: toml::Value = s.parse::().unwrap(); + convert_toml_value_to_nu_value(&v) +} + pub fn from_toml(args: CommandArgs) -> Result { let out = args.input; Ok(out .map(|a| match a { Value::Primitive(Primitive::String(s)) => { - let v: toml::Value = s.parse::().unwrap(); - ReturnValue::Value(convert_toml_value_to_nu_value(&v)) + ReturnValue::Value(from_toml_string_to_value(s)) } _ => ReturnValue::Value(Value::Primitive(Primitive::String("".to_string()))), }) diff --git a/src/commands/open.rs b/src/commands/open.rs index cce5b76649..4e9a17b2ee 100644 --- a/src/commands/open.rs +++ b/src/commands/open.rs @@ -14,9 +14,25 @@ pub fn open(args: CommandArgs) -> Result { let contents = std::fs::read_to_string(&full_path).unwrap(); let mut stream = VecDeque::new(); - stream.push_back(ReturnValue::Value(Value::Primitive(Primitive::String( - contents, - )))); + + let open_raw = match args.positional.get(1) { + Some(Value::Primitive(Primitive::String(s))) if s == "--raw" => true, + _ => false, + }; + + match full_path.extension() { + Some(x) if x == "toml" && !open_raw => { + stream.push_back(ReturnValue::Value(crate::commands::from_toml::from_toml_string_to_value(contents))); + } + Some(x) if x == "json" && !open_raw => { + stream.push_back(ReturnValue::Value(crate::commands::from_json::from_json_string_to_value(contents))); + } + _ => { + stream.push_back(ReturnValue::Value(Value::Primitive(Primitive::String( + contents, + )))); + } + } Ok(stream.boxed()) } diff --git a/src/evaluate/evaluator.rs b/src/evaluate/evaluator.rs index 71eab8b134..0ce95a7338 100644 --- a/src/evaluate/evaluator.rs +++ b/src/evaluate/evaluator.rs @@ -1,5 +1,6 @@ use crate::parser::ast; use crate::prelude::*; +use crate::object::Primitive; use derive_new::new; #[derive(new)] @@ -20,10 +21,7 @@ crate fn evaluate_expr(expr: &ast::Expression, scope: &Scope) -> Result Ok(evaluate_leaf(l)), Expression::Parenthesized(p) => evaluate_expr(&p.expr, scope), - Expression::Flag(f) => Err(ShellError::string(format!( - "can't evaluate the flag {}", - f.print() - ))), + Expression::Flag(f) => Ok(Value::Primitive(Primitive::String(f.print()))), Expression::Block(b) => evaluate_block(&b, scope), Expression::Path(p) => evaluate_path(&p, scope), Expression::Binary(b) => evaluate_binary(b, scope), From d6cd0df232d26dce77f12b191fb2dc2407455eff Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 2 Jun 2019 09:11:28 +1200 Subject: [PATCH 04/17] Add git branch to prompt --- Cargo.lock | 149 ++++++++++++++++++++++++++++++++++++++++++++++++++++ Cargo.toml | 1 + src/cli.rs | 9 +++- src/git.rs | 19 +++++++ src/main.rs | 1 + 5 files changed, 177 insertions(+), 2 deletions(-) create mode 100644 src/git.rs diff --git a/Cargo.lock b/Cargo.lock index 22c36fea44..f26dd65699 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -400,6 +400,20 @@ dependencies = [ "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "curl-sys" +version = "0.4.18" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", + "winapi 0.3.7 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "cursive" version = "0.12.0" @@ -822,6 +836,20 @@ dependencies = [ "syn 0.15.34 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "git2" +version = "0.8.0" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "bitflags 1.0.4 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "libgit2-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)", + "log 0.4.6 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)", + "url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "hashbrown" version = "0.3.0" @@ -840,6 +868,16 @@ name = "ident_case" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "idna" +version = "0.1.5" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)", + "unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "indexmap" version = "1.0.2" @@ -935,6 +973,44 @@ name = "libc" version = "0.2.55" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "libgit2-sys" +version = "0.7.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "curl-sys 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "libssh2-sys 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libssh2-sys" +version = "0.2.11" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)", + "openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "libz-sys" +version = "1.0.25" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "line-wrap" version = "0.1.1" @@ -990,6 +1066,11 @@ name = "maplit" version = "1.0.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "matches" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "memchr" version = "2.2.0" @@ -1088,6 +1169,7 @@ dependencies = [ "futures-sink-preview 0.3.0-alpha.16 (registry+https://github.com/rust-lang/crates.io-index)", "futures_codec 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)", "getset 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)", + "git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", "itertools 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)", "lalrpop-util 0.17.0 (registry+https://github.com/rust-lang/crates.io-index)", @@ -1213,6 +1295,23 @@ dependencies = [ "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "openssl-probe" +version = "0.1.2" +source = "registry+https://github.com/rust-lang/crates.io-index" + +[[package]] +name = "openssl-sys" +version = "0.9.47" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "autocfg 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)", + "cc 1.0.37 (registry+https://github.com/rust-lang/crates.io-index)", + "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", + "pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)", + "vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "ordered-float" version = "1.0.2" @@ -1291,6 +1390,11 @@ dependencies = [ "libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "percent-encoding" +version = "1.0.1" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "pin-utils" version = "0.1.0-alpha.4" @@ -1974,6 +2078,22 @@ name = "ucd-util" version = "0.1.3" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "unicode-bidi" +version = "0.3.4" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", +] + +[[package]] +name = "unicode-normalization" +version = "0.1.8" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "smallvec 0.6.9 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "unicode-segmentation" version = "1.3.0" @@ -1997,6 +2117,16 @@ dependencies = [ "void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)", ] +[[package]] +name = "url" +version = "1.7.2" +source = "registry+https://github.com/rust-lang/crates.io-index" +dependencies = [ + "idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)", + "matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)", + "percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)", +] + [[package]] name = "utf8-ranges" version = "1.0.2" @@ -2007,6 +2137,11 @@ name = "utf8parse" version = "0.1.1" source = "registry+https://github.com/rust-lang/crates.io-index" +[[package]] +name = "vcpkg" +version = "0.2.6" +source = "registry+https://github.com/rust-lang/crates.io-index" + [[package]] name = "vec_map" version = "0.8.1" @@ -2157,6 +2292,7 @@ dependencies = [ "checksum csv 1.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "9044e25afb0924b5a5fc5511689b0918629e85d68ea591e5e87fbf1e85ea1b3b" "checksum csv-core 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "fa5cdef62f37e6ffe7d1f07a381bc0db32b7a3ff1cac0de56cb0d81e71f53d65" "checksum ctor 0.1.9 (registry+https://github.com/rust-lang/crates.io-index)" = "3b4c17619643c1252b5f690084b82639dd7fac141c57c8e77a00e0148132092c" +"checksum curl-sys 0.4.18 (registry+https://github.com/rust-lang/crates.io-index)" = "9d91a0052d5b982887d8e829bee0faffc7218ea3c6ebd3d6c2c8f678a93c9a42" "checksum cursive 0.12.0 (registry+https://github.com/rust-lang/crates.io-index)" = "b7ecc7282b5361471b607c26f44148205607e26d48a2fc65bd16e7619b1ebb78" "checksum darling 0.8.6 (registry+https://github.com/rust-lang/crates.io-index)" = "9158d690bc62a3a57c3e45b85e4d50de2008b39345592c64efd79345c7e24be0" "checksum darling 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fcfbcb0c5961907597a7d1148e3af036268f2b773886b8bb3eeb1e1281d3d3d6" @@ -2202,9 +2338,11 @@ dependencies = [ "checksum futures-util-preview 0.3.0-alpha.16 (registry+https://github.com/rust-lang/crates.io-index)" = "f7a0451b9c5047c2b9ab93425ffd0793165511e93c04b977cd45fbd41c6e34b2" "checksum futures_codec 0.2.2 (registry+https://github.com/rust-lang/crates.io-index)" = "b60f48aa03e365df015d2fbf0b79f17b440350c268a5e20305da17b394adcc1e" "checksum getset 0.0.7 (registry+https://github.com/rust-lang/crates.io-index)" = "19fbde0fad0c1c1f9474694b1f5c9ba22b09f2f74f74e6d2bd19c43f6656e2cb" +"checksum git2 0.8.0 (registry+https://github.com/rust-lang/crates.io-index)" = "c7339329bfa14a00223244311560d11f8f489b453fb90092af97f267a6090ab0" "checksum hashbrown 0.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "570178d5e4952010d138b0f1d581271ff3a02406d990f887d1e87e3d6e43b0ac" "checksum humantime 1.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3ca7e5f2e110db35f93b837c81797f3714500b81d517bf20c431b16d3ca4f114" "checksum ident_case 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b9e0384b61958566e926dc50660321d12159025e767c18e043daf26b70104c39" +"checksum idna 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "38f09e0f0b1fb55fdee1f17470ad800da77af5186a1a76c026b679358b7e844e" "checksum indexmap 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "7e81a7c05f79578dbc15793d8b619db9ba32b4577003ef3af1a91c416798c58d" "checksum iovec 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dbe6e417e7d0975db6512b90796e8ce223145ac4e33c377e4a42882a0e88bb08" "checksum is-match 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "7e5b386aef33a1c677be65237cb9d32c3f3ef56bd035949710c4bb13083eb053" @@ -2218,6 +2356,9 @@ dependencies = [ "checksum lazycell 1.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "b294d6fa9ee409a054354afc4352b0b9ef7ca222c69b8812cbea9e7d2bf3783f" "checksum lexical-core 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3e82e023e062f1d25f807ad182008fba1b46538e999f908a08cc0c29e084462e" "checksum libc 0.2.55 (registry+https://github.com/rust-lang/crates.io-index)" = "42914d39aad277d9e176efbdad68acb1d5443ab65afe0e0e4f0d49352a950880" +"checksum libgit2-sys 0.7.11 (registry+https://github.com/rust-lang/crates.io-index)" = "48441cb35dc255da8ae72825689a95368bf510659ae1ad55dc4aa88cb1789bf1" +"checksum libssh2-sys 0.2.11 (registry+https://github.com/rust-lang/crates.io-index)" = "126a1f4078368b163bfdee65fbab072af08a1b374a5551b21e87ade27b1fbf9d" +"checksum libz-sys 1.0.25 (registry+https://github.com/rust-lang/crates.io-index)" = "2eb5e43362e38e2bca2fd5f5134c4d4564a23a5c28e9b95411652021a8675ebe" "checksum line-wrap 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f30344350a2a51da54c1d53be93fade8a237e545dbcc4bdbe635413f2117cab9" "checksum linked-hash-map 0.5.2 (registry+https://github.com/rust-lang/crates.io-index)" = "ae91b68aebc4ddb91978b11a1b02ddd8602a05ec19002801c5666000e05e0f83" "checksum lock_api 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "ed946d4529956a20f2d63ebe1b69996d5a2137c91913fe3ebbeff957f5bca7ff" @@ -2225,6 +2366,7 @@ dependencies = [ "checksum logos 0.10.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)" = "e136962e0902a48fd1d8da8706fac078fdba547bf82f9d9d728cf551d367b41e" "checksum logos-derive 0.10.0-rc2 (registry+https://github.com/rust-lang/crates.io-index)" = "5f03ecd1d993aacc6c4f3a9540e60a4f3811ddac2276dbb66dad4d42671bd5bf" "checksum maplit 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "08cbb6b4fef96b6d77bfc40ec491b1690c779e77b05cd9f07f787ed376fd4c43" +"checksum matches 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "7ffc5c5338469d4d3ea17d269fa8ea3512ad247247c30bd2df69e68309ed0a08" "checksum memchr 2.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "2efc7bc57c883d4a4d6e3246905283d8dae951bb3bd32f49d6ef297f546e1c39" "checksum memoffset 0.2.1 (registry+https://github.com/rust-lang/crates.io-index)" = "0f9dc261e2b62d7a622bf416ea3c5245cdd5d9a7fcc428c0d06804dfce1775b3" "checksum miniz-sys 0.1.12 (registry+https://github.com/rust-lang/crates.io-index)" = "1e9e3ae51cea1576ceba0dde3d484d30e6e5b86dee0b2d412fe3a16a15c98202" @@ -2245,6 +2387,8 @@ dependencies = [ "checksum ole32-sys 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "5d2c49021782e5233cd243168edfa8037574afed4eba4bbaf538b3d8d1789d8c" "checksum onig 4.3.2 (registry+https://github.com/rust-lang/crates.io-index)" = "a646989adad8a19f49be2090374712931c3a59835cb5277b4530f48b417f26e7" "checksum onig_sys 69.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "388410bf5fa341f10e58e6db3975f4bea1ac30247dd79d37a9e5ced3cb4cc3b0" +"checksum openssl-probe 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "77af24da69f9d9341038eba93a073b1fdaaa1b788221b00a69bce9e762cb32de" +"checksum openssl-sys 0.9.47 (registry+https://github.com/rust-lang/crates.io-index)" = "75bdd6dbbb4958d38e47a1d2348847ad1eb4dc205dc5d37473ae504391865acc" "checksum ordered-float 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "18869315e81473c951eb56ad5558bbc56978562d3ecfb87abb7a1e944cea4518" "checksum output_vt100 0.1.2 (registry+https://github.com/rust-lang/crates.io-index)" = "53cdc5b785b7a58c5aad8216b3dfa114df64b0b06ae6e1501cef91df2fbdf8f9" "checksum owning_ref 0.4.0 (registry+https://github.com/rust-lang/crates.io-index)" = "49a4b8ea2179e6a2e27411d3bca09ca6dd630821cf6894c6c7c8467a8ee7ef13" @@ -2253,6 +2397,7 @@ dependencies = [ "checksum parking_lot_core 0.5.0 (registry+https://github.com/rust-lang/crates.io-index)" = "cb88cb1cb3790baa6776844f968fea3be44956cf184fa1be5a03341f5491278c" "checksum parse-zoneinfo 0.2.0 (registry+https://github.com/rust-lang/crates.io-index)" = "089a398ccdcdd77b8c38909d5a1e4b67da1bc4c9dbfe6d5b536c828eddb779e5" "checksum pdcurses-sys 0.7.1 (registry+https://github.com/rust-lang/crates.io-index)" = "084dd22796ff60f1225d4eb6329f33afaf4c85419d51d440ab6b8c6f4529166b" +"checksum percent-encoding 1.0.1 (registry+https://github.com/rust-lang/crates.io-index)" = "31010dd2e1ac33d5b46a5b413495239882813e0369f8ed8a5e266f173602f831" "checksum pin-utils 0.1.0-alpha.4 (registry+https://github.com/rust-lang/crates.io-index)" = "5894c618ce612a3fa23881b152b608bafb8c56cfc22f434a3ba3120b40f7b587" "checksum pkg-config 0.3.14 (registry+https://github.com/rust-lang/crates.io-index)" = "676e8eb2b1b4c9043511a9b7bea0915320d7e502b0a079fb03f9635a5252b18c" "checksum plist 0.4.1 (registry+https://github.com/rust-lang/crates.io-index)" = "f4739851c08dd9a62a78beff2edf1a438517268b2c563c42fc6d9d3139e42d2a" @@ -2330,12 +2475,16 @@ dependencies = [ "checksum toml-query 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "a24369a1894ac8224efcfd567c3d141aea360292f49888e7ec7dcc316527aebb" "checksum toml-query_derive 0.9.0 (registry+https://github.com/rust-lang/crates.io-index)" = "3c99ca245ec273c7e75c8ee58f47b882d0146f3c2c8495158082c6671e8b5335" "checksum ucd-util 0.1.3 (registry+https://github.com/rust-lang/crates.io-index)" = "535c204ee4d8434478593480b8f86ab45ec9aae0e83c568ca81abf0fd0e88f86" +"checksum unicode-bidi 0.3.4 (registry+https://github.com/rust-lang/crates.io-index)" = "49f2bd0c6468a8230e1db229cff8029217cf623c767ea5d60bfbd42729ea54d5" +"checksum unicode-normalization 0.1.8 (registry+https://github.com/rust-lang/crates.io-index)" = "141339a08b982d942be2ca06ff8b076563cbe223d1befd5450716790d44e2426" "checksum unicode-segmentation 1.3.0 (registry+https://github.com/rust-lang/crates.io-index)" = "1967f4cdfc355b37fd76d2a954fb2ed3871034eb4f26d60537d88795cfc332a9" "checksum unicode-width 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "882386231c45df4700b275c7ff55b6f3698780a650026380e72dabe76fa46526" "checksum unicode-xid 0.1.0 (registry+https://github.com/rust-lang/crates.io-index)" = "fc72304796d0818e357ead4e000d19c9c174ab23dc11093ac919054d20a6a7fc" "checksum unreachable 1.0.0 (registry+https://github.com/rust-lang/crates.io-index)" = "382810877fe448991dfc7f0dd6e3ae5d58088fd0ea5e35189655f84e6814fa56" +"checksum url 1.7.2 (registry+https://github.com/rust-lang/crates.io-index)" = "dd4e7c0d531266369519a4aa4f399d748bd37043b00bde1e4ff1f60a120b355a" "checksum utf8-ranges 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "796f7e48bef87609f7ade7e06495a87d5cd06c7866e6a5cbfceffc558a243737" "checksum utf8parse 0.1.1 (registry+https://github.com/rust-lang/crates.io-index)" = "8772a4ccbb4e89959023bc5b7cb8623a795caa7092d99f3aa9501b9484d4557d" +"checksum vcpkg 0.2.6 (registry+https://github.com/rust-lang/crates.io-index)" = "def296d3eb3b12371b2c7d0e83bfe1403e4db2d7a0bba324a12b21c4ee13143d" "checksum vec_map 0.8.1 (registry+https://github.com/rust-lang/crates.io-index)" = "05c78687fb1a80548ae3250346c3db86a80a7cdd77bda190189f2d0a0987c81a" "checksum version_check 0.1.5 (registry+https://github.com/rust-lang/crates.io-index)" = "914b1a6776c4c929a602fafd8bc742e06365d4bcbe48c30f9cca5824f70dc9dd" "checksum void 1.0.2 (registry+https://github.com/rust-lang/crates.io-index)" = "6a02e4885ed3bc0f2de90ea6dd45ebcbb66dacffe03547fadbb0eeae2770887d" diff --git a/Cargo.toml b/Cargo.toml index 02a59f0fd9..f845705179 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -48,6 +48,7 @@ app_dirs = "1.2.1" toml = "0.5.1" toml-query = "0.9.0" clap = "2.33.0" +git2 = "0.8.0" [dependencies.pancurses] version = "0.16" diff --git a/src/cli.rs b/src/cli.rs index 00a47b3944..018126f9a3 100644 --- a/src/cli.rs +++ b/src/cli.rs @@ -11,6 +11,7 @@ crate use crate::format::{EntriesListView, GenericView}; use crate::object::Value; use crate::parser::{ParsedCommand, Pipeline}; use crate::stream::empty_stream; +use crate::git::current_branch; use log::debug; use rustyline::error::ReadlineError; @@ -83,8 +84,12 @@ pub async fn cli() -> Result<(), Box> { loop { let readline = rl.readline(&format!( - "{}> ", - context.env.lock().unwrap().cwd().display().to_string() + "{}{}> ", + context.env.lock().unwrap().cwd().display().to_string(), + match current_branch() { + Some(s) => format!("({})", s), + None => "".to_string() + } )); match process_line(readline, &mut context).await { diff --git a/src/git.rs b/src/git.rs new file mode 100644 index 0000000000..3655285aba --- /dev/null +++ b/src/git.rs @@ -0,0 +1,19 @@ +use git2::Repository; + +pub fn current_branch() -> Option { + match Repository::open(".") { + Ok(repo) => { + let r = repo.head(); + match r { + Ok(r) => { + match r.shorthand() { + Some(s) => Some(s.to_string()), + None => None, + } + }, + _ => None + } + }, + _ => None + } +} diff --git a/src/main.rs b/src/main.rs index 0275b34792..3959da163c 100644 --- a/src/main.rs +++ b/src/main.rs @@ -11,6 +11,7 @@ mod env; mod errors; mod evaluate; mod format; +mod git; mod object; mod parser; mod prelude; From 91220429984d3e0ee8fc19cdeafb89e8fe40cf53 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 2 Jun 2019 11:38:28 +1200 Subject: [PATCH 05/17] Find the repo even in a subdir --- src/git.rs | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/src/git.rs b/src/git.rs index 3655285aba..4782765a23 100644 --- a/src/git.rs +++ b/src/git.rs @@ -1,7 +1,9 @@ -use git2::Repository; +use git2::{Repository, RepositoryOpenFlags}; +use std::ffi::OsString; pub fn current_branch() -> Option { - match Repository::open(".") { + let v: Vec = vec![]; + match Repository::open_ext(".", RepositoryOpenFlags::empty(), v) { Ok(repo) => { let r = repo.head(); match r { From 040c3a5e9c129913d55bb7d65458323be04b5bf1 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 2 Jun 2019 15:37:09 +1200 Subject: [PATCH 06/17] Add first integration test --- src/main.rs | 1 + src/tests.rs | 61 +++++++++++++++++++++++++++++++++++++++++++++ tests/open_toml.out | 1 + tests/open_toml.txt | 2 ++ 4 files changed, 65 insertions(+) create mode 100644 src/tests.rs create mode 100644 tests/open_toml.out create mode 100644 tests/open_toml.txt diff --git a/src/main.rs b/src/main.rs index ab6cf7e095..4705b34bb2 100644 --- a/src/main.rs +++ b/src/main.rs @@ -17,6 +17,7 @@ mod parser; mod prelude; mod shell; mod stream; +mod tests; use clap::{App, Arg}; use log::LevelFilter; diff --git a/src/tests.rs b/src/tests.rs new file mode 100644 index 0000000000..25b027af5a --- /dev/null +++ b/src/tests.rs @@ -0,0 +1,61 @@ +#[cfg(test)] +mod tests { + use std::path::PathBuf; + use std::io::prelude::*; + use std::process::{Command, Stdio}; + use std::error::Error; + + fn test_helper(test_name: &str) { + let mut baseline_path = PathBuf::new(); + baseline_path.push("tests"); + baseline_path.push(test_name); + baseline_path.set_extension("out"); + + let mut txt_path = PathBuf::new(); + txt_path.push("tests"); + txt_path.push(test_name); + txt_path.set_extension("txt"); + + let executable = { + let mut buf = PathBuf::new(); + buf.push("target"); + buf.push("debug"); + buf.push("nu"); + buf + }; + + let process = match Command::new(executable) + .stdin(Stdio::piped()) + .stdout(Stdio::piped()) + .spawn() { + + Ok(process) => process, + Err(why) => panic!("Can't run test {}", why.description()) + }; + + let baseline_out = std::fs::read_to_string(baseline_path).unwrap(); + let baseline_out = baseline_out.replace("\r\n", "\n"); + let input_commands = std::fs::read_to_string(txt_path).unwrap(); + + match process.stdin.unwrap().write_all(input_commands.as_bytes()) { + Err(why) => panic!("couldn't write to wc stdin: {}", + why.description()), + Ok(_) => println!("sent pangram to wc"), + } + + let mut s = String::new(); + match process.stdout.unwrap().read_to_string(&mut s) { + Err(why) => panic!("couldn't read stdout: {}", + why.description()), + Ok(_) => { + let s = s.replace("\r\n", "\n"); + assert_eq!(s, baseline_out); + } + } + } + + #[test] + fn test_toml() { + test_helper("open_toml"); + } +} \ No newline at end of file diff --git a/tests/open_toml.out b/tests/open_toml.out new file mode 100644 index 0000000000..b39a36a7c1 --- /dev/null +++ b/tests/open_toml.out @@ -0,0 +1 @@ +2018 diff --git a/tests/open_toml.txt b/tests/open_toml.txt new file mode 100644 index 0000000000..4c93effadf --- /dev/null +++ b/tests/open_toml.txt @@ -0,0 +1,2 @@ +open tests\test.toml | select package.edition | echo $it +exit From 6fe9dc0bbf2962c43c04f18f493ca6126f258c07 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 2 Jun 2019 18:56:02 +1200 Subject: [PATCH 07/17] Add missing test file --- tests/test.toml | 58 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 58 insertions(+) create mode 100644 tests/test.toml diff --git a/tests/test.toml b/tests/test.toml new file mode 100644 index 0000000000..f845705179 --- /dev/null +++ b/tests/test.toml @@ -0,0 +1,58 @@ +[package] +name = "nu" +version = "0.1.1" +authors = ["Yehuda Katz "] +description = "A shell for the GitHub era" +license = "ISC" +edition = "2018" + +# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html + +[dependencies] +rustyline = "4.1.0" +sysinfo = "0.8.4" +chrono = { version = "0.4.6", features = ["serde"] } +chrono-tz = "0.5.1" +derive-new = "0.5.6" +prettytable-rs = "0.8.0" +itertools = "0.8.0" +ansi_term = "0.11.0" +conch-parser = "0.1.1" +nom = "5.0.0-beta1" +subprocess = "0.1.18" +dunce = "1.0.0" +indexmap = { version = "1.0.2", features = ["serde-1"] } +chrono-humanize = "0.0.11" +byte-unit = "2.1.0" +ordered-float = "1.0.2" +prettyprint = "0.6.0" +cursive = { version = "0.12.0", features = ["pancurses-backend"], default-features = false } +futures-preview = { version = "0.3.0-alpha.16", features = ["compat", "io-compat"] } +futures-sink-preview = "0.3.0-alpha.16" +tokio-fs = "0.1.6" +futures_codec = "0.2.2" +term = "0.5.2" +bytes = "0.4.12" +log = "0.4.6" +pretty_env_logger = "0.3.0" +lalrpop-util = "0.17.0" +regex = "1.1.6" +serde = "1.0.91" +serde_json = "1.0.39" +serde_derive = "1.0.91" +getset = "0.0.7" +logos = "0.10.0-rc2" +logos-derive = "0.10.0-rc2" +language-reporting = "0.3.0" +app_dirs = "1.2.1" +toml = "0.5.1" +toml-query = "0.9.0" +clap = "2.33.0" +git2 = "0.8.0" + +[dependencies.pancurses] +version = "0.16" +features = ["win32a"] + +[dev-dependencies] +pretty_assertions = "0.6.1" From 2045e0194503f37a3b1db121271e7b7d6ebb8182 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Sun, 2 Jun 2019 19:51:54 +1200 Subject: [PATCH 08/17] Fix linux shell support --- src/commands/classified.rs | 63 ++++++++++++++++++++++++++++---------- 1 file changed, 47 insertions(+), 16 deletions(-) diff --git a/src/commands/classified.rs b/src/commands/classified.rs index d744fd04e4..10be56d4c4 100644 --- a/src/commands/classified.rs +++ b/src/commands/classified.rs @@ -133,28 +133,59 @@ impl ExternalCommand { arg_string.push_str(" "); arg_string.push_str(&arg); } - let mut process = Exec::shell(&self.name); - if arg_string.contains("$it") { - let mut first = true; - for i in &inputs { - if !first { - process = process.arg("&&"); - process = process.arg(&self.name); - } else { - first = false; + let mut process; + #[cfg(windows)] + { + process = Exec::shell(&self.name); + + if arg_string.contains("$it") { + let mut first = true; + for i in &inputs { + if !first { + process = process.arg("&&"); + process = process.arg(&self.name); + } else { + first = false; + } + + for arg in &self.args { + process = process.arg(&arg.replace("$it", &i.as_string().unwrap())); + } } - + } else { for arg in &self.args { - process = process.arg(&arg.replace("$it", &i.as_string().unwrap())); - } - } - } else { - for arg in &self.args { - process = process.arg(arg); + process = process.arg(arg); + } } } + #[cfg(not(windows))] + { + let mut new_arg_string = self.name.to_string(); + if arg_string.contains("$it") { + let mut first = true; + for i in &inputs { + if !first { + new_arg_string.push_str(" && "); + new_arg_string.push_str(&self.name); + } else { + first = false; + } + + for arg in &self.args { + new_arg_string.push_str(" "); + new_arg_string.push_str(&arg.replace("$it", &i.as_string().unwrap())); + } + } + } else { + for arg in &self.args { + new_arg_string.push_str(" "); + new_arg_string.push_str(&arg); + } + } + process = Exec::shell(new_arg_string); + } process = process.cwd(context.env.lock().unwrap().cwd()); let mut process = match stream_next { From eb7cb0fba1ba798e4cc233552d07b3c9b76e651e Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 04:47:52 +1200 Subject: [PATCH 09/17] Create LICENSE --- LICENSE | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) create mode 100644 LICENSE diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000000..421e79c499 --- /dev/null +++ b/LICENSE @@ -0,0 +1,21 @@ +MIT License + +Copyright (c) 2019 Yehuda Katz, Jonathan Turner + +Permission is hereby granted, free of charge, to any person obtaining a copy +of this software and associated documentation files (the "Software"), to deal +in the Software without restriction, including without limitation the rights +to use, copy, modify, merge, publish, distribute, sublicense, and/or sell +copies of the Software, and to permit persons to whom the Software is +furnished to do so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. From 8d3ab12b1f22fe3c9dc4ce442719ef5f0b65f623 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 04:48:50 +1200 Subject: [PATCH 10/17] Update README.md --- README.md | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/README.md b/README.md index 98786a8d92..62176e9200 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,10 @@ A shell for the GitHub era. A shell you can hack on. +# License + +The project is made available under the MIT license. See "LICENSE" for more information. + # Status This project has little of what will eventually be necessary for Nu to serve as your day-to-day shell. It already works well enough for contributors to dogfood it as their daily driver, but there are too many basic deficiencies for it to be useful for most people. From 6dd04e43223e3aeb3bcdb2d046878a61ee78df0e Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 04:49:56 +1200 Subject: [PATCH 11/17] Update README.md --- README.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/README.md b/README.md index 62176e9200..d274622c41 100644 --- a/README.md +++ b/README.md @@ -2,10 +2,6 @@ A shell for the GitHub era. A shell you can hack on. -# License - -The project is made available under the MIT license. See "LICENSE" for more information. - # Status This project has little of what will eventually be necessary for Nu to serve as your day-to-day shell. It already works well enough for contributors to dogfood it as their daily driver, but there are too many basic deficiencies for it to be useful for most people. @@ -48,6 +44,10 @@ Priority #3: It's an object shell like PowerShell. > These goals are all critical, project-defining priorities. Priority #1 is "direct compatibility" because any new shell absolutely needs a way to use existing executables in a direct and natural way. +# License + +The project is made available under the MIT license. See "LICENSE" for more information. + # A Taste of Nu ```text From f51c8ea4dc72daf8ef76ec180e737db2d64968a4 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 04:50:41 +1200 Subject: [PATCH 12/17] Update Cargo.toml --- Cargo.toml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index f845705179..0cde56aace 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -1,9 +1,9 @@ [package] name = "nu" version = "0.1.1" -authors = ["Yehuda Katz "] +authors = ["Yehuda Katz ", "Jonathan Turner "] description = "A shell for the GitHub era" -license = "ISC" +license = "MIT" edition = "2018" # See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html From 2fcde1b1e9f9ab2e03d33d702465faa4c76450fd Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 05:18:24 +1200 Subject: [PATCH 13/17] Update README.md --- README.md | 191 ++++++++++++++++++++++++++++++------------------------ 1 file changed, 106 insertions(+), 85 deletions(-) diff --git a/README.md b/README.md index d274622c41..b0026f6b0e 100644 --- a/README.md +++ b/README.md @@ -50,95 +50,116 @@ The project is made available under the MIT license. See "LICENSE" for more info # A Taste of Nu +Nu has built-in commands for ls and ps, loading these results into a table you can work with. + ```text ~\Code\nushell> ps | where cpu > 0 -+-------------------+-----+-------+-------+----------+ -| name | cmd | cpu | pid | status | -+-------------------+-----+-------+-------+----------+ -| chrome.exe | - | 7.83 | 10508 | Runnable | -+-------------------+-----+-------+-------+----------+ -| SearchIndexer.exe | - | 7.83 | 4568 | Runnable | -+-------------------+-----+-------+-------+----------+ -| nu.exe | - | 54.83 | 15436 | Runnable | -+-------------------+-----+-------+-------+----------+ -| chrome.exe | - | 7.83 | 10000 | Runnable | -+-------------------+-----+-------+-------+----------+ -| BlueJeans.exe | - | 7.83 | 6968 | Runnable | -+-------------------+-----+-------+-------+----------+ - -~\Code\nushell> ps | where name == chrome.exe | take 10 - -+------------+-----+------+-------+----------+ -| name | cmd | cpu | pid | status | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 22092 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 17324 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 16376 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 21876 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 13432 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 11772 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 13796 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 1608 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 3340 | Runnable | -+------------+-----+------+-------+----------+ -| chrome.exe | - | 0.00 | 20268 | Runnable | -+------------+-----+------+-------+----------+ - -~\Code\nushell> ls | sort-by "file type" size -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| file name | file type | readonly | size | created | accessed | modified | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| .git | Directory | | Empty | a week ago | 2 minutes ago | 2 minutes ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| src | Directory | | Empty | a week ago | 42 minutes ago | 42 minutes ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| target | Directory | | Empty | a day ago | 19 hours ago | 19 hours ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| .gitignore | File | | 30 B | a week ago | 2 days ago | 2 days ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| .editorconfig | File | | 148 B | 6 days ago | 6 days ago | 6 days ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| Cargo.toml | File | | 714 B | 42 minutes ago | 42 minutes ago | 42 minutes ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| history.txt | File | | 1.4 KiB | 2 days ago | 30 minutes ago | 30 minutes ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| README.md | File | | 2.3 KiB | an hour ago | 30 seconds ago | 30 seconds ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ -| Cargo.lock | File | | 38.6 KiB | 42 minutes ago | 42 minutes ago | 42 minutes ago | -+---------------+-----------+----------+----------+----------------+----------------+----------------+ - -~\Code\nushell> ls | column "file name" "file type" size | sort-by "file type" -+---------------+-----------+----------+ -| file name | file type | size | -+---------------+-----------+----------+ -| .git | Directory | Empty | -+---------------+-----------+----------+ -| src | Directory | Empty | -+---------------+-----------+----------+ -| target | Directory | Empty | -+---------------+-----------+----------+ -| .editorconfig | File | 148 B | -+---------------+-----------+----------+ -| .gitignore | File | 30 B | -+---------------+-----------+----------+ -| Cargo.lock | File | 38.6 KiB | -+---------------+-----------+----------+ -| Cargo.toml | File | 714 B | -+---------------+-----------+----------+ -| history.txt | File | 1.4 KiB | -+---------------+-----------+----------+ -| README.md | File | 2.3 KiB | -+---------------+-----------+----------+ +C:\Source\Play\nushell(master)> ps | where cpu > 0 +------------------------------------------------ + name cmd cpu pid status +------------------------------------------------ + msedge.exe - 0.77 26472 Runnable +------------------------------------------------ + nu.exe - 7.83 15473 Runnable +------------------------------------------------ + SearchIndexer.exe - 82.17 23476 Runnable +------------------------------------------------ + BlueJeans.exe - 4.54 10000 Runnable +------------------------------------------------ ``` +Commands are linked together with pipes, allowing you to select the data you want to use. + +```text +~\Code\nushell> ps | where name == chrome.exe | first 5 + +---------------------------------------- + name cmd cpu pid status +---------------------------------------- + chrome.exe - 0.00 22092 Runnable +---------------------------------------- + chrome.exe - 0.00 17324 Runnable +---------------------------------------- + chrome.exe - 0.00 16376 Runnable +---------------------------------------- + chrome.exe - 0.00 21876 Runnable +---------------------------------------- + chrome.exe - 0.00 13432 Runnable +---------------------------------------- +``` + +The name of the columns in the table can be used to sort the table. + +```text +~\Code\nushell> ls | sort-by "file type" size +---------------------------------------------------------------------------------------- + file name file type readonly size created accessed modified +---------------------------------------------------------------------------------------- + .cargo Directory Empty a week ago a week ago a week ago +---------------------------------------------------------------------------------------- + .git Directory Empty 2 weeks ago 9 hours ago 9 hours ago +---------------------------------------------------------------------------------------- + images Directory Empty 2 weeks ago 2 weeks ago 2 weeks ago +---------------------------------------------------------------------------------------- + src Directory Empty 2 weeks ago 10 hours ago 10 hours ago +---------------------------------------------------------------------------------------- + target Directory Empty 10 hours ago 10 hours ago 10 hours ago +---------------------------------------------------------------------------------------- + tests Directory Empty 14 hours ago 10 hours ago 10 hours ago +---------------------------------------------------------------------------------------- + tmp Directory Empty 2 days ago 2 days ago 2 days ago +---------------------------------------------------------------------------------------- + rustfmt.toml File 16 B a week ago a week ago a week ago +---------------------------------------------------------------------------------------- + .gitignore File 32 B 2 weeks ago 2 weeks ago 2 weeks ago +---------------------------------------------------------------------------------------- + .editorconfig File 156 B 2 weeks ago 2 weeks ago 2 weeks ago +---------------------------------------------------------------------------------------- +``` + +You can also use the names of the columns to down-select to only the data you want. +```text +~\Code\nushell> ls | column "file name" "file type" size | sort-by "file type" +------------------------------------ + file name file type size +------------------------------------ + .cargo Directory Empty +------------------------------------ + .git Directory Empty +------------------------------------ + images Directory Empty +------------------------------------ + src Directory Empty +------------------------------------ + target Directory Empty +------------------------------------ + tests Directory Empty +------------------------------------ + rustfmt.toml File 16 B +------------------------------------ + .gitignore File 32 B +------------------------------------ + .editorconfig File 156 B +------------------------------------ +``` + +Some file times can be loaded as tables. + +```text +~\Code\nushell> open Cargo.toml +---------------------------------------------------- + dependencies dev-dependencies package +---------------------------------------------------- + [object Object] [object Object] [object Object] +---------------------------------------------------- + +~\Code\nushell> open Cargo.toml | select package +-------------------------------------------------------------------------- + authors description edition license name version +-------------------------------------------------------------------------- + [list List] A shell for the GitHub era 2018 MIT nu 0.1.1 +-------------------------------------------------------------------------- +``` Nu currently has fish-style completion of previous commands, as well ctrl-r reverse search. ![autocompletion][fish-style] From 6d0afcc763ecda57dd2b6e70e30ebff5c6e98493 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 05:21:50 +1200 Subject: [PATCH 14/17] Update README.md --- README.md | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index b0026f6b0e..2c47f7db16 100644 --- a/README.md +++ b/README.md @@ -1,6 +1,6 @@ # Nu Shell -A shell for the GitHub era. A shell you can hack on. +A shell for the GitHub era. Like having a playground for a shell. # Status @@ -160,6 +160,14 @@ Some file times can be loaded as tables. [list List] A shell for the GitHub era 2018 MIT nu 0.1.1 -------------------------------------------------------------------------- ``` + +Once you've cound the data, you can call out to external applications and use it. + +```text +~\Code\nushell> open Cargo.toml | select package.version | echo $it +0.1.1 +``` + Nu currently has fish-style completion of previous commands, as well ctrl-r reverse search. ![autocompletion][fish-style] From fd4c86b77a70f0e30fbdd9e8d94b167ae3190c2e Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 05:27:01 +1200 Subject: [PATCH 15/17] Update README.md --- README.md | 2 -- 1 file changed, 2 deletions(-) diff --git a/README.md b/README.md index 2c47f7db16..fa4c1f7f98 100644 --- a/README.md +++ b/README.md @@ -54,7 +54,6 @@ Nu has built-in commands for ls and ps, loading these results into a table you c ```text ~\Code\nushell> ps | where cpu > 0 -C:\Source\Play\nushell(master)> ps | where cpu > 0 ------------------------------------------------ name cmd cpu pid status ------------------------------------------------ @@ -72,7 +71,6 @@ Commands are linked together with pipes, allowing you to select the data you wan ```text ~\Code\nushell> ps | where name == chrome.exe | first 5 - ---------------------------------------- name cmd cpu pid status ---------------------------------------- From dff43e3c61850bd66d7bcb5eeda1db9dc42d5bd8 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 05:45:57 +1200 Subject: [PATCH 16/17] Update README.md --- README.md | 48 +++++++++++++++++++++++++++--------------------- 1 file changed, 27 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index fa4c1f7f98..f0250c750a 100644 --- a/README.md +++ b/README.md @@ -8,29 +8,35 @@ This project has little of what will eventually be necessary for Nu to serve as At the moment, executing a command that isn't identified as a built-in new command will fall back to running it as a shell command (using cmd on Windows or bash on Linux and MacOS), correctly passing through stdin, stdout and stderr, so things like your daily git workflows and even `vim` will work just fine. -There is not yet support for piping external commands to each other; piping is limited to Nu commands at the moment. +## Commands +| command | description | +| ------------- | ------------- | +| cd directory | Change to the given directory | +| ls | View current directory contents | +| ps | View current processes | +| open filename | Load a file into a cell, convert to table if possible (avoid by appending '--raw') | -Nu currently has the following built-in commands: +## Commands on tables +| command | description | +| ------------- | ------------- | +| column ...fields | Down-select table to only these columns | +| reject ...fields | Remove the given columns from the table | +| sort-by ...fields | Sort by the given columns | +| where condition | Filter table to match the condition | +| skip amount | Skip a number of rows | +| first amount | Show only the first number of rows | +| to-array | Collapse rows into a single list | +| to-json | Convert table into .json text | +| to-toml | Convert table into .toml text | -- cd directory -- ls -- ps -- column ...fields -- reject ...fields -- sort-by ...fields -- where condition -- skip amount -- first amount -- to-array -- to-json -- to-toml -- from-json -- from-toml -- open filename -- split-column sep ...fields -- split-row sep ...fields -- select field -- trim +## Commands on text +| command | description | +| ------------- | ------------- | +| from-json | Parse text as .json and create table | +| from-toml | Parse text as .toml and create table | +| split-column sep ...fields | Split row contents across multiple rows via the separator | +| split-row sep | Split row contents over multiple rows via the separator | +| trim | Trim leading and following whitespace from text data | # Goals From bd7e17a4ad7f5f9c1c25359f301abaaf74e35145 Mon Sep 17 00:00:00 2001 From: Jonathan Turner Date: Mon, 3 Jun 2019 05:49:08 +1200 Subject: [PATCH 17/17] Update README.md --- README.md | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/README.md b/README.md index f0250c750a..ea64123185 100644 --- a/README.md +++ b/README.md @@ -19,9 +19,10 @@ At the moment, executing a command that isn't identified as a built-in new comma ## Commands on tables | command | description | | ------------- | ------------- | -| column ...fields | Down-select table to only these columns | -| reject ...fields | Remove the given columns from the table | -| sort-by ...fields | Sort by the given columns | +| column ...columns | Down-select table to only these columns | +| reject ...columns | Remove the given columns from the table | +| select column-or-column-path | Open given cells as text | +| sort-by ...columns | Sort by the given columns | | where condition | Filter table to match the condition | | skip amount | Skip a number of rows | | first amount | Show only the first number of rows | @@ -37,6 +38,7 @@ At the moment, executing a command that isn't identified as a built-in new comma | split-column sep ...fields | Split row contents across multiple rows via the separator | | split-row sep | Split row contents over multiple rows via the separator | | trim | Trim leading and following whitespace from text data | +| {external-command} $it | Run external command with given arguments, replacing $it with each row text | # Goals