Skip to content

Commit

Permalink
Merge pull request #19 from TomasTomecek/final-polish
Browse files Browse the repository at this point in the history
Final polish
  • Loading branch information
TomasTomecek authored May 21, 2017
2 parents 25ff192 + 4154503 commit c5c9337
Show file tree
Hide file tree
Showing 10 changed files with 146 additions and 102 deletions.
37 changes: 19 additions & 18 deletions Makefile
Original file line number Diff line number Diff line change
@@ -1,43 +1,44 @@
# exec-* targets execute the target targetly
# exec-* targets execute commands of the target directly
# rest is executed in a container
#
# stable container is meant to be used
# unstable is meant for development & testing
# stable container produces binaries which are meant to be used in production
# nightly container is meant for development & testing (b/c of clippy)
#
# TODO: cache build container: run it and exec statements inside
# or figure out bind-mounted cargo cache

.PHONY=default compile build stable-environment unstable-environment stable-build unstable-build exec-stable-build exec-unstable-build test exec-test
.PHONY=default compile build stable-environment nightly-environment stable-build nightly-build exec-stable-build exec-nightly-build test exec-test
RUST_STABLE_SPEC="1.15.1"
RUST_UNSTABLE_SPEC="nightly-2017-03-30"
# 05-21, last nightly used: -2017-03-30
RUST_NIGHTLY_SPEC="nightly"
DEPS=$(wildcard src/*.rs)
CURRENT_USER="$(shell id -u)"
STABLE_BUILD_IMAGE="${USER}/pretty-git-prompt"
UNSTABLE_BUILD_IMAGE="${USER}/pretty-git-prompt:dev"
NIGHTLY_BUILD_IMAGE="${USER}/pretty-git-prompt:dev"
STABLE_CONTAINER_RUN=docker run --rm -v ${PWD}:/app:Z -ti $(STABLE_BUILD_IMAGE)
# breaks CI: -v ~/.cargo/registry/:/home/pretty/.cargo/registry/:Z
UNSTABLE_CONTAINER_RUN=docker run --rm -v ${PWD}:/app:Z -ti $(UNSTABLE_BUILD_IMAGE)
# breaks CI: -v ~/.cargo/registry/:/home/pretty/.cargo/registry/:Z
NIGHTLY_CONTAINER_RUN=docker run --rm -v ${PWD}:/app:Z -ti $(NIGHTLY_BUILD_IMAGE)

default: build


compile: unstable-build
compile: nightly-build

build: stable-build

stable-environment:
docker build --build-arg USER_ID=$(CURRENT_USER) --build-arg RUST_SPEC=$(RUST_STABLE_SPEC) --build-arg WITH_TEST=no --tag $(STABLE_BUILD_IMAGE) .
unstable-environment:
docker build --build-arg USER_ID=$(CURRENT_USER) --build-arg RUST_SPEC=$(RUST_UNSTABLE_SPEC) --build-arg WITH_TEST=yes --tag $(UNSTABLE_BUILD_IMAGE) .
nightly-environment:
docker build --build-arg USER_ID=$(CURRENT_USER) --build-arg RUST_SPEC=$(RUST_NIGHTLY_SPEC) --build-arg WITH_TEST=yes --tag $(NIGHTLY_BUILD_IMAGE) .

stable-build: stable-environment
$(STABLE_CONTAINER_RUN) make exec-stable-build
unstable-build:
$(UNSTABLE_CONTAINER_RUN) make exec-unstable-build
nightly-build:
$(NIGHTLY_CONTAINER_RUN) make exec-nightly-build

exec-stable-build: target/release/pretty-git-prompt

exec-unstable-build: target/debug/pretty-git-prompt
exec-nightly-build: target/debug/pretty-git-prompt

target/release/pretty-git-prompt: $(DEPS)
LIBZ_SYS_STATIC=1 cargo build --release
Expand All @@ -46,7 +47,7 @@ target/debug/pretty-git-prompt: $(DEPS)


test:
$(UNSTABLE_CONTAINER_RUN) make exec-test
$(NIGHTLY_CONTAINER_RUN) make exec-test

exec-test: target/debug/pretty-git-prompt
py.test-3 -vv tests
Expand All @@ -56,13 +57,13 @@ exec-test: target/debug/pretty-git-prompt
# compile and inject into container
# open prompt with prepared git repo
zsh-demo:
$(UNSTABLE_CONTAINER_RUN) files/demo.py zsh
$(NIGHTLY_CONTAINER_RUN) files/demo.py zsh
bash-demo:
$(UNSTABLE_CONTAINER_RUN) files/demo.py bash
$(NIGHTLY_CONTAINER_RUN) files/demo.py bash


shell:
$(UNSTABLE_CONTAINER_RUN) zsh -l
$(NIGHTLY_CONTAINER_RUN) zsh -l

show-work:
egrep --color=yes -C 3 "(TODO|FIXME)" $(DEPS) Makefile Dockerfile
Expand Down
66 changes: 47 additions & 19 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,17 +6,32 @@ Your current git repository information inside a beautiful shell prompt.

![Preview of pretty-git-prompt](/data/example.png)

Features:

* You are able to display values such as:
* git repository state (resolving `merge` conflict, interactive `rebase`, ...)
* Current branch name.
* Count of changed, newly-added, staged, conflicting files.
* You can track divergence against arbitrary branches.
* Every value in output can be fully configured via a config file.
* Sample configuration files feature colors.
* The tool supports `zsh` and `bash`.
* pretty-git-prompt is written in Rust programming language and is delivered as a single, statically-linked binary.


## Development status

I would like to produce the first official 0.1.0 release, but there are still
some issues I need to clear out. So use at your own risk.
The tool is ready to use.


## How can I try this out?

## How can I try this?
Very easily! You don't need to install pretty-git-prompt if you just want to
see it in action. There is a make target which launches docker container with
whole environment set up.

Very easily, actually! It just takes some time to prepare it (create build
environment, compile the tool, run the demo).
It just takes some time to prepare the environment (create build environment,
compile the tool, run the demo).

Just clone this git repository

Expand All @@ -35,38 +50,50 @@ $ make zsh-demo

And this is what you should see:

![]() TBD
![Preview using zsh.](/data/zsh-screenshot.png)

This is an interactive shell, so you can play with it.


### bash

In case you want to see the tool in bash shell:

```
$ make bash-demo
```

![]() TBD
![Preview using bash.](/data/bash-screenshot.png)

This demo is one of the ways I test the tool.
This demo is one of the ways I verify that the tool works correctly.


## Usage
## Installation

If you want to add it inside your shell, this section contains information how to do that.
If you want to add pretty-git-prompt inside your shell, this section contains
information how to do that.


### Obtaining `pretty-git-prompt` binary


#### GitHub release

Get latest binary via GitHub release:
Get the binary via [latest GitHub release](https://github.com/TomasTomecek/pretty-git-prompt/releases/latest).

For a linux distrubution:

```
$ curl -O TBD
$ curl -O https://github.com/TomasTomecek/pretty-git-prompt/releases/download/0.1.3/pretty-git-prompt-0.1.0-x86_64-unknown-linux-gnu
```

Or for MacOS:

```
$ curl -O https://github.com/TomasTomecek/pretty-git-prompt/releases/download/0.1.0/pretty-git-prompt-0.1.0-x86_64-apple-darwin
```



#### Compile it yourself

Expand All @@ -80,14 +107,14 @@ If you have rust compiler and cargo available on your system, you can compile
the tool without using a container:

```
$ cargo build --release
$ make exec-stable-build
```

The binary is then available on this path:

```
$ ls -lha target/release/pretty-git-prompt
-rwxr-xr-x 2 user group 4.8M Apr 1 21:37 target/release/pretty-git-prompt
-rwxr-xr-x 2 user group 1.7M May 9 21:37 target/release/pretty-git-prompt
```


Expand Down Expand Up @@ -145,10 +172,11 @@ This is not a git repository: Error { code: -3, klass: 6, message: "could not fi
## Configuration

The configuration is documented inside default config file. Therefore it's not
explicitely written down here. You can obtain it via:
explicitly written down here. You can obtain it via:

```
$ pretty-git-prompt create-default-config
Configuration file created at "/home/you/.config/pretty-git-prompt.yml"
```

This repository contains also configuration for bash and zsh with colors:
Expand All @@ -174,7 +202,7 @@ This project builds upon several principles:
1. Configurable as much as possible.
2. Pretty and useful.
3. As few dependencies as possible.
4. Easy to contibute to:
4. Easy to contribute to:
* Build with a single command.
* Build inside predictive environment.
* Test with a single command.
Expand All @@ -189,10 +217,10 @@ All you need is [docker](https://github.com/docker/docker) engine running and `m
First you need to build container image with rust and all dependencies inside:

```
$ make unstable-environment
$ make nightly-environment
```

This is using latest usable nightly rust.
This is using latest nightly rust. The nightly is used because of [clippy](https://github.com/Manishearth/rust-clippy).

And then just make sure all tests are passing and you are not introducing any new warnings:

Expand All @@ -207,4 +235,4 @@ If any of the two `make` invocations above doesn't work for you, please open an

This tool is heavily inspired by
[zsh-git-prompt](https://github.com/olivierverdier/zsh-git-prompt). At some
point I realized, I wanted a more powerful tool.
point I realized, I wanted a more powerful tool so I wrote pretty-git-prompt.
Binary file added data/bash-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file modified data/example.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/zsh-screenshot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
37 changes: 20 additions & 17 deletions files/demo.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,16 @@ def checkout_ref(z, ref):
def checkout_b(z, branch_name):
z.sendline("git checkout -b {}".format(branch_name))

def create_file(filename, content):
with open(filename, "w") as fd:
fd.write(content + "\r\n")
def append_file(z, filename, content):
z.sendline("echo '{}' >> {}".format(content, filename))
# with open(filename, "a") as fd:
# fd.write(content + "\r\n")

def append_file(filename, content):
with open(filename, "a") as fd:
fd.write(content + "\r\n")
def create_file(z, filename, content):
z.sendline("touch {}".format(filename))
append_file(z, filename, content)
# with open(filename, "w") as fd:
# fd.write(content + "\r\n")


class G():
Expand Down Expand Up @@ -111,7 +114,7 @@ def run(self):
class SimpleUntrackedFilesRepo(BareRepo):
def run(self):
super().run()
create_file("file.txt", "text")
create_file(self.z, "file.txt", "text")


class SimpleChangedFilesRepo(SimpleUntrackedFilesRepo):
Expand All @@ -130,7 +133,7 @@ def run(self):
class SimpleDirtyWithCommitRepo(SimpleRepo):
def run(self):
super().run()
create_file("file.txt", "text2")
create_file(self.z, "file.txt", "text2")


class RepoWithOrigin(SimpleRepo):
Expand All @@ -145,7 +148,7 @@ def run(self):
super().run()
with self.s:
push(self.z, "origin", "master", with_tracking=False)
create_file("file.txt", "text3")
create_file(self.z, "file.txt", "text3")
with self.s:
add_file(self.z, "file.txt")
with self.s:
Expand All @@ -167,7 +170,7 @@ def run(self):
class RWORemoteCommits(RepoWithOrigin):
def run(self):
super().run()
create_file("file.txt", "text4")
create_file(self.z, "file.txt", "text4")
with self.s:
add_file(self.z, "file.txt")
with self.s:
Expand All @@ -192,7 +195,7 @@ def run(self):
super().run()
checkout_b(self.z, "branch")
reset_hard(self.z, "HEAD^")
create_file("file.txt", "text5")
create_file(self.z, "file.txt", "text5")
add_file(self.z, "file.txt")
commit(self.z)
checkout_ref(self.z, "master")
Expand All @@ -204,7 +207,7 @@ class Demo(RWORemoteCommits):
def run(self):
super().run()
with self.s:
create_file("file.txt", "text5")
create_file(self.z, "file.txt", "text5")
with self.s:
add_file(self.z, "file.txt")
with self.s:
Expand All @@ -214,22 +217,22 @@ def run(self):
with self.s:
push(self.z, "upstream", "master", with_tracking=False)
with self.s:
append_file("file.txt", "text6")
append_file(self.z, "file.txt", "text6")
with open("file.txt", "a") as f:
f.write("text6")
with self.s:
add_file(self.z, "file.txt")
with self.s:
commit(self.z)
with self.s:
append_file("file.txt", "text7")
append_file(self.z, "file.txt", "text7")
with self.s:
add_file(self.z, "file.txt")
with self.s:
append_file("file.txt", "text8")
append_file(self.z, "file.txt", "text8")
with self.s:
create_file("file2.txt", "text7")
self.z.sendline()
create_file(self.z, "file2.txt", "text7")
# self.z.sendline()
self.z.interact()


Expand Down
2 changes: 1 addition & 1 deletion hack/ci.sh
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@


if [ "${TRAVIS_EVENT_TYPE}" = "cron" -a "${TARGET}" = "x86_64-unknown-linux-gnu" ] ; then
make unstable-environment && make test
make nightly-environment && make test
else
cargo test --verbose
fi
Loading

0 comments on commit c5c9337

Please sign in to comment.