Integration with the promp
You can benefit from cdir shortcuts and pretty printing to use them into your shell prompt.
This is based on the pretty-print-path command that you can use into the configuration of your prompt manager.
Here is an explanation of this command, and then examples of how to use it into zsh, bash and starship.rs.
The pretty-print-path command
Basics
You can invoke cdir to pretty print a path in the same way as it is displayed into the directory history view.
To do so, you just have to invoke the pretty-print-path command with the path, e.g.:
# Let's assume that the shortcut 'shortcut' = '/the/path/to'
$ cdir pretty-print-path "/the/path/to/pretty/print"
[shortcut]/pretty/print
As shown herebefore, a shortcut substitution has been performed.
The theme colors and styles are also used to pretty print the path exactly in the same way as it is displayed into the directory history view.
Additional options
The pretty-print-path command accept two additional and optional parameters:
First, the color and styles can be removed from the output in order to get a simple string of characters.
To do so, just add the false parameter to the command.
Second, you can limit the max size of the string of characters by providing a numerical value. For instance, to limit the size to 40 characters:
Customizing the zsh prompt
You can integrate cdir directly into your zsh prompt.
Add the following to your .zshrc file:
setopt PROMPT_SUBST
function cdir_prompt() {
cdir pretty-print-path "$PWD"
}
PROMPT='$(cdir_prompt) \$ '
This will display the pretty-printed current directory in your prompt, including shortcut substitutions and theme colors.
After editing .zshrc, reload your shell or run source ~/.zshrc to apply the changes.
Customizing the bash prompt
You can also integrate cdir into your bash prompt. Add the following to your .bashrc file:
This will display the pretty-printed current directory in your prompt, including shortcut substitutions and theme colors.
After editing .bashrc, reload your shell or run source ~/.bashrc to apply the changes.
Integration with starship.rs
In order to use cdir with starship.rs, the Custom commands feature should be used.
Let's define a custom command into the starship.toml configuration file:
Then, adjust the format parameter to replace the ${directory} directive by the ${custom.cdir} one, i.e.:
From:
To: