1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-06-27 20:13:30 +00:00
Commit Graph

14 Commits

Author SHA1 Message Date
Segev Finer
1c305c9de7
feat(directory): Windows path formatting via path_slash::PathBufExt (#3157)
* feat: Experimental Windows path formatting via path_slash::PathBufExt

* Rework the slash path conversion into a real PR

* Add a test for convert_slash = false

* Attempt fixing CI failures

* Fix lint and fmt

* Fix docs/config/README.md getting messed up

* Rename convert_slash/from_slash

* Move convert_path_sep calls in tests

* Keep path_vec immutable

* Run rustfmt
2021-12-30 09:57:13 +01:00
t-mangoe
b07abc990e
feat: style git repo root (#2010) 2021-11-09 14:12:40 -05:00
David Knaack
d06ba072a8
feat(config): allow printing default and computed config (#2521)
* feat: allow printing default and computed config

* fix custom modules

* actually fix custom modules
2021-03-31 17:31:55 +02:00
David Knaack
052b56fe10
refactor: replace RootModuleConfig with Default (#2458) 2021-03-15 11:40:52 +01:00
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
Rodrigo Suárez
ca36d15acd
feat(directory): Add home directory symbol (#2198)
* feat(directory): Add home directory symbol

* Replace HOME_SYMBOL constant as a config variable
2021-01-24 22:50:37 +01:00
David Knaack
4de9e43cff
fix(directory): preserve substitution order (#1782) 2020-10-13 15:06:41 -04:00
Jeremy Hilliker
1673d565f4
feat(directory): add ellipsis to truncated paths (#1563)
Adds ellipsis in front of truncated paths: …/
Configurable through new config option: directory.truncation_symbol
Fixes #1162, #1626
2020-10-03 11:25:21 -05:00
David Knaack
b633248606
fix(readonly): change module to match docs (#1728) 2020-10-02 13:10:46 -04:00
Alexey Chernyshov
57c39437bc
feat(directory): Show lock symbol if current directory is read only (#1298)
Add feature to display icon if current directory is read-only.
2020-07-13 16:55:42 -05:00
Zhenhui Xie
ec76fafff0
feat: refactor modules to use format strings (#1374) 2020-07-07 18:45:32 -04:00
Radu Butoi
ab1c3d1c54
feat(directory): Add directory substitutions (#1183)
Adds an option to provide a table of strings to substitute in the
directory string. Fixes #1065.

Co-authored-by: Radu Butoi <butoi@google.com>
2020-05-31 19:32:35 +02:00
Dan Wendorf
dee25c7b35 feat: Add prefix config to directory module (#642) 2019-12-06 14:19:11 -05:00
Zhenhui Xie
be2d5cf1cd refactor: Rewrite cmd_duration, directory and env_var module to use module config (#460)
This PR is a batched rewrite of the following modules:
- cmd_duration
- directory
- env_var
2019-10-15 20:34:48 +09:00