Add support for prompt configuration (#62)

- Create `Config` struct that is added to `Context` when initialized
- Read `~/.confg/starship.toml` during initialization (can be updated later to also look at `$XDG_CONFIG_HOME`)
- `Context` now has a method for creating modules. This allows us to provide modules with a reference to the configuration specific to that module
This commit is contained in:
Matan Kushner
2019-06-10 15:56:17 +01:00
committed by GitHub
parent 8239fbd12b
commit 097f1b05f1
27 changed files with 196 additions and 182 deletions
+23 -18
View File
@@ -1,36 +1,46 @@
FROM rust
# Create /src as root
RUN mkdir /src && chmod -R a+w /src
# Create non-root user
RUN useradd -ms /bin/bash nonroot
USER nonroot
# Install Node.js
ENV NODE_VERSION 12.0.0
ENV PATH /root/.nvm/versions/node/v$NODE_VERSION/bin:$PATH
ENV NVM_DIR /home/nonroot/.nvm
ENV PATH $NVM_DIR/versions/node/v$NODE_VERSION/bin:$PATH
RUN curl https://raw.githubusercontent.com/creationix/nvm/master/install.sh | bash
# Check that Node.js was correctly installed
RUN node --version
# Install Go
ENV GO_VERSION 1.10.0
ENV GOENV_ROOT /root/.goenv
ENV GOENV_ROOT /home/nonroot/.goenv
ENV PATH $GOENV_ROOT/bin:$GOENV_ROOT/shims:$PATH
RUN git clone https://github.com/syndbg/goenv.git $GOENV_ROOT \
&& eval "$(goenv init -)" \
&& goenv install $GO_VERSION \
&& goenv global $GO_VERSION
&& eval "$(goenv init -)" \
&& goenv install $GO_VERSION \
&& goenv global $GO_VERSION \
&& chmod -R a+x $GOENV_ROOT
# Check that Go was correctly installed
RUN go version
# Install Python
ENV PYTHON_VERSION 3.6.8
ENV PYENV_ROOT /root/.pyenv
ENV PYENV_ROOT /home/nonroot/.pyenv
ENV PATH $PYENV_ROOT/bin:$PYENV_ROOT/shims:$PATH
RUN curl https://pyenv.run | bash \
&& pyenv install $PYTHON_VERSION \
&& pyenv global $PYTHON_VERSION
&& pyenv global $PYTHON_VERSION \
&& chmod -R a+x $PYENV_ROOT
# Check that Python was correctly installed
RUN python --version
# Create blank project
RUN USER=root cargo new --bin starship
WORKDIR /starship
RUN USER=nonroot cargo new --bin /src/starship
WORKDIR /src/starship
# We want dependencies cached, so copy those first
COPY ./Cargo.lock ./Cargo.lock
@@ -41,13 +51,8 @@ RUN mkdir benches
RUN touch benches/my_benchmark.rs
# This is a dummy build to get dependencies cached
RUN cargo build --release
RUN cargo build --release \
&& rm -rf src target/debug/starship*
# Delete the dummy build
RUN rm -rf /starship
# Create the directory for the real source files
RUN mkdir starship
WORKDIR /starship
CMD ["cargo", "test", "--", "--ignored"]
# "-Z unstable-options" is required for "--include-ignored"
CMD ["cargo", "test", "--", "-Z", "unstable-options", "--include-ignored"]
+2 -2
View File
@@ -67,10 +67,10 @@ fn root_directory() -> io::Result<()> {
#[test]
fn directory_in_root() -> io::Result<()> {
let output = common::render_module("dir").arg("--path=/tmp").output()?;
let output = common::render_module("dir").arg("--path=/usr").output()?;
let actual = String::from_utf8(output.stdout).unwrap();
let expected = format!("in {} ", Color::Cyan.bold().paint("/tmp"));
let expected = format!("in {} ", Color::Cyan.bold().paint("/usr"));
assert_eq!(expected, actual);
Ok(())
}
+12 -9
View File
@@ -7,31 +7,34 @@ use crate::common;
// Requires mocking
#[test]
fn no_username_shown() -> io::Result<()> {
let expected = "";
// No environment variables
fn no_env_variables() -> io::Result<()> {
let output = common::render_module("username").env_clear().output()?;
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
assert_eq!("", actual);
Ok(())
}
// LOGNAME == USER
#[test]
fn logname_equals_user() -> io::Result<()> {
let output = common::render_module("username")
.env_clear()
.env("LOGNAME", "astronaut")
.env("USER", "astronaut")
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
assert_eq!("", actual);
Ok(())
}
#[test]
fn ssh_wo_username() -> io::Result<()> {
// SSH connection w/o username
let output = common::render_module("username")
.env_clear()
.env("SSH_CONNECTION", "192.168.223.17 36673 192.168.223.229 22")
.output()?;
let actual = String::from_utf8(output.stdout).unwrap();
assert_eq!(expected, actual);
assert_eq!("", actual);
Ok(())
}