Skip to content

Commit

Permalink
Updated incon functions, See details below
Browse files Browse the repository at this point in the history
functions/icons.zsh
- changed core icon definitions to use registerIcon()

segments/vcs.p9k
- moved icon override for P9K_HIDE_BRANCH_ICON to this file instead of
in icons.zsh

powerlevel9k.zsh-theme
- changed the sourcing order of icons and utilities so that defined() is
available to registerIcon()
  • Loading branch information
onaforeignshore committed May 4, 2018
1 parent ed890e7 commit 894fa6a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 103 deletions.
132 changes: 34 additions & 98 deletions functions/icons.zsh
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,27 @@
# boxes or bizarre characters below, your fonts are not correctly installed. If
# you do not want to install a special font, you can set `P9K_MODE` to
# `compatible`. This shows all icons in regular symbols.
#
# For specific fonts configurations, please refer to:
# - [Awesome-Patched Font](https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched)
# - [fontconfig with awesome-font](https://github.com/gabrielelana/awesome-terminal-fonts)
# - [mapped fontconfig with awesome-font](https://github.com/gabrielelana/awesome-terminal-fonts) and don't forget
# to source the font maps in your startup script
# - [nerd-font patched (complete)](https://github.com/ryanoasis/nerd-fonts) and the [cheat sheet](http://nerdfonts.com/#cheat-sheet)
# - [Powerline-Patched Font](https://github.com/Lokaltog/powerline-fonts)
##

# Set the right locale to protect special characters
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
typeset -gAH icons

if [[ P9K_MODE == "awesome-mapped-fontconfig" && -z "$AWESOME_GLYPHS_LOADED" ]]; then
echo "Powerlevel9k warning: Awesome-Font mappings have not been loaded.
Source a font mapping in your shell config, per the Awesome-Font docs
(https://github.com/gabrielelana/awesome-terminal-fonts),
or use a different Powerlevel9k font configuration.";
fi

################################################################
# @description
# This function allows a segment to register the icons that it
Expand All @@ -43,7 +60,7 @@ typeset -gAH icons
# @example
# registerIcon "LOCK_ICON" $'\UE0A2' $'\UE138' $'\UF023' '\u'$CODEPOINT_OF_AWESOME_LOCK $'\UF023'
##
registerIcon() {
function registerIcon() {
local map
local ICON_USER_VARIABLE=P9K_${1}
if defined "$ICON_USER_VARIABLE"; then # check for icon override first
Expand All @@ -60,100 +77,22 @@ registerIcon() {
icons[$1]=${map}
}

# Initialize the icon list according to the user's `P9K_MODE`.
typeset -gAH icons
case $P9K_MODE in
'flat'|'awesome-patched')
# Awesome-Patched Font required! See:
# https://github.com/gabrielelana/awesome-terminal-fonts/tree/patching-strategy/patched
# Set the right locale to protect special characters
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
icons=(
LEFT_SEGMENT_SEPARATOR $'\uE0B0' #
RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #
LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace
LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
)
;;
'awesome-fontconfig')
# fontconfig with awesome-font required! See
# https://github.com/gabrielelana/awesome-terminal-fonts
# Set the right locale to protect special characters
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
icons=(
LEFT_SEGMENT_SEPARATOR $'\uE0B0' #
RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #
LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace
LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
)
;;
'awesome-mapped-fontconfig')
# mapped fontconfig with awesome-font required! See
# https://github.com/gabrielelana/awesome-terminal-fonts
# don't forget to source the font maps in your startup script
# Set the right locale to protect special characters
local LC_ALL="" LC_CTYPE="en_US.UTF-8"

