aboutsummaryrefslogtreecommitdiff
path: root/functions
diff options
context:
space:
mode:
Diffstat (limited to 'functions')
-rw-r--r--functions/icons.zsh4
-rw-r--r--functions/utilities.zsh60
-rw-r--r--functions/vcs.zsh31
3 files changed, 80 insertions, 15 deletions
diff --git a/functions/icons.zsh b/functions/icons.zsh
index 1eaef3d6..e7dc3bfa 100644
--- a/functions/icons.zsh
+++ b/functions/icons.zsh
@@ -49,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' # 
@@ -103,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' # 
@@ -152,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..5ca5b431 100644
--- a/functions/utilities.zsh
+++ b/functions/utilities.zsh
@@ -27,6 +27,9 @@ function set_default() {
}
# Converts large memory values into a human-readable unit (e.g., bytes --> GB)
+# Takes two arguments:
+# * $size - The number which should be prettified
+# * $base - The base of the number (default Bytes)
printSizeHumanReadable() {
typeset -F 2 size
size="$1"+0.00001
@@ -60,10 +63,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 +137,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
+}
diff --git a/functions/vcs.zsh b/functions/vcs.zsh
index 4a0a7ead..9baccd24 100644
--- a/functions/vcs.zsh
+++ b/functions/vcs.zsh
@@ -6,10 +6,22 @@
# https://github.com/bhilburn/powerlevel9k
################################################################
+set_default POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY true
function +vi-git-untracked() {
+ # TODO: check git >= 1.7.2 - see function git_compare_version()
+ local FLAGS
+ FLAGS=('--porcelain')
+
+ if [[ "$POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY" == "false" ]]; then
+ FLAGS+='--ignore-submodules=dirty'
+ fi
+
if [[ $(git rev-parse --is-inside-work-tree 2> /dev/null) == 'true' && \
- -n $(git ls-files --others --exclude-standard | sed q) ]]; then
- hook_com[unstaged]+=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_UNTRACKED_ICON')%f"
+ -n $(git status ${FLAGS} | grep -E '^??' 2> /dev/null | tail -n1) ]]; then
+ hook_com[unstaged]+=" $(print_icon 'VCS_UNTRACKED_ICON')"
+ VCS_WORKDIR_HALF_DIRTY=true
+ else
+ VCS_WORKDIR_HALF_DIRTY=false
fi
}
@@ -22,12 +34,12 @@ function +vi-git-aheadbehind() {
# for git prior to 1.7
# ahead=$(git rev-list origin/${branch_name}..HEAD | wc -l)
ahead=$(git rev-list "${branch_name}"@{upstream}..HEAD 2>/dev/null | wc -l)
- (( ahead )) && gitstatus+=( " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}%f" )
+ (( ahead )) && gitstatus+=( " $(print_icon 'VCS_OUTGOING_CHANGES_ICON')${ahead// /}" )
# for git prior to 1.7
# behind=$(git rev-list HEAD..origin/${branch_name} | wc -l)
behind=$(git rev-list HEAD.."${branch_name}"@{upstream} 2>/dev/null | wc -l)
- (( behind )) && gitstatus+=( " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}%f" )
+ (( behind )) && gitstatus+=( " $(print_icon 'VCS_INCOMING_CHANGES_ICON')${behind// /}" )
hook_com[misc]+=${(j::)gitstatus}
}
@@ -39,12 +51,12 @@ function +vi-git-remotebranch() {
remote=${$(git rev-parse --verify HEAD@{upstream} --symbolic-full-name 2>/dev/null)/refs\/(remotes|heads)\/}
branch_name=$(git symbolic-ref --short HEAD 2>/dev/null)
- hook_com[branch]="%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}%f"
+ hook_com[branch]="$(print_icon 'VCS_BRANCH_ICON')${hook_com[branch]}"
# Always show the remote
#if [[ -n ${remote} ]] ; then
# Only show the remote if it differs from the local
if [[ -n ${remote} ]] && [[ "${remote#*/}" != "${branch_name}" ]] ; then
- hook_com[branch]+="%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_REMOTE_BRANCH_ICON')%f%F{$POWERLEVEL9K_VCS_FOREGROUND}${remote// /}%f"
+ hook_com[branch]+="$(print_icon 'VCS_REMOTE_BRANCH_ICON')${remote// /}"
fi
}
@@ -52,7 +64,7 @@ function +vi-git-tagname() {
local tag
tag=$(git describe --tags --exact-match HEAD 2>/dev/null)
- [[ -n "${tag}" ]] && hook_com[branch]="%F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_TAG_ICON')${tag}%f"
+ [[ -n "${tag}" ]] && hook_com[branch]="$(print_icon 'VCS_TAG_ICON')${tag}"
}
# Show count of stashed changes
@@ -62,13 +74,13 @@ function +vi-git-stash() {
if [[ -s $(git rev-parse --git-dir)/refs/stash ]] ; then
stashes=$(git stash list 2>/dev/null | wc -l)
- hook_com[misc]+=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_STASH_ICON')${stashes// /}%f"
+ hook_com[misc]+=" $(print_icon 'VCS_STASH_ICON')${stashes// /}"
fi
}
function +vi-hg-bookmarks() {
if [[ -n "${hgbmarks[@]}" ]]; then
- hook_com[hg-bookmark-string]=" %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_BOOKMARK_ICON')${hgbmarks[@]}%f"
+ hook_com[hg-bookmark-string]=" $(print_icon 'VCS_BOOKMARK_ICON')${hgbmarks[@]}"
# To signal that we want to use the sting we just generated, set the special
# variable `ret' to something other than the default zero:
@@ -90,4 +102,3 @@ function +vi-vcs-detect-changes() {
VCS_WORKDIR_DIRTY=false
fi
}
-