1
0
mirror of https://github.com/Llewellynvdm/starship.git synced 2024-09-27 12:49:02 +00:00
Commit Graph

79 Commits

Author SHA1 Message Date
David Knaack
1eaf996a36
fix(windows): avoid inadvertly running exes from cwd (#2885)
On Windows when running commands with their name instead of the path with Command::new, executable with that name from the current working directory will be executed.

This PR replaces all instances of Command::new with a new create_command function which will first resolve any executable paths and avoid this issue.
2021-07-16 15:20:59 -04:00
David Knaack
cea1a1ceb1
feat: add support for nu shell (#2847) 2021-07-04 15:32:58 -04:00
David Knaack
436eb61efd
test: allow running tests as root (#2571) 2021-04-10 19:05:46 +02:00
Thomas O'Donnell
7779ed6075
style(directory): Add comments for test settings (#2538)
Have added some comments to explain the settings we are using in some
tests.
2021-04-02 06:18:40 +02:00
David Knaack
9d15eb135b
test(directory): fix on windows without admin (#2497) 2021-03-31 18:00:24 +02:00
David Knaack
d14736dbfe
fix(directory): contract git repo with display path (#2304) 2021-02-14 18:15:47 +01:00
David Knaack
5ee09aa4dd
fix(directory): Handle non-UTF-8 folder names (#2303) 2021-02-13 19:32:18 +01:00
David Knaack
04d1332f9c
refactor(clippy): fix new lints (#2297) 2021-02-11 21:08:17 +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
d3002cf961
test: avoid setting $HOME (#2155)
* test: avoid setting $HOME

* add comment to get_home

* move everything to context.get_home
2021-01-19 23:23:27 +01:00
David Knaack
4de9e43cff
fix(directory): preserve substitution order (#1782) 2020-10-13 15:06:41 -04:00
David Knaack
7c941af11a
feat(directory): strip Microsoft.PowerShell.Core\FileSystem:: prefix on windows (#1732) 2020-10-06 09:44:27 +02: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
Tilmann Meyer
2233683410
feat: add error messaging (#1576)
This creates a custom logger for the log crate which logs everything to a file (/tmp/starship/session_$STARSHIP_SESSION_KEY.log) and it logs everything above Warn to stderr, but only if the log file does not contain the line that should be logged resulting in an error or warning to be only logged at the first starship invocation after opening the shell.
2020-09-28 16:38:50 -04:00
David Knaack
0912ed0058
fix(test/dir): make lock thread-safe (#1575)
* fix(test/dir): make lock thread-safe

* stronger ordering
2020-08-14 18:58:53 +02:00
Tilmann Meyer
88b603be38
test: introduce env variable mocking (#1490) 2020-08-07 15:13:12 -04:00
David Knaack
36ae36282a
refactor(directory/lock): fix clippy, replace str with Path (#1544) 2020-08-02 18:42:38 +02:00
Alexey Chernyshov
fbaeef8589
Do not check readonly on network locations (#1506)
Do not try to analyze if the current process can write network location
on Windows. There's no way on Windows to tell if we can write a network
location because it's not being controlled by the OS itself. Thus now
the lock symbol is never shown on network locations.  

This PR introduces a new unsafe call.
2020-07-30 11:22:19 -05: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
dependabot-preview[bot]
f9bf2324e2
build(deps): bump path-slash from 0.1.1 to 0.1.2 (#1377)
* build(deps): bump path-slash from 0.1.1 to 0.1.2

Bumps [path-slash](https://github.com/rhysd/path-slash) from 0.1.1 to 0.1.2.
- [Release notes](https://github.com/rhysd/path-slash/releases)
- [Changelog](https://github.com/rhysd/path-slash/blob/master/CHANGELOG.md)
- [Commits](https://github.com/rhysd/path-slash/compare/0.1.1...v0.1.2)

Signed-off-by: dependabot-preview[bot] <support@dependabot.com>

* Fix tests to improve slash handling on Windows

* Fix number of slashes

* Try fixing the slashes again

Co-authored-by: dependabot-preview[bot] <27856297+dependabot-preview[bot]@users.noreply.github.com>
Co-authored-by: Matan Kushner <hello@matchai.dev>
2020-06-22 18:41:05 -04:00
Julian Gehring
d21cb62e3a
Replace dirs with dirs-next dependency (#1361)
`dirs` will be unmaintained for the foreseeable future, so
switch to the maintained fork `dirs-next`.

Closes #1319.
2020-06-20 12:59:35 -05:00
SeongChan Lee
611a754ec7
fix(directory): Fix path contractions for symlinked git repos (#1299)
Fixes git repo path contractions in two situations:

1. When path obtained from `PWD` is a logical path but git libraries
   return physical paths.
2. When a git repository's subdirectory is symlinked to ouside of the
   repository tree.

(1) is fixed by implementing a realpath()-like function, then reparsing
the (possibly logical) `PWD` using realpath() to convert logical
components into physical ones. The physical paths are then matched
against each other.

In the case of (2), the default behavior has been changed by simply
contracting to the home directory, exactly the same as if we are not in
a repo at all. Because determining the correct contraction is not
obvious, we bail out and just pretend we are not in a repo at all.
2020-06-17 22:44:51 -05: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
Jean Gautier
02edad0c66
fix(directory): avoid confusing modules with PowerShell paths (#1114)
* Avoid confusing modules with PowerShell paths

* Avoid confusing modules with PowerShell paths

Powershell supports PSDrives (https://docs.microsoft.com/en-us/powershell/module/microsoft.powershell.management/new-psdrive?view=powershell-7) that allow to create "logical" drives mapped to actual Windows drives.

* Preserve Windows directories

* Preserve logical paths for Powershell

* Fix formating with cargo fmt

* Fix directory_in_root test

Co-authored-by: Jean Gautier <jean.gautier@ssi.gouv.fr>
2020-04-30 10:40:56 +02:00
AppleTheGolden
3c835ba34b fix: Truncate long paths in conda environment names (#694)
Environment names created via conda create -p [path] tend to be too long for comfort, so this truncates them.
2019-12-09 12:59:02 -05:00
Dan Wendorf
dee25c7b35 feat: Add prefix config to directory module (#642) 2019-12-06 14:19:11 -05:00
Raidou
2a75a18eb1 fix: Fix panic when using fish-style pwd with unicode symbols (#672) 2019-11-29 00:02:22 -05:00
Zhenhui Xie
aa260899d4 fix: Use logical path instead of physical path when available (#398)
* Get pathbuf from logical path. (fixes #204)

(also fixes #397)

* fix: Update directory module so that use_logical_path will work properly

* Remove test directory::use_logical_and_physical_paths

* Fix merge errors


Co-authored-by: Matan Kushner <hello@matchai.me>
2019-10-24 19:37:44 +09:00
Clément Joly
7e21f5c6b6 Refactor: Remove unnecessary parentheses in if condition (#566) 2019-10-20 17:36:02 +09: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
Keith Wade
10efe3e320 fix: Show leading slash when truncating from root (#526) 2019-10-15 00:12:43 +09:00
Matan Kushner
05210b9510
refactor: Go from Rust workspaces to a package with nested packages (#480) 2019-10-04 22:30:46 +09:00
Zhenhui Xie
dd0b1a1aa2 refactor: Refactoring config (#383)
This PR refactors config and puts configuration files for all modules in `configs/`.
2019-09-30 21:10:35 +09:00
yuri
63a45d01f9 feat: Use tilde for home_directory when under version control (#439) 2019-09-28 22:50:38 -05:00
Kevin Song
c2875d99b6 feat: add support for logical paths in directory (#366)
Adds the ability for starship to display the logical path instead of the physical path.
2019-09-20 12:28:09 -04:00
Neil Kistner
cd892ebb60 fix: fish_pwd option handles repeated directories properly (#399) 2019-09-20 10:37:55 -04:00
Neil Kistner
9f70ffb7a7 fix: Lazy load git repo and only run module if not disabled (#306)
A couple of optimizations are done in this PR. One, we now will check config ahead of time to see if a module is disabled before running any module code. Also, we won't try to discover a git repository unless the module requests access to it.
2019-09-09 19:14:38 -04:00
Kevin Song
9721666d33
feat: Add the ability to configure per-module color styles (#285)
Add parsing logic, config support, docs, and integration with other modules 
for custom styling of each module.
2019-09-07 19:33:06 -05:00
Neil Kistner
e034253a5e feat: Add ability to use an alternate directory truncation style (#239)
* Add ability to use an alternate directory truncation style
2019-08-26 21:52:45 -04:00
Saghm Rossi
84c394e7b0 feat: Add option to control git directory truncation (#165) 2019-08-16 20:29:22 -07:00
Saghm Rossi
5ad07bf2d9 docs: Fix typo in directory module description (#163) 2019-08-16 14:16:29 -04:00
Matan Kushner
f40f73dc8e fix: Address longstanding linter errors 2019-08-05 11:05:08 -04:00
Andrew Dassonville
5dbf4381ac feat: Allow directory truncation length to be configured (#120)
This allows the directory truncation length to be configured. Previously, it was hard-coded to truncate to 3 parent directories.
2019-07-28 21:05:13 -04:00
Andrew Dassonville
75e74e0d74 feat: Use Unix-style slash on Windows (#119)
Prior to this change, starship would use inconsistent slashes when displaying the working directory. With this change, starship uses Unix-style slashes on all platforms. This is consistent with the Git Bash and Cygwin prompts on Windows.
2019-07-28 20:15:40 -04:00
Tiffany Le-Nguyen
08cf33522a docs: Add vuepress with initial docs (#99)
Co-authored-by: Tiffany Le-Nguyen <tlenguyen@expedia.com>
Co-authored-by: Matan Kushner <hello@matchai.me>
2019-07-19 16:18:52 -04:00
Matan Kushner
0703a74048
ci: Add GitHub releases to CI (#95) 2019-07-14 17:54:45 -04:00
Matan Kushner
77ba97df19
chore: Refactor getting string values from config (#94) 2019-07-14 11:15:47 -04:00