Skip to content

Commit

Permalink
Merge pull request agnoster#91 from apodkutin/customize-prompt
Browse files Browse the repository at this point in the history
Add the prompt view customization ability
  • Loading branch information
agnoster authored Nov 4, 2018
2 parents 3ad94b6 + 9ab0556 commit 6bba672
Show file tree
Hide file tree
Showing 3 changed files with 61 additions and 6 deletions.
47 changes: 47 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,53 @@ To test if your terminal and font support it, check that all the necessary chara

![Screenshot](https://gist.githubusercontent.com/agnoster/3712874/raw/screenshot.png)

## Customize your prompt view

By default prompt has these segments: `prompt_status`, `prompt_context`, `prompt_virtualenv`, `prompt_dir`, `prompt_git`, `prompt_end` in that particular order.

If you want to add, change the order or remove some segments of the prompt, you can use array environment variable named `AGNOSTER_PROMPT_SEGMENTS`.

Examples:
- Show all segments of the prompt with indices:
```
echo "${(F)AGNOSTER_PROMPT_SEGMENTS[@]}" | cat -n
```
- Add the new segment of the prompt to the beginning:
```
AGNOSTER_PROMPT_SEGMENTS=("prompt_git" "${AGNOSTER_PROMPT_SEGMENTS[@]}")
```
- Add the new segment of the prompt to the end:
```
AGNOSTER_PROMPT_SEGMENTS+="prompt_end"
```
- Insert the new segment of the prompt = `PROMPT_SEGMENT_NAME` on the particular position = `PROMPT_SEGMENT_POSITION`:
```
PROMPT_SEGMENT_POSITION=5 PROMPT_SEGMENT_NAME="prompt_end";\
AGNOSTER_PROMPT_SEGMENTS=("${AGNOSTER_PROMPT_SEGMENTS[@]:0:$PROMPT_SEGMENT_POSITION-1}" "$PROMPT_SEGMENT_NAME" "${AGNOSTER_PROMPT_SEGMENTS[@]:$PROMPT_SEGMENT_POSITION-1}");\
unset PROMPT_SEGMENT_POSITION PROMPT_SEGMENT_NAME
```
- Swap segments 4th and 5th:
```
SWAP_SEGMENTS=(4 5);\
TMP_VAR="$AGNOSTER_PROMPT_SEGMENTS[$SWAP_SEGMENTS[1]]"; AGNOSTER_PROMPT_SEGMENTS[$SWAP_SEGMENTS[1]]="$AGNOSTER_PROMPT_SEGMENTS[$SWAP_SEGMENTS[2]]"; AGNOSTER_PROMPT_SEGMENTS[$SWAP_SEGMENTS[2]]="$TMP_VAR"
unset SWAP_SEGMENTS TMP_VAR
```
- Remove the 5th segment:
```
AGNOSTER_PROMPT_SEGMENTS[5]=
```

A small demo of the dummy custom prompt segment, which has been created with help of the built-in `prompt_segment()` function from Agnoster theme:
```
# prompt_segment() - Takes two arguments, background and foreground.
# Both can be omitted, rendering default background/foreground.
customize_agnoster() {
prompt_segment 'red' '' ' ⚙ ⚡⚡⚡ ⚙ '
}
```
![Customization demo](https://github.com/apodkutin/agnoster-zsh-theme/raw/customize-prompt/agnoster_customization.gif)

## Future Work

I don't want to clutter it up too much, but I am toying with the idea of adding RVM (ruby version) and n (node.js version) display.
Expand Down
20 changes: 14 additions & 6 deletions agnoster.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,17 @@
# jobs are running in this shell will all be displayed automatically when
# appropriate.

### Segments of the prompt, default order declaration

typeset -aHg AGNOSTER_PROMPT_SEGMENTS=(
prompt_status
prompt_context
prompt_virtualenv
prompt_dir
prompt_git
prompt_end
)

### Segment drawing
# A few utility functions to make it easy and re-usable to draw segmented prompts

Expand Down Expand Up @@ -135,12 +146,9 @@ prompt_virtualenv() {
prompt_agnoster_main() {
RETVAL=$?
CURRENT_BG='NONE'
prompt_status
prompt_context
prompt_virtualenv
prompt_dir
prompt_git
prompt_end
for prompt_segment in "${AGNOSTER_PROMPT_SEGMENTS[@]}"; do
[[ -n $prompt_segment ]] && $prompt_segment
done
}

prompt_agnoster_precmd() {
Expand Down
Binary file added agnoster_customization.gif
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 6bba672

Please sign in to comment.