1
Fork 0
mirror of https://github.com/RGBCube/nu_scripts synced 2025-08-02 07:07:46 +00:00

feat: add example for starship and shell_space (#320)

This commit is contained in:
Access 2022-12-01 21:01:15 +08:00 committed by GitHub
parent 8aec0bcc57
commit 3451c3f0e0
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
5 changed files with 54 additions and 0 deletions

View file

@ -3,3 +3,25 @@
### Definition
These scripts should be used to draw a custom command prompt in nushell. They can include anything that we think is appropriate for prompts such as `git` commands, `starship`, `oh-my-posh`, etc.
#### starship.nu
File is in [starship](./starship.nu)
This discribe how to use starship to make a leftprompt, the repo of starship is [here](https://github.com/starship/starship).
This script set the output of starship as leftprompt
![starshipshow](./images/starship.png)
#### shell_space.nu
File is in [shell_space](./shell_space.nu)
Use the function of shells in nu, you can view the fucntion with the command following
```
help shells
```
![shell_spaceshow](./images/shell_space.png)

Binary file not shown.

After

Width:  |  Height:  |  Size: 5.2 KiB

BIN
prompt/images/starship.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 20 KiB

21
prompt/shell_space.nu Normal file
View file

@ -0,0 +1,21 @@
# use shells to to show workspaces
def workspaces [] {
shells | each {|item index|
if $item.active {
$"(ansi green)($index) "
} else {
$"(ansi blue)($index) "
}
}| str collect
}
def create_right_prompt [] {
let time_segment = ([
(date now | date format '%r'),
" ",
(workspaces)
] | str collect)
$time_segment
}
let-env PROMPT_COMMAND_RIGHT = { create_right_prompt }

11
prompt/starship.nu Normal file
View file

@ -0,0 +1,11 @@
def create_left_prompt [] {
^starship prompt --cmd-duration $env.CMD_DURATION_MS $'--status=($env.LAST_EXIT_CODE)'
}
let-env PROMPT_COMMAND = { create_left_prompt }
# avoid same PROMPT_INDICATOR
let-env PROMPT_INDICATOR = { "" }
let-env PROMPT_INDICATOR_VI_INSERT = { ": " }
let-env PROMPT_INDICATOR_VI_NORMAL = { "〉" }
let-env PROMPT_MULTILINE_INDICATOR = { "::: " }