diff --git a/README.md b/README.md index a45667e4..dd3cbb5e 100644 --- a/README.md +++ b/README.md @@ -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. diff --git a/agnoster.zsh-theme b/agnoster.zsh-theme index 4eceafdc..d156340f 100644 --- a/agnoster.zsh-theme +++ b/agnoster.zsh-theme @@ -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 @@ -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() { diff --git a/agnoster_customization.gif b/agnoster_customization.gif new file mode 100644 index 00000000..2e472d32 Binary files /dev/null and b/agnoster_customization.gif differ