1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-11-04 20:37:56 +00:00
The minimal, blazing-fast, and infinitely customizable prompt for any shell!
Go to file
Benjamin Fox 20d845f9b3
refactor(directory): Introduce logical-path argument which allows a shell to explicitly specify both a logical and physical filesystem path (#2104)
* refactor(directory): Introduce `logical-path` argument which allows a shell to explicitly specify both a logical and physical filesystem path

Fix `directory::module` to consume both path and logical-path (if provided).  The "logical" path is preferred when rendering the "display path", while the "physical" path is used to resolve the "read only" flag. Repo- and home-directory contraction behavior is maintained, based on the logical path if it is set, or the physical path if it is not.

The custom "get_current_dir" logic has been removed entirely, and the `directory` module now relies on `context.current_dir` / `context.logical_dir` entirely.

Changes have been made to `init/starship.ps1` to work with this new flag:
- Calculate and pass "physical" and "logical" paths explicitly (as other shells do not pass `--logical-path` that they fall back to rendering the physical path)
- Moved the "powershell provider prefix" cleanup code to the PowerShell script - this code _should_ now support any kind of powershell path prefix.

* fix(powershell): Fix an issue with trailing backslashes on file paths causing command line parsing issues.

This is a bit of a footgun!
The work-around chosen is to append a trailing space when a path string ends with a backslash, and then trim any extra whitespace away in the Context constructor.
Other alternatives considered and rejected:
1. Always trim trailing backslashes as the filesystem generally doesn't need them.
2. Escape trailing backslashes with another backslash. This proved complex as PS only quotes string args when the string includes some whitespace, and other backslashes within the string apparently don't need to be escaped.

* fix(powershell): Use Invoke-Native pattern for safely invoking native executables with strings which may contain characters which need to be escaped carefully.

* fix(context): Remove superfluous argument trims

These were in place to clean up extra whitespace sometimes injected by starship.ps1::prompt, and are no longer required with the new Invoke-Native helper in place.

* refactor(directory): Clean up the semantics of `logical_dir` defaulting it to `current_dir` but overridable by the `--logical-dir` flag.

- Restore `use_logical_path` config flag.
- Always attempt to contract repo paths from the `current_dir`.

* fix(directory) :Use logical_dir for contracting the home directory

This keeps the two calls to contract_path in sync.

* fix(directory): Remove test script

* refactor(directory): Convert current_dir to canonical filesystem path when use_logical_path = false

- This requires some clean-up to remove the extended-path prefix on Windows
- The configured logical_dir is ignored entirely in this mode - we calculate a new logical_dir by cleaning up the physical_dir path for display.
- Test coverage

* fix(directory): Use AsRef style for passing Path arguments

* fix(directory): Strip the windows extended-path prefix from the display string later in the render process

* fix(docs): Update docs/config/README.md for use_logical_path

* refactor(context): Populate `current_dir` from `--path` or `std::env::current_dir`, populate `logical_dir` from `--logical-path` or the `PWD` env var

- `current_dir` is always canonicalized
- On Windows, `current_dir` will have an extended-path prefix
- `logical_dir` is now always set
- `directory::module` now just selects between `current_dir` and `logical_dir` when picking which path to render
- Test coverage

* fix(directory): Fix path comparison operations in directory to ignore differences between path prefixes

- Added PathExt extension trait which adds `normalised_equals`, `normalised_starts_with` and `without_prefix`

* fix(path): Add test coverage for PathExt on *nix

* fix(directory): Test coverage for `contract_repo_path`, `contract_path` with variations of verbatim and non-verbatim paths

* fix(directory): Update path-slash to latest

This fixes the issue with the trailing character of some Windows paths being truncated, e.g. `\\server\share` and `C:`

* fix(powershell): Improve UTF8 output handling, argument encoding

- Use `ProcessStartInfo` to launch native executable, replacing manual UTF8 output encoding handling
- If we detect we're on PWSH6+ use the new `System.Diagnostics.ProcessStartInfo.ArgumentList` parameter, otherwise manually escape the argument string
- Move `Get-Cwd` and `Invoke-Native` into the prompt function scope so that they don't leak into the user's shell scope

* fix(path): Make PathExt methods no-ops on *nix

* fix(path): Cargo fmt

* fix(powershell): Remove typo ';'. Fix variable assignment lint.
2021-02-08 15:14:59 +01:00
.cargo ci: ignore RUSTSEC-2020-0100 (#2179) 2021-01-20 11:01:55 -05:00
.github ci: fix changelog generation (#2267) 2021-02-04 20:29:41 -05:00
docs refactor(directory): Introduce logical-path argument which allows a shell to explicitly specify both a logical and physical filesystem path (#2104) 2021-02-08 15:14:59 +01:00
install build: add x86_64 freebsd build (#2233) 2021-01-30 12:50:38 +01:00
media docs(i18n): add Vietnamese doc translations 2021-01-26 17:25:25 -05:00
src refactor(directory): Introduce logical-path argument which allows a shell to explicitly specify both a logical and physical filesystem path (#2104) 2021-02-08 15:14:59 +01:00
starship_module_config_derive chore(release): release starship_module_config_derive v0.1.2 2020-09-30 16:13:42 -04:00
.gitignore feat(package): Add Maven pom.xml version support (#1511) 2020-07-31 09:54:03 +02:00
.rustfmt.toml style: make rustfmt use the default configuration (#1661) 2020-09-19 08:45:17 +02:00
build.rs build: Add additional build information to version and bug report (#2124) 2021-01-22 20:14:51 +01:00
Cargo.lock build(deps): bump serde_json from 1.0.61 to 1.0.62 2021-02-08 05:45:45 +00:00
Cargo.toml build(deps): bump serde_json from 1.0.61 to 1.0.62 2021-02-08 05:45:45 +00:00
CODE_OF_CONDUCT.md Create CODE_OF_CONDUCT.md (#42) 2019-04-30 23:30:42 -04:00
CONTRIBUTING.md docs: Add note about Crowdin-managed files to CONTRIBUTING.md (#2013) 2020-12-20 19:56:06 -05:00
Cross.toml build: add x86_64 freebsd build (#2233) 2021-01-30 12:50:38 +01:00
crowdin.yml chore: update Crowdin PR title 2021-01-29 16:53:32 -05:00
LICENSE docs: update license to include 2021 (#2207) 2021-01-26 22:43:20 +01:00
README.md feat: add support for elvish shell (#1725) 2021-02-02 12:59:55 +01:00
snapcraft.yaml fix: snap build failure (#1177) 2020-05-06 20:29:09 -04:00

Starship – Cross-shell prompt

GitHub Actions workflow status Crates.io version Packaging status
Chat on Discord Follow @StarshipPrompt on Twitter

Website · Installation · Configuration

English   日本語   繁體中文   Русский   Deutsch   简体中文   Español   Français   Tiếng Việt

Starship with iTerm2 and the Snazzy theme

The minimal, blazing-fast, and infinitely customizable prompt for any shell!

  • Fast: it's fast really really fast! 🚀
  • Customizable: configure every aspect of your prompt.
  • Universal: works on any shell, on any operating system.
  • Intelligent: shows relevant information at a glance.
  • Feature rich: support for all your favorite tools.
  • Easy: quick to install  start using it in minutes.

Explore the Starship docs  ▶

🚀 Installation

Prerequisites

Getting Started

Note: due to the proliferation of different platforms, only a subset of supported platforms are shown below. Can't see yours? Have a look at the extra platform instructions.

  1. Install the starship binary:

    Install Latest Version

    From prebuilt binary, with Shell:
    curl -fsSL https://starship.rs/install.sh | bash
    

    Install via Package Manager

    Example: Homebrew:
    brew install starship
    
    With Scoop:
    scoop install starship
    
  2. Add the init script to your shell's config file:

    Bash

    Add the following to the end of ~/.bashrc:

    # ~/.bashrc
    
    eval "$(starship init bash)"
    

    Fish

    Add the following to the end of ~/.config/fish/config.fish:

    # ~/.config/fish/config.fish
    
    starship init fish | source
    

    Zsh

    Add the following to the end of ~/.zshrc:

    # ~/.zshrc
    
    eval "$(starship init zsh)"
    

    PowerShell

    Add the following to the end of Microsoft.PowerShell_profile.ps1. You can check the location of this file by querying the $PROFILE variable in PowerShell. Typically the path is ~\Documents\PowerShell\Microsoft.PowerShell_profile.ps1 or ~/.config/powershell/Microsoft.PowerShell_profile.ps1 on -Nix.

    Invoke-Expression (&starship init powershell)
    

    Ion

    Add the following to the end of ~/.config/ion/initrc:

    # ~/.config/ion/initrc
    
    eval $(starship init ion)
    

    Elvish

    Warning Only elvish v0.15 or higher is supported. Add the following to the end of ~/.elvish/rc.elv:

    # ~/.elvish/rc.elv
    
    eval (starship init elvish)
    

🤝 Contributing

We are always looking for contributors of all skill levels! If you're looking to ease your way into the project, try out a good first issue.

If you are fluent in a non-English language, we greatly appreciate any help keeping our docs translated and up-to-date in other languages. If you would like to help, translations can be contributed on the Starship Crowdin.

If you are interested in helping contribute to starship, please take a look at our Contributing Guide. Also, feel free to drop into our Discord server and say hi. 👋

Code Contributors

This project exists thanks to all the people who contribute. [Contribute].

Financial Contributors

Become a financial contributor and help us sustain our community. [Contribute]

Individuals

Organizations

Support this project with your organization. Your logo will show up here with a link to your website. [Contribute]

💭 Inspired By

Please check out these previous works that helped inspire the creation of starship. 🙏


Starship rocket icon

📝 License

Copyright © 2019-present, Starship Contributors.
This project is ISC licensed.