* Add CMakeCache.txt to cmake module
* Remove trailing whitespace
* Apply fixes by @andytom
* Add CMakeCache.txt to docs
* Revert documentation for languages other than en
* [f]Use_global_dollar_hook_for_lastExitCodeForPrompt Switched to use the dollar hook, as source of truth for exit code of las command, included comments to clarify.
* fix: Adjusted accordingly to comments on PR.
* fix: Moved last exit code handling inside if to reuse that variable.
Co-authored-by: Marcos Quezada Perez <marcos.quezadaperez@peakwork.com>
Have refactored the kubernetes module to better support stacked
kubeconfigs. Rather than trying to grab both the current-context and
namespace on a single pass we now do two passes. These changes should
fix the problems where the current-context is defined in one file but
the context and the namespace are defined in a different file.
Have switched to use a monotonic clock for calculating the timeout when
indexing the current directory for the context to avoid any issues with
calculating the timeout when the systems clock might change.
* fix: rust modules are compiled twice
The modules being declared both in the _library_ crate and the _binary_
crate made cargo compile everything twice:
1. for the library
2. for the binary
What happened was:
1. The library "starship" was compiled.
2. The binary "starship" (and all its modules) were compiled.
* fix: stop compiling every rust module twice
restrict visibility
* Run cargo fmt
* Add bug_report module
Co-authored-by: Matan Kushner <hello@matchai.dev>
Co-authored-by: Kevin Song <chips@ksong.dev>
When running the AWS module it will parse the AWS config found in
`~/.aws/config` to get the region. This means that tests that expect no
region to be set will fail if there exists a default profile with a
region set, which is probably true for most AWS users. To avoid this
have set the AWS tests that depend on the non-existance of a
`.aws/config` to be ignored.
Have added a little bit more context to the error messages that occur
when if starship is unable to setup the logger. This should hopefully
make it a bit easier to work out why starship can't setup the logger.
* ✨ Add --prompt rendering to python virtualenv
* Use pyvenv.cfg to find prompt
* Remove usage of VIRTUAL_ENV_PROMPT variable
Seeing how both venv and virtualenv set a pyvenv.cfg, this isn't needed.
Additionally pyvenv.cfg is set in earlier versions than VIRTUAL_ENV_PROMPT,
which at this moment is in the unrelased python 3.10
* Smarter result unwrapping thanks to clippy
Some users have commit.gpgSign set to true in their global git config,
causing tests which run `git commit` to fail if the configured
user.signingKey is not present (as is often the case with PGP smart
cards). Passing this flag overrides the global git configuration,
preventing git from attempting sign the specified commit. This change
has no effect on users who haven't set commit.gpgSign to true.
Have reduced the log level when we fail to execute a command since this
is happening a lot more that expected, for example if a user checks out
a repo that contains a `.js` file but they don't have node installed.
The tests for git-state assume the default branch is `master`.
In git 2.28 support for a global option, `init.defaultBranch`, to
change the default branch name which causes git-state tests to fail.
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.
The default `disabled: true` is actually only available within the module (when the config struct is used and not the user toml) but not all (the hg_branch) modules checked it there again.
Document this in all places and add the check (+ test) to the hg_branch module.
* add the exit code module
this allows to display more precisely the last command exit code
and to configure starship to not change the last charcter of the
prompt even in case of failure. It is disabled by default, because
it seems a bit redundant with the character module in its default
configuration.
* rename exit_code module to status
* Enforce a default disabled=true
In the outer places, we only check for the disabled flag in the config toml file, only when this is loaded into the real config struct, we see the default. And if the default is true, we have to abort at that place. For status and hg_branch that wasn't so. I also commented the rest
* fix spaces in markdown table for status module
* Add a tip that status module is disabled by default
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
* Remove unrelated changes for default disabled=true
Co-authored-by: Gaëtan Lehmann <gaetan.lehmann@gmail.com>
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
* feat: Add computational duration to all computed modules
This also means that in case we do some computations and these end up empty, we submit an empty module
* feat: Add timings subcommand
This outputs the timings of all computed modules, sorted by the duration it took to compute the module.
Useful for debugging why the prompt takes so long.
* feat: Add timings to explain output
* fix: Ensure that even empty custom modules get timings
* format main.rs
* feat: Only show interesting timings
* fix(tests): Change tests to look for empty string instead of None
* Use proper wording in timings help
* Revert "fix(tests): Change tests to look for empty string instead of None"
This reverts commit aca5bd1b03c48e1dee1b7ca91d66e2bda2d5a97c.
* fix(tests): Returning None in case the module produced an empty string
* fix: Ensure that linebreaks (and space) make a module not-empty
* Make cargo clippy happy
* Make Module.duration a proper Duration
* Only return a module if we would report it
* Change to cleaner way to return None for empty modules
* Avoid unnecessary module creation
* Simplify a string comparison
* Add timings to trace
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
Have restored the `pyenv_prefix` option to the python module. This is
added as a new variable that will only be shown if `pyenv` is being used
to determine the version of python that is being used.
Previously the prompt function used in PowerShell would overwrite the $LASTEXITCODE and $? automatic variables that were set by the previous command run the user in the shell. This results in surprising behavior for the user if they inspect those variables looking for the result of the command they last ran.
This fixes the bug reported here: https://github.com/starship/starship/issues/1051
And goes further to also propagate the $? automatic variable which is not mentioned in that bug.
Previously, all modules would have prefixes, which lead to the first
module having a dangling prefix. This change ensures that the first
few modules would instead have suffixes so that we don't start or
end with a prefix or suffix.
* docs: Clarify that commands will be passed in on stdin
* docs: Clearer instruction how to include individual custom modules
* docs: Include link to #1252 in docs for custom modules
That issue is used to share custom modules.
* docs: Remove reference to prompt_order
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
Convert-Path in the powershell prompt script works with -Path,
which interprets paths as wildcard patterns.
Not all valid paths are also valid wildcard patterns, possibly causing
the prompt to error (eg []*).
Replace it with -LiteralPath that makes Convert-Path use the path as-is.
Often it is handy to get notified when the execution of a command finished.
This commit includes notify-rust in order to generate a desktop notification
when a command execution finished.
* fix(explain): align table correctly
* iterate over lines directly
* calculate desc_width with the actual space available
* custom unicode-aware textwrapping
* fix clippy error
* better width estimination
* explain +6
* move padding width into a constant
* initial commit of support for shlvl
* documentation for shlvl
* use a symbol instead
* test coverage for shlvl
* actually disable when the config says to
* fix docs
* tweak defaults some
* refactor from pr comments
* redisable
* return early to avoid indenting
* make default suffix empty space
* fixing tests after suffix change
* updating docs for format
* making shlvl compatible with formatting
* adding variables table for shlvl
* removing extra line
* doc clarity
* Add gitignore for Emacs backup files.
* Add package version support for Maven pom.xml.
* Update docs with Maven package version support.
* Fix for clippy.
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.
* refactor(java): parse version using regex
Mock java version retrieval & extend java module test suite with
rendering tests.
* chore: remove nom crate
* fix(java): support parsing version from both stdout & stderr
* fix(java): fix java command mock
* refactor(java): simplify version regex
* Remove renames_index_to_workdir() option from git status
This option causes advanced files rename detection which causes inconsistency between `git status` and Starship reports.
Closes #1371
* add test for manually remaned and deleted files in git_state module
* fix tests
A recent refactor of modules to use format strings accidentally got rid
of the `trim()` on the NodeJS version string. This just adds it back so
that the prompt doesn't include an unnecessary line break when showing
that module.
Given how slow the Haskell module is (#1240), it is slowing down the entire prompt
from rendering when the module is active. This commit removes the module until we
can find a faster way to retreive the Haskell version.
* Git branch: read from HEAD on newly init repo
On a newly initialized git repo, there are no branches created until a
commit is made. Previously, starship handled this by having a default
branch "master" for when branch `head` could not be read.
However, if a user wants to set a different default branch name, that
name won't appear on starship until a commit is made to the branch.
If git2 provides a way to read the default branch name, we can use that,
but at the moment it's not obvious how.
For the moment, we can directly read `.git/HEAD`, which contains the
name of the default branch head reference. This commit implements this
strategy.
Closes #1327
* update git_branch test from unborn master to unborn default
* cargo fmt
Have switched the fallback shell used when the custom module can't use
the default to use `/usr/bin/env sh` rather than `/bin/env` since
`/usr/bin/env` is more commonly available.
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.
* Add option to change the python binary
We are going to start to have problems with the python binary as python2
is removed and replaced with python3. To make the transition easier I
have added an option to the python module to allow the user to pick a
particular binary, e.g `python3`, for the module to use when selecting
the version of python. I have also refactored the python tests moving
almost all of them into the module and removing the dependency on the
version of python that is installed on the system.
* Add advanced config section to python module docs
Have added an advanced config section to the python module docs and
moved the `python_binary` option into that section.
PHP will output error messages when displaying the version if, for
example, there is something wrong with the local `php.ini` file. Have
updated the command used to get the PHP version to only use the default
PHP config.
* Nim module and tests
* Add nim to docs
* parse_nim_version refactor, add nim desc
* Add nim symbol to Nerd Font preset
* Yellow with v prefix as default version
* Nim version fmt fix
* Update docs/config/README.md
Co-authored-by: Dario Vladović <d.vladimyr@gmail.com>
* Update src/modules/nim.rs
Co-authored-by: Dario Vladović <d.vladimyr@gmail.com>
* Nim module and tests
* Add nim to docs
* Yellow with v prefix as default version
* Update docs/config/README.md
Co-authored-by: Dario Vladović <d.vladimyr@gmail.com>
* Update src/modules/nim.rs
Co-authored-by: Dario Vladović <d.vladimyr@gmail.com>
* Add nim to docs, proper version formatting.
* Remove v from symbol, add to fmt string
* cargo fmt
Co-authored-by: Dario Vladovic <d.vladimyr@gmail.com>
* Creation of range field in TimeConfig
* time_range parsing
* Hide time module if outside of time_range
* Tidying of code, and properly handling more cases
* is_inside_time_range function
* Tests and fmt
* Update docs
* The configuration needs the 24-hours format
* Fix clippy errors
To improve overall support of PowerShell in custom modules,
the ability to pass arguments to the shell was also added. Additionally,
the arguments `-NoProfile -Command -` will be automatically passed
to PowerShell, unless other arguments are given by the user.
* Added configs/purescript
* Added modules/purescript
* Added necessary codes
* Added tests
* Updated README
* Fixed color because black is hard to see
* Fixed of push mistake
* Fixed pointed out in PR
* 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>
* feat: Modify config keys from shell
* chore: Fix clippy
* refactor: Add `configure` as alias
* chore: Remove redundant code
* fix: Soft error if user doesn't pass in valid key
* feat: Support integers and booleans
* chore: Fix clippy
* refactor: Use exit instead of abort
Co-Authored-By: Thomas O'Donnell <andytom@users.noreply.github.com>
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
According by this standards
> While "Julia" is a female name in many parts of the world, the programming language is not a person and does not have a gender.
* Use AWS_VAULT as the profile if set
[aws-vault](https://github.com/99designs/aws-vault) sets
the `AWS_VAULT` env var instead of `AWS_PROFILE` when an
aws-vault session is active.
This PR adds support for reading the AWS profile value from
the `AWS_VAULT` env var, giving priority to `AWS_VAULT` if both
it and `AWS_PROFILE` are set.
* Update docs for AWS_VAULT
* feat: add docker context module
Adds a simple module that checks for a Docker config file and if present, reads the `currentContext` value out and displays on the prompt with a whale.
* feat: add `only_with_compose_yml` option to docker_context
When enabled, will only show the docker context name if there's a docker-compose.yml file in the current directory.
* Update src/modules/docker_context.rs
Co-Authored-By: Thomas O'Donnell <andytom@users.noreply.github.com>
* Update src/modules/docker_context.rs
Co-Authored-By: Thomas O'Donnell <andytom@users.noreply.github.com>
* rename `only_with_compose_yml` configuration key to a more generic `only_with_files`
* Update src/modules/docker_context.rs
Co-Authored-By: Thomas O'Donnell <andytom@users.noreply.github.com>
* re-order configuration table
* Update docs/config/README.md
Co-Authored-By: Thomas O'Donnell <andytom@users.noreply.github.com>
* Update src/configs/docker_context.rs
Co-Authored-By: Thomas O'Donnell <andytom@users.noreply.github.com>
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
* Allow kubernetes module to use aliases for contexts
* documentation for kubernetes context aliasing
* Apply suggestions from code review: consistent ordering of options in documentation
Co-Authored-By: Thomas O'Donnell <andytom@users.noreply.github.com>
Co-authored-by: Thomas O'Donnell <andytom@users.noreply.github.com>
* fix: check if editor is not found for `configure`
STD_EDITOR falls back on `vi` if $EDITOR and $VISUAL is not set.
However, some machines might not have `vi` symlinked or installed and a
bad error message is displayed. This commit adds a better error message.
* fix lint errors
* Change NotFound to write to stderr instead of panic!
Oh wow writing rust makes my commit messages look very enthusiastic!
`private: true` in `package.json` files means that the package is not supposed to be published to npm, which makes the `version` field meaningless, so we should probably ignore it to not clutter the prompt too much.
This PR adds package version support for Gradle projects. The version number is extracted from the `build.gradle` file in the current directory, similar to existing support for other packages.
Replaces the existing nodejs module end-to-end tests with integration tests that don't require preinstalled environmental dependencies.
- Moved the tests to the same file as the module they test
- Created a render_module utility function for rendering modules within tests
- Removed Node.js installation during CI setup
- Add Shell to Context to allow for tests to not run shell-specific code
Currently the Java module detection looks for build.gradle specifically, but it's possible to rename build.gradle to *.gradle. This change adds Gradle files to the list of detected file extensions.
perf: don't use hg process to get branch / bookmark information, each call was taking 250ms and it was making on average 2 calls.
the branch and bookmark information is available in files in the root of the repo, use that instead.
now takes 300 micro seconds
fix: do not use .hgignore to decide if it is an hg repo. was providing false positives. #721
fix: after changing branch the new branch was not show (the old branch was shown), the new branch is now correctly shown. #722
fix: if no branch override was set it would say (no branch) however if you commited in that state you would commit to the branch default so say that instead
This adds a sub command to generate the link. Information, such as operating system and it's version; the current shell's config; and current starship conf, is gathered from the environment and is included in the pre-filled text. The command will also try to open the link in the default browser. Should that fail it will print the link instead and ask the user to copy it.
This PR tries to improve the version detection across multiple Java VM vendors. The module captures both STDOUT and STDERR outputs of the java -Xinternalversion call.
Eclipse OpenJ9, Azul Zulu, SapMachine, Amazon Corretto and GraalVM outputs are unit tested now.
* 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>
Also addresses a number of bugs:
- the percent sign not displaying correctly on some terminal emulators, including kitty
- changing the symbol in the configuration file didn't do anything
- swap being shown even if the system didn't have any
This removes ArgMatches from the Context struct and replaces it with a simple HashMap. This work is towards getting Starship in a better place for use as a library in other shells written in Rust so they don't need to use a command-line interface to invoke and configure things.
Contributes to #521
This updates the default AWS default symbol to include a space after the
symbol to make it a little bit more readable. Have also updated the
README to include the AWS module.
Structure the prompt as a function that returns a string instead of writing directly to stdout.
This makes it easier to embed Starship into other Rust programs such as shells written in Rust. It also decouples the arguments from the context for more programmatic initialization of the context.
Implements the Default trait for SegmentConfig to clean up construction of empty segments.
Also adds a segment::new() function to ease construction of simple segments.
Given the global nature of the Kubernetes module, the module has been disabled by default. The opportunity has also been taken to refactor the Kubernetes module to use the new config module.
Adds the ability to style individual segments in the prompt.
The segment documentation is not fully updated in this commit and is waiting on
a config refactor so that we can write unified docs.
Prevents the rust module from installing rustup toolchains.
Previously, the rust module would trigger rustup toolchain installations in some cases,
leading to frozen prompts while rustup downloads/installs components. This commit
changes the behaviour to avoid this.
- Replaced for loop that iterates over mutable state with a fold expression
- Unified the logging for the different accessors. The code is now screaming for further refactoring (get_module_config, get_as_bool, get_as_str, get_as_i64 and get_as_array are basically the same up to higher order functions but I didn't manage to get the life times right)
- Increased test coverage (especially a test case for none not at the end)
- Removed code comments that literally repeated the code in the next line (see e.g. https://blog.usejournal.com/stop-writing-code-comments-28fef5272752)
- Added TODO for the problematic line that swallows the None and produces Some(Style::new()) (this also happened before but in a less obvious way)
Previously, a set of empty segments would cause the module to print. This changes the
logic of Module::is_empty to check that all the segments are empty instead.
Shell inits are now in a separate directory in the source code, with each shell getting its own script. Also adds a little DRY + commenting in init/mod.rs.
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.
Add a configuration option (show_sync_count) to the git_status module that will show/hide the counts ahead/behind of the tracked branch. Currently have this default to false, and would opt-in to show this information.
Migrated CI from Azure Pipelines to GitHub Actions.
Until the release process is figured out in Actions, we'll stick to using Azure pipelines for releases.
Git branches can become very long (e.g. gitlab auto-generated branch
names), thus it would be nice to be able to truncate them to keep your
prompt lenght in line.
This patch adds two new options to the git_branch module:
* truncation_length: The amount of graphemes to of a gitbranch to
truncate to
* truncation_symbol: The symbol that should be used to indicate that a
branch name was trunctated
To be able to correctly work with UTF-8 graphemes, unicode-segmentation
was added as a dependency.
Implement a two-phase init procedure in starship. The first phase causes the shell to source a subshell, while the second phase (in the subshell) prints the main init script.
This allows us to have nice init scripts with good styling, comments, and no pile of semicolons. Even better, it works as a drop-in replacement, so we don't need to update the docs.
Solves the issue of cursor location confusion on bash and zsh (#110) . Solution: modify ANSIString and wrap non-printing characters with correct escape sequences.
MacOS wc has a habit of leaving nasty spaces in the output, which was
messing up our argparser.
To fix, quote the output from the jobs command, then have Rust trim out
whitespace in the jobs module before parsing.
Implement a timer module that takes a commandline argument, the number of seconds the last job took to complete, and displays it if appropriate.
Alters shell initialization files to compute this number using date +%s where needed.
Adds a config section to configure minimum amount of time before timer is shown (default is 2s)
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.