Giter VIP home page Giter VIP logo

powerline-rust's Introduction

powerline-rust

Build Status

powerline-rust is an alternative to powerline-shell. It's heavily inspired by it, but focuses on minimalizing time of execution.

Nobody wants to see latency between pressing enter in favourite shell and seeing prompt. This is main aim of this crate and that's why some features of other alternatives like dynamic segments choosing and theming via commandline arguments is not possible here.

Although, similar results can be archived by customization.

There is a demand to recompile every time while customizing, but you change your prompt only once upon a time. I think performance beneficence is worth it.

With default settings powerline-rust uses libgit for git prompt. Unfortunately results vary from system to system so if you want every last bit of a performance you can try disabling this feature and benchmarking.

Advantages

  • blazing fast (less than 0.010s)
  • only necessary dependencies
  • runs git backend only when needed (huge time improvements in directories not in git tree)
  • optional caching git results in memory or file

Simple installation

git clone https://github.com/cirho/powerline-rust
cd powerline-rust
# bash shell 
cargo install --path .
# zsh shell 
cargo install --path . --no-default-features --features=zsh-shell,libgit
# fish shell
cargo install --path . --no-default-features --features=bare-shell,libgit

You can also install one of examples by adding --example {name} to cargo command.

Setting up shell

Make sure you have executable in $PATH

bash

function _update_ps1() {
    PS1="$(powerline $?)"
}

if [ "$TERM" != "linux" ]; then
    PROMPT_COMMAND="_update_ps1; $PROMPT_COMMAND"
fi

zsh

You must also compile with zsh-shell feature.

_update_ps1() {
    PS1="$(powerline $?)"
}
precmd_functions+=(_update_ps1)

fish

You must also compile with bare-shell feature.

function fish_prompt
    powerline $status
end

Custom shell prompt

Simply create new rust program that fulfils your requirements.

use powerline::{modules::*, theme::SimpleTheme};

fn main() {
    let mut prompt = powerline::Powerline::new();

    prompt.add_module(User::<SimpleTheme>::new());
    prompt.add_module(Host::<SimpleTheme>::new());
    prompt.add_module(Cwd::<SimpleTheme>::new(45, 4, false));
    prompt.add_module(Git::<SimpleTheme>::new());
    prompt.add_module(ReadOnly::<SimpleTheme>::new());
    prompt.add_module(Cmd::<SimpleTheme>::new());

    println!("{}", prompt);
}

Tips and trigs

Strip executable

Remove unnecessary symbols from file to greatly reduce size of it. Theoretically it can reduce time of execution.

cd ~/.cargo/bin/
strip powerline

Use LTO and other

# Cargo.toml
[profile.release]
lto = true
panic = 'abort'

Target native

Enables optimizations for your specific processor.

RUSTFLAGS="-C target-cpu=native" cargo ...

Cache untracked files

Git module can be slower on repos with big number of untracked files. Read about caching untracked files here.

Custom theme

use powerline::{modules::*, terminal::Color};

struct Theme;

impl CmdScheme for Theme {
    const CMD_FAILED_BG: Color = Color(161);
    const CMD_FAILED_FG: Color = Color(15);
    const CMD_PASSED_BG: Color = Color(236);
    const CMD_PASSED_FG: Color = Color(15);
}

fn main() {
    let mut prompt = powerline::Powerline::new();
    prompt.add_module(Cmd::<SimpleTheme>::new());

...

powerline-rust's People

Contributors

cirho avatar inamiy avatar jesse-millwood avatar sumanthratna avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

powerline-rust's Issues

Colors and icons not showing in Zsh

When I open a new Terminal window, this is what I see (macOS 10.15.5 Beta):

\[\e[38;5;250m\]\[\e[48;5;240m\] suman \[\e[48;5;238m\]\[\e[38;5;240m\]\[\e[38;5;250m\]\[\e[48;5;238m\] SumanthRatnasAir \[\e[48;5;31m\]\[\e[38;5;238m\]\[\e[38;5;254m\]\[\e[48;5;31m\] ~ \[\e[48;5;236m\]\[\e[38;5;31m\]\[\e[38;5;15m\]\[\e[48;5;236m\] $ \[\e[0m\]\[\e[38;5;236m\]\[\e[0m\] 

Pics Please!!

I think this kind of project deserves a picture or three :)

It may help more with adoption than it maybe should.

I know what powerline-shell looks like, but what does powerline-rust look like?

Give me the choice between easier configuration and slightly faster performance

I want my config to be easy to install.
It would be much more convenient if I could have a file like ~/.config/powerline-rust.yaml.

Proposal: Look for a config file at runtime and use it if present, otherwise use compiled-in default prompt. Checking if a file exists should take negligible time and i'm pretty sure the kernel caches it.

Optional: have a feature which decides whether it even looks for a config file at runtime

If you want the slight speed advantage of a compile-time prompt, then you can compile your prompt in and not have a config file. If you want the easyness of a config file, you can just use the file.

Offer a newline feature before the cmd prompt

Powerline prompts can run long. It is common for users to put the command prompt on the following line.

Unfamiliar with rust, I attempted to do this locally by modifying the cmd $ and # to \n$ and \n#. The result has unwanted background color in the prompt line. It's not clear to me how I should configure the background and foreground to avoid this.

Could a newline 'feature' be made available so that it can be toggled on install?

Branch parsing - Git Segment

Currently regex does not parse branch name correctly.
No information about ahead and behind provided and git repo without commits not working good.

Support RGB color

I would like to see powerline-rust support 24-bit colour, terminal-side support for which is available in popular terminals such as Konsole, xterm, iTerm2, and alacritty.

Color handling

Should be better with some traits and to avoid huge match function.

Git icons not showing properly in Zsh

On macOS 10.15.5 Beta and zsh 5.7.1 (x86_64-apple-darwin19.0), this is what I see:

myterm

This is the output of git status:

On branch master
Your branch is up to date with 'origin/master'.

Changes not staged for commit:
  (use "git add/rm <file>..." to update what will be committed)
  (use "git restore <file>..." to discard changes in working directory)
	deleted:    prompt/powerline-go

Untracked files:
  (use "git add <file>..." to include in what will be committed)
	envvars/cargo
	prompt/powerline-rust

no changes added to commit (use "git add" and/or "git commit -a")

Output looks odd in macOS bash

If I run powerline directly, I get reasonable output, but running from .bash_profile using the recommended approach gives mangled output. You can see both in this screenshot:
Screen Shot 2019-11-08 at 14 39 04

It looks a little like it's returning to the start of line somewhere through the prompt. The behaviour is the same in VS Code terminal and normal macOS terminal.

I've tried some other powerline implementations (e.g. powerline-go) using the same configuration in .bash_profile and they work fine, but I prefer Rust :)

Trying to uninstall breaks the terminal prompt

Hey there,
I was playing around with powerline-rust for a bit now. I tried uninstalling it and it broke the entire prompt. Please refer to the screenshot attached.

image

As you can see from the image, the terminal works but the prompt is broken. It would be great if you could integrate the install function to the repository as well.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.