Bump to 0.18.2. Move starship external. (#2345)

* Bump to 0.18.2. Move starship external.

* Fix failing test
This commit is contained in:
Jonathan Turner
2020-08-14 07:02:45 +12:00
committed by GitHub
parent 22519c9083
commit da4d24d082
32 changed files with 212 additions and 430 deletions

View File

@ -4,20 +4,20 @@ description = "CLI for nushell"
edition = "2018"
license = "MIT"
name = "nu-cli"
version = "0.18.1"
version = "0.18.2"
[lib]
doctest = false
[dependencies]
nu-errors = {version = "0.18.1", path = "../nu-errors"}
nu-parser = {version = "0.18.1", path = "../nu-parser"}
nu-plugin = {version = "0.18.1", path = "../nu-plugin"}
nu-protocol = {version = "0.18.1", path = "../nu-protocol"}
nu-source = {version = "0.18.1", path = "../nu-source"}
nu-table = {version = "0.18.1", path = "../nu-table"}
nu-test-support = {version = "0.18.1", path = "../nu-test-support"}
nu-value-ext = {version = "0.18.1", path = "../nu-value-ext"}
nu-errors = {version = "0.18.2", path = "../nu-errors"}
nu-parser = {version = "0.18.2", path = "../nu-parser"}
nu-plugin = {version = "0.18.2", path = "../nu-plugin"}
nu-protocol = {version = "0.18.2", path = "../nu-protocol"}
nu-source = {version = "0.18.2", path = "../nu-source"}
nu-table = {version = "0.18.2", path = "../nu-table"}
nu-test-support = {version = "0.18.2", path = "../nu-test-support"}
nu-value-ext = {version = "0.18.2", path = "../nu-value-ext"}
ansi_term = "0.12.1"
app_dirs = {version = "2", package = "app_dirs2"}
@ -95,7 +95,6 @@ clipboard = {version = "0.5", optional = true}
encoding_rs = "0.8.23"
quick-xml = "0.18.1"
rayon = "1.3.1"
starship = {version = "0.43.0", optional = true}
trash = {version = "1.0.1", optional = true}
url = {version = "2.1.1"}
@ -124,5 +123,4 @@ quickcheck_macros = "0.9"
[features]
clipboard-cli = ["clipboard"]
stable = []
starship-prompt = ["starship"]
trash-support = ["trash"]

View File

@ -228,22 +228,6 @@ impl History {
}
}
#[allow(dead_code)]
fn create_default_starship_config() -> Option<toml::Value> {
let mut map = toml::value::Table::new();
map.insert("add_newline".into(), toml::Value::Boolean(false));
let mut git_branch = toml::value::Table::new();
git_branch.insert("symbol".into(), toml::Value::String("📙 ".into()));
map.insert("git_branch".into(), toml::Value::Table(git_branch));
let mut git_status = toml::value::Table::new();
git_status.insert("disabled".into(), toml::Value::Boolean(true));
map.insert("git_status".into(), toml::Value::Table(git_status));
Some(toml::Value::Table(map))
}
pub fn create_default_context(
syncer: &mut crate::EnvironmentSyncer,
interactive: bool,
@ -746,11 +730,6 @@ pub async fn cli(
);
}
let use_starship = config
.get("use_starship")
.map(|x| x.is_true())
.unwrap_or(false);
#[cfg(windows)]
{
let _ = ansi_term::enable_ansi_support();
@ -808,37 +787,7 @@ pub async fn cli(
)));
let colored_prompt = {
if use_starship {
#[cfg(feature = "starship")]
{
std::env::set_var("STARSHIP_SHELL", "");
std::env::set_var("PWD", &cwd);
let mut starship_context =
starship::context::Context::new_with_dir(clap::ArgMatches::default(), cwd);
match starship_context.config.config {
None => {
starship_context.config.config = create_default_starship_config();
}
Some(toml::Value::Table(t)) if t.is_empty() => {
starship_context.config.config = create_default_starship_config();
}
_ => {}
};
starship::print::get_prompt(starship_context)
}
#[cfg(not(feature = "starship"))]
{
format!(
"\x1b[32m{}{}\x1b[m> ",
cwd,
match current_branch() {
Some(s) => format!("({})", s),
None => "".to_string(),
}
)
}
} else if let Some(prompt) = config.get("prompt") {
if let Some(prompt) = config.get("prompt") {
let prompt_line = prompt.as_string()?;
match nu_parser::lite_parse(&prompt_line, 0).map_err(ShellError::from) {

View File

@ -79,11 +79,6 @@ fn features_enabled(tag: impl Into<Tag>) -> TaggedListBuilder {
names.push_untagged(UntaggedValue::string("trash"));
}
#[cfg(feature = "starship-prompt")]
{
names.push_untagged(UntaggedValue::string("starship"));
}
names
}

View File

@ -1,41 +1,26 @@
use crate::prelude::*;
pub fn current_branch() -> Option<String> {
if let Ok(config) = crate::data::config::config(Tag::unknown()) {
let use_starship = config
.get("use_starship")
.map(|x| x.is_true())
.unwrap_or(false);
#[cfg(feature = "git2")]
{
use git2::{Repository, RepositoryOpenFlags};
use std::ffi::OsString;
if !use_starship {
#[cfg(feature = "git2")]
{
use git2::{Repository, RepositoryOpenFlags};
use std::ffi::OsString;
let v: Vec<OsString> = vec![];
match Repository::open_ext(".", RepositoryOpenFlags::empty(), v) {
Ok(repo) => {
let r = repo.head();
match r {
Ok(r) => match r.shorthand() {
Some(s) => Some(s.to_string()),
None => None,
},
_ => None,
}
}
let v: Vec<OsString> = vec![];
match Repository::open_ext(".", RepositoryOpenFlags::empty(), v) {
Ok(repo) => {
let r = repo.head();
match r {
Ok(r) => match r.shorthand() {
Some(s) => Some(s.to_string()),
None => None,
},
_ => None,
}
}
#[cfg(not(feature = "git2"))]
{
None
}
} else {
None
_ => None,
}
} else {
}
#[cfg(not(feature = "git2"))]
{
None
}
}

View File

@ -32,16 +32,30 @@ fn figures_out_intelligently_where_to_write_out_with_metadata() {
#[test]
fn writes_out_csv() {
Playground::setup("save_test_2", |dirs, _| {
Playground::setup("save_test_2", |dirs, sandbox| {
sandbox.with_files(vec![FileWithContent(
"cargo_sample.json",
r#"
{
"package": {
"name": "nu",
"version": "0.14",
"description": "A new type of shell",
"license": "MIT",
"edition": "2018"
}
}
"#,
)]);
let expected_file = dirs.test().join("cargo_sample.csv");
nu!(
cwd: dirs.root(),
"open \"{}/cargo_sample.toml\" | get package | save save_test_2/cargo_sample.csv",
dirs.formats()
"open save_test_2/cargo_sample.json | get package | save save_test_2/cargo_sample.csv",
);
let actual = file_contents(expected_file);
assert!(actual.contains("nu,0.1.1,[Table],a new type of shell,ISC,2018"));
assert!(actual.contains("nu,0.14,A new type of shell,MIT,2018"));
})
}