8000 GitHub - r58Playz/powerline-rust: powerline-shell written in Rust - fork with truecolor support and my opinionated modifications
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

powerline-shell written in Rust - fork with truecolor support and my opinionated modifications

License

Notifications You must be signed in to change notification settings

r58Playz/powerline-rust

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

91 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

powerline-rust

powerline-rust is an alternative to powerline-shell. It's heavily inspired by it, but f 8000 ocuses 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 achieved 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 benefit 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 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

# bash shell 
cargo install --git https://github.com/r58Playz/powerline-rust
# zsh shell 
cargo install --git https://github.com/r58Playz/powerline-rust --no-default-features --features=zsh-shell,libgit
# fish shell
cargo install --git https://github.com/r58Playz/powerline-rust --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 ${PIPESTATUS[@]})"
}

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

zsh

You must also compile with zsh-shell feature.

_update_ps1() {
    PS1="$(powerline ${pipestatus[@]})"
}
precmd_functions+=(_update_ps1)

fish

You must also compile with bare-shell feature.

function fish_prompt
    powerline $pipestatus
end

Custom shell prompt

Simply create a 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 tricks

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(215, 0, 95);
    const CMD_FAILED_FG: Color = Color(255, 255, 255);
    const CMD_PASSED_BG: Color = Color(48, 48, 48);
    const CMD_PASSED_FG: Color = Color(255, 255, 255);
}

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

...

About

powerline-shell written in Rust - fork with truecolor support and my opinionated modifications

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Rust 100.0%
0