diff options
Diffstat (limited to 'functions')
-rw-r--r-- | functions/icons.zsh | 7 | ||||
-rw-r--r-- | functions/utilities.zsh | 57 |
2 files changed, 59 insertions, 5 deletions
diff --git a/functions/icons.zsh b/functions/icons.zsh index aad62dc1..e7dc3bfa 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -29,6 +29,7 @@ case $POWERLEVEL9K_MODE in ROOT_ICON $'\UE801' # RUBY_ICON $'\UE847 ' # AWS_ICON $'\UE895' # + AWS_EB_ICON $'\U1F331 ' # 🌱 BACKGROUND_JOBS_ICON $'\UE82F ' # TEST_ICON $'\UE891' # TODO_ICON $'\U2611' # ☑ @@ -48,7 +49,7 @@ case $POWERLEVEL9K_MODE in FOLDER_ICON $'\UE818' # NETWORK_ICON $'\UE1AD' # LOAD_ICON $'\UE190 ' # - #RAM_ICON $'\UE87D' # + SWAP_ICON $'\UE87D' # RAM_ICON $'\UE1E2 ' # VCS_UNTRACKED_ICON $'\UE16C' # VCS_UNSTAGED_ICON $'\UE17C' # @@ -82,6 +83,7 @@ case $POWERLEVEL9K_MODE in ROOT_ICON $'\uF201' # RUBY_ICON $'\UF219 ' # AWS_ICON $'\UF296' # + AWS_EB_ICON $'\U1F331 ' # 🌱 BACKGROUND_JOBS_ICON $'\UF013 ' # TEST_ICON $'\UF291' # TODO_ICON $'\U2611' # ☑ @@ -101,6 +103,7 @@ case $POWERLEVEL9K_MODE in FOLDER_ICON $'\UF115' # NETWORK_ICON $'\UF09E' # LOAD_ICON $'\UF080 ' # + SWAP_ICON $'\UF0E4' # RAM_ICON $'\UF0E4' # VCS_UNTRACKED_ICON $'\UF059' # VCS_UNSTAGED_ICON $'\UF06A' # @@ -130,6 +133,7 @@ case $POWERLEVEL9K_MODE in ROOT_ICON $'\u26A1' # ⚡ RUBY_ICON '' AWS_ICON 'AWS:' + AWS_EB_ICON $'\U1F331 ' # 🌱 BACKGROUND_JOBS_ICON $'\u2699' # ⚙ TEST_ICON '' TODO_ICON $'\U2611' # ☑ @@ -149,6 +153,7 @@ case $POWERLEVEL9K_MODE in FOLDER_ICON '' NETWORK_ICON 'IP' LOAD_ICON 'L' + SWAP_ICON 'SWP' RAM_ICON 'RAM' VCS_UNTRACKED_ICON '?' VCS_UNSTAGED_ICON $'\u25CF' # ● diff --git a/functions/utilities.zsh b/functions/utilities.zsh index f855caf5..079e675a 100644 --- a/functions/utilities.zsh +++ b/functions/utilities.zsh @@ -60,10 +60,10 @@ printSizeHumanReadable() { # worthy. The callback function has access to # the inner variable $item. function getRelevantItem() { - setopt shwordsplit # We need to split the words in $interfaces - - local list callback - list=$1 + local -a list + local callback + # Explicitly split the elements by whitespace. + list=${=1} callback=$2 for item in $list; do @@ -134,3 +134,52 @@ print_deprecation_warning() { fi done } + +# A helper function to determine if a segment should be +# joined or promoted to a full one. +# Takes three arguments: +# * $1: The array index of the current segment +# * $2: The array index of the last printed segment +# * $3: The array of segments of the left or right prompt +function segmentShouldBeJoined() { + local current_index=$1 + local last_segment_index=$2 + # Explicitly split the elements by whitespace. + local -a elements + elements=${=3} + + local current_segment=${elements[$current_index]} + local joined=false + if [[ ${current_segment[-7,-1]} == '_joined' ]]; then + joined=true + # promote segment to a full one, if the predecessing full segment + # was conditional. So this can only be the case for segments that + # are not our direct predecessor. + if (( $(($current_index - $last_segment_index)) > 1)); then + # Now we have to examine every previous segment, until we reach + # the last printed one (found by its index). This is relevant if + # all previous segments are joined. Then we want to join our + # segment as well. + local examined_index=$((current_index - 1)) + while (( $examined_index > $last_segment_index )); do + local previous_segment=${elements[$examined_index]} + # If one of the examined segments is not joined, then we know + # that the current segment should not be joined, as the target + # segment is the wrong one. + if [[ ${previous_segment[-7,-1]} != '_joined' ]]; then + joined=false + break + fi + examined_index=$((examined_index - 1)) + done + fi + fi + + # Return 1 means error; return 0 means no error. So we have + # to invert $joined + if [[ "$joined" == "true" ]]; then + return 0 + else + return 1 + fi +} |