if [ -z "$AWESOME_GLYPHS_LOADED" ]; then
echo "Powerlevel9k warning: Awesome-Font mappings have not been loaded.
Source a font mapping in your shell config, per the Awesome-Font docs
(https://github.com/gabrielelana/awesome-terminal-fonts),
Or use a different Powerlevel9k font configuration.";
fi

icons=(
LEFT_SEGMENT_SEPARATOR $'\uE0B0' #
RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #
LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace
LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
)
;;
'nerdfont-complete'|'nerdfont-fontconfig')
# nerd-font patched (complete) font required! See
# https://github.com/ryanoasis/nerd-fonts
# http://nerdfonts.com/#cheat-sheet
# Set the right locale to protect special characters
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
icons=(
LEFT_SEGMENT_SEPARATOR $'\uE0B0' #
RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #
LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace
LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
)
;;
*)
# Powerline-Patched Font required!
# See https://github.com/Lokaltog/powerline-fonts
# Set the right locale to protect special characters
local LC_ALL="" LC_CTYPE="en_US.UTF-8"
icons=(
LEFT_SEGMENT_SEPARATOR $'\uE0B0' #
RIGHT_SEGMENT_SEPARATOR $'\uE0B2' #
LEFT_SEGMENT_END_SEPARATOR ' ' # Whitespace
LEFT_SUBSEGMENT_SEPARATOR $'\uE0B1' #
RIGHT_SUBSEGMENT_SEPARATOR $'\uE0B3' #
MULTILINE_FIRST_PROMPT_PREFIX $'\u256D'$'\U2500' # ╭─
MULTILINE_NEWLINE_PROMPT_PREFIX $'\u251C'$'\U2500' # ├─
MULTILINE_LAST_PROMPT_PREFIX $'\u2570'$'\U2500 ' # ╰─
)
;;
esac
#     
registerIcon "LEFT_SEGMENT_SEPARATOR" $'\uE0B0' $'\uE0B0' $'\uE0B0' $'\uE0B0' $'\uE0B0'
#     
registerIcon "RIGHT_SEGMENT_SEPARATOR" $'\uE0B2' $'\uE0B2' $'\uE0B2' $'\uE0B2' $'\uE0B2'
# Whitespace Whitespace Whitespace Whitespace Whitespace
registerIcon "LEFT_SEGMENT_END_SEPARATOR" ' ' ' ' ' ' ' ' ' '
#     
registerIcon "LEFT_SUBSEGMENT_SEPARATOR" $'\uE0B1' $'\uE0B1' $'\uE0B1' $'\uE0B1' $'\uE0B1'
#     
registerIcon "RIGHT_SUBSEGMENT_SEPARATOR" $'\uE0B3' $'\uE0B3' $'\uE0B3' $'\uE0B3' $'\uE0B3'
# ╭─ ╭─ ╭─ ╭─ ╭─
registerIcon "MULTILINE_FIRST_PROMPT_PREFIX" $'\u256D'$'\U2500' $'\u256D'$'\U2500' $'\u256D'$'\U2500' $'\u256D'$'\U2500' $'\u256D'$'\U2500'
# ├─ ├─ ├─ ├─ ├─
registerIcon "MULTILINE_NEWLINE_PROMPT_PREFIX" $'\u251C'$'\U2500' $'\u251C'$'\U2500' $'\u251C'$'\U2500' $'\u251C'$'\U2500' $'\u251C'$'\U2500'
# ╰─ ╰─ ╰─ ╰─ ╰─
registerIcon "MULTILINE_LAST_PROMPT_PREFIX" $'\u2570'$'\U2500 ' $'\u2570'$'\U2500 ' $'\u2570'$'\U2500 ' $'\u2570'$'\U2500 ' $'\u2570'$'\U2500 '

# Override the above icon settings with any user-defined variables.
case $P9K_MODE in
Expand All @@ -173,9 +112,6 @@ case $P9K_MODE in
;;
esac

# Hide branch icon if user wants it hidden
[[ "$P9K_HIDE_BRANCH_ICON" == true ]] && icons[VCS_BRANCH_ICON]=''

################################################################
# @description
# Prints the requested icon.
Expand Down
8 changes: 4 additions & 4 deletions powerlevel9k.zsh-theme
Original file line number Diff line number Diff line change
Expand Up @@ -47,16 +47,16 @@ else
fi

################################################################
# Source icon functions
# Source utility functions
################################################################

source "${p9kDirectory}/functions/icons.zsh"
source "${p9kDirectory}/functions/utilities.zsh"

################################################################
# Source utility functions
# Source icon functions
################################################################

source "${p9kDirectory}/functions/utilities.zsh"
source "${p9kDirectory}/functions/icons.zsh"

################################################################
# Source color functions
Expand Down
5 changes: 4 additions & 1 deletion segments/vcs.p9k
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,10 @@ registerIcon "VCS_BOOKMARK_ICON" $'\u263F' $'\uE87B' $'\uF27B' '\u'$CODEPOIN
#    
registerIcon "VCS_COMMIT_ICON" '' $'\uE821 ' $'\uF221 ' '\u'$CODEPOINT_OF_OCTICONS_GIT_COMMIT' ' $'\uE729 '

if [[ "$P9K_HIDE_BRANCH_ICON" != true ]]; then
# Hide branch icon if user wants it hidden
if [[ "$P9K_HIDE_BRANCH_ICON" == true ]]; then
icons[VCS_BRANCH_ICON]=''
else
if [[ $P9K_MODE != 'compatible' ]]; then
#     
registerIcon "VCS_BRANCH_ICON" $'\uE0A0 ' $'\uE220 ' $'\uF126 ' '\u'$CODEPOINT_OF_OCTICONS_GIT_BRANCH' ' $'\uF126 '
Expand Down

0 comments on commit 894fa6a

Please sign in to comment.