Files
starship/docs/fr-FR/advanced-config/README.md
T

204 lines
8.6 KiB
Markdown
Raw Normal View History

# Configuration avancée
2020-09-30 16:26:13 -04:00
Même si Starship est un shell polyvalent, éditer `starship.toml` ne suffit parfois pas pour faire certaines choses. Cette page détaille quelques techniques de configuration avancées utilisées dans starship.
::: warning
2020-09-30 16:26:13 -04:00
Les configurations dans cette section sont sujettes à modification dans les futures versions de Starship.
:::
2022-01-15 17:08:31 -05:00
## Custom pre-prompt and pre-execution Commands in Cmd
2022-01-15 17:08:31 -05:00
Clink provides extremely flexible APIs to run pre-prompt and pre-exec commands in Cmd shell. It is fairly simple to use with Starship. Make the following changes to your `starship.lua` file as per your requirements:
2022-01-15 17:08:31 -05:00
- To run a custom function right before the prompt is drawn, define a new function called `starship_preprompt_user_func`. This function receives the current prompt as a string that you can utilize. For example, to draw a rocket before the prompt, you would do
```lua
function starship_preprompt_user_func(prompt)
print("🚀")
end
load(io.popen('starship init cmd'):read("*a"))()
```
- To run a custom function right before a command is executed, define a new function called `starship_precmd_user_func`. This function receives the current commandline as a string that you can utilize. For example, to print the command that's about to be executed, you would do
```lua
function starship_precmd_user_func(line)
print("Executing: "..line)
end
load(io.popen('starship init cmd'):read("*a"))()
```
2022-02-07 15:53:55 +01:00
## Commandes pré-commande et pré-exécution personnalisées en Bash
2022-01-15 17:08:31 -05:00
2022-02-07 15:53:55 +01:00
Bash n'a pas de structure officielle préexec/précmd comme la plupart des autres shells. C'est pourquoi il est difficile de fournir des hooks entièrement personnalisables dans `bash`. Cependant, Starship vous permet dans une certaine mesure d'insérer vos propres fonctions dans la procédure de rendu du prompt :
2022-01-15 17:08:31 -05:00
2022-02-07 15:53:55 +01:00
- Pour exécuter une fonction personnalisée juste avant que le prompt ne soit dessiné, définissez une nouvelle fonction et assignez son nom à `starship_precmd_user_func`. Par exemple, pour dessiner une fusée avant la commande, vous feriez
```bash
function blastoff(){
echo "🚀"
}
starship_precmd_user_func="blastoff"
```
2022-02-07 15:53:55 +01:00
- Pour exécuter une fonction personnalisée juste avant l'exécution d'une commande, vous pouvez utiliser le [ mécanisme d'interruption du signal ` DEBUG`](https://jichu4n.com/posts/debug-trap-and-prompt_command-in-bash/). Cependant, vous **devez** piéger le signal DEBUG _avant_ l'initialisation de Starship ! Starship peut préserver la valeur du piège DEBUG, mais si le piège est écrasé après le démarrage de Starship, certaines fonctionnalités vont casser.
```bash
function blastoff(){
echo "🚀"
}
2022-01-15 17:08:31 -05:00
trap blastoff DEBUG # Trap DEBUG *before* running starship
2022-02-07 15:53:55 +01:00
set -o functrace
eval $(starship init bash)
2022-02-07 15:53:55 +01:00
set +o functrace
```
2022-02-07 15:53:55 +01:00
## Commandes pré-invite et pré-exécution personnalisées dans PowerShell
2022-02-07 15:53:55 +01:00
Powershell n'a pas de système de préexec/précmd officiel comme la plupart des autres shells. C'est pourquoi il est difficile de fournir des hooks entièrement personnalisables dans `powershell`. Cependant, Starship vous permet dans une certaine mesure d'insérer vos propres fonctions dans la procédure de rendu du prompt :
2022-02-07 15:53:55 +01:00
Créez une fonction nommée `Invoke-Starship-PreCommand`
2021-11-07 18:07:39 +00:00
```powershell
function Invoke-Starship-PreCommand {
$host.ui.Write("🚀")
}
```
2022-02-07 15:53:55 +01:00
## Changer le titre de la fenêtre
2021-11-07 18:07:39 +00:00
2022-02-07 15:53:55 +01:00
Certaines commandes du shell changeront automatiquement le titre de la fenêtre (par exemple, pour refléter votre répertoire de travail). Fish le fait même par défaut. Starship does not do this, but it's fairly straightforward to add this functionality to `bash`, `zsh`, `cmd` or `powershell`.
2021-11-07 18:07:39 +00:00
2022-02-07 15:53:55 +01:00
Tout d'abord, définissez une fonction de changement de titre de fenêtre (identique en bash et zsh) :
```bash
2022-02-07 15:53:55 +01:00
function set_titre_fenetre(){
echo -ne "\033]0; VOTRE_TITRE_ICI\007"
}
```
2022-02-07 15:53:55 +01:00
Vous pouvez utiliser des variables pour personnaliser ce titre (`$USER`, `$HOSTNAME`, et `$PWD` sont des choix populaires).
2022-02-07 15:53:55 +01:00
Dans `bash`, définissez cette fonction comme la fonction précommande Starship :
```bash
2022-02-07 15:53:55 +01:00
starship_precmd_user_func="set_titre_fenetre"
```
2022-02-07 15:53:55 +01:00
Dans `zsh`, ajoutez ceci au tableau `precmd_functions` :
```bash
2022-02-07 15:53:55 +01:00
precmd_functions+=(set_titre_fenetre)
```
2022-02-07 15:53:55 +01:00
Si vous aimez le résultat, ajoutez ces lignes à votre fichier de configuration shell (`~/.bashrc` ou `~/.zshrc`) pour le rendre permanent.
2022-02-07 15:53:55 +01:00
Par exemple, si vous voulez afficher votre répertoire actuel dans le titre de l'onglet de votre terminal, ajoutez le code suivant à votre `~/.bashrc` ou `~/.zshrc`:
```bash
function set_win_title(){
2021-04-05 10:55:57 -04:00
echo -ne "\033]0; $(basename "$PWD") \007"
}
starship_precmd_user_func="set_win_title"
```
2022-01-15 17:08:31 -05:00
For Cmd, you can change the window title using the `starship_preprompt_user_func` function.
```lua
function starship_preprompt_user_func(prompt)
console.settitle(os.getenv('USERNAME').."@"..os.getenv('COMPUTERNAME')..": "..os.getcwd())
end
load(io.popen('starship init cmd'):read("*a"))()
```
2021-11-07 18:07:39 +00:00
You can also set a similar output with PowerShell by creating a function named `Invoke-Starship-PreCommand`.
```powershell
# edit $PROFILE
function Invoke-Starship-PreCommand {
$host.ui.Write("`e]0; PS> $env:USERNAME@$env:COMPUTERNAME`: $pwd `a")
}
Invoke-Expression (&starship init powershell)
```
2022-02-07 15:53:55 +01:00
## Mettre linvite à droite
2021-09-21 09:36:29 -04:00
Some shells support a right prompt which renders on the same line as the input. Starship can set the content of the right prompt using the `right_format` option. Any module that can be used in `format` is also supported in `right_format`. The `$all` variable will only contain modules not explicitly used in either `format` or `right_format`.
Note: The right prompt is a single line following the input location. To right align modules above the input line in a multi-line prompt, see the [fill module](/config/#fill).
2022-01-15 17:08:31 -05:00
`right_format` is currently supported for the following shells: elvish, fish, zsh, xonsh, cmd.
2021-09-21 09:36:29 -04:00
### Exemple
```toml
# ~/.config/starship.toml
2022-02-07 15:53:55 +01:00
# Une invite minimale à gauche
2021-09-21 09:36:29 -04:00
format = """$character"""
2022-02-07 15:53:55 +01:00
# déplace le reste de linvite à droite
2021-09-21 09:36:29 -04:00
right_format = """$all"""
```
2022-02-07 15:53:55 +01:00
Génère linvite suivante:
2021-09-21 09:36:29 -04:00
```
▶ starship on  rprompt [!] is 📦 v0.57.0 via 🦀 v1.54.0 took 17s
```
2022-02-07 15:53:55 +01:00
## Invite de continuation
2022-01-15 17:08:31 -05:00
Some shells support a continuation prompt along with the normal prompt. This prompt is rendered instead of the normal prompt when the user has entered an incomplete statement (such as a single left parenthesis or quote).
Starship can set the continuation prompt using the `continuation_prompt` option. The default prompt is `"[∙](bright-black) "`.
Note: `continuation_prompt` should be set to a literal string without any variables.
Note: Continuation prompts are only available in the following shells:
2022-02-07 15:53:55 +01:00
- `bash`
- `zsh`
- `PowerShell`
2022-01-15 17:08:31 -05:00
### Exemple
```toml
# ~/.config/starship.toml
# A continuation prompt that displays two filled in arrows
continuation_prompt = "▶▶"
```
2021-09-21 09:36:29 -04:00
## Chaînes de style
2022-02-07 15:53:55 +01:00
Les chaînes de style sont une liste de mots, séparés par des espaces blancs. Les mots ne sont pas sensibles à la casse (` bold ` et ` boLd ` sont considérés comme la même string). Chaque mot peut être l'un des suivants :
2022-02-07 15:53:55 +01:00
- `bold`
- `italic (italique)`
- `underline`
- `dimmed`
- `inverted`
- `bg:<couleur>`
- `fg:<couleur>`
- `<couleur>`
- `none`
2022-02-07 15:53:55 +01:00
`<color>` est un spécificateur de couleur (discuté ci-dessous). `fg:<color>` et `<color>` font actuellement la même chose, bien que cela puisse changer dans le futur. `inverted` permute les couleurs de fond et de premier plan. L'ordre des mots dans le string n'a pas d'importance.
2022-02-07 15:53:55 +01:00
La valeur `none` remplace toutes les autres valeurs si elle n'est pas incluse dans un spécificateur `bg:`, de sorte que par exemple `fg: red none fg:blue` créera une chaîne sans style. `bg:none` définit l'arrière plan sur la couleur par défaut, donc `fg:red bg:none` est équivalent à `red` ou `fg:red` et `bg:green fg:red bg:none` est aussi équivalent à `fg:red` ou `red`. Il peut devenir une erreur d'utiliser `none` en conjonction avec d'autres jetons dans le futur.
2022-02-07 15:53:55 +01:00
Un spécificateur de couleur peut être l'un des éléments suivants :
2022-02-07 15:53:55 +01:00
- One of the standard terminal colors: `black`, `red`, `green`, `blue`, `yellow`, `purple`, `cyan`, `white`. You can optionally prefix these with `bright-` to get the bright version (e.g. `bright-white`).
- Un `#` suivi d'un nombre hexadécimal de six chiffres. Ceci spécifie un [ Code hexadécimal de couleur RVB ](https://www.w3schools.com/colors/colors_hexadecimal.asp).
- Un nombre entre 0 et 255. Ceci spécifie un [code de couleur ANSI 8 bits](https://i.stack.imgur.com/KTSQa.png).
2022-02-07 15:53:55 +01:00
Si plusieurs couleurs sont spécifiées pour le premier plan/arrière-plan, la dernière dans le string prendra la priorité.