aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--CHANGELOG.md7
-rw-r--r--README.md9
-rw-r--r--functions/icons.zsh4
-rw-r--r--functions/utilities.zsh57
-rwxr-xr-xpowerlevel9k.zsh-theme143
5 files changed, 142 insertions, 78 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index ce0fe494..aa1b3aef 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -1,4 +1,9 @@
-## v0.4.0
+## v0.4.0 (next)
+
+### `ram` changes
+
+The `ram` segment was split up into `ram` and `swap`. The `POWERLEVEL9K_RAM_ELEMENTS`
+variable is void.
### New segment `aws_eb_env` added
diff --git a/README.md b/README.md
index c04f5620..1fcd8086 100644
--- a/README.md
+++ b/README.md
@@ -97,12 +97,13 @@ The segments that are currently available are:
* **nvm** - Show the version of Node that is currently active, if it differs from the version used by NVM
* **os_icon** - Display a nice little icon, depending on your operating system.
* **php_version** - Show the current PHP version.
-* [ram](#ram) - Show free RAM and used Swap.
+* **ram** - Show free RAM
* [rbenv](#rbenv) - Ruby environment information (if one is active).
* **root_indicator** - An indicator if the user is root.
* [rspec_stats](#rspec_stats) - Show a ratio of test classes vs code classes for RSpec.
* **rust_version** - Display the current rust version.
* [status](#status) - The return code of the previous command.
+* **swap** - Prints the current swap size.
* [symphony2_tests](#symphony2_tests) - Show a ratio of test classes vs code classes for Symfony2.
* **symphony2_version** - Show the current Symfony2 version, if you are in a Symfony2-Project dir.
* [time](#time) - System time.
@@ -256,12 +257,6 @@ This segment shows the return code of the last command.
|----------|---------------|-------------|
|`POWERLEVEL9K_STATUS_VERBOSE`|`true`|Set to false if you wish to hide this segment when the last command completed successfully.|
-##### ram
-
-| Variable | Default Value | Description |
-|----------|---------------|-------------|
-|`POWERLEVEL9K_RAM_ELEMENTS`|Both|Specify `ram_free` or `swap_used` to only show one or the other rather than both.|
-
##### symphony2_tests
See [Unit Test Ratios](#unit-test-ratios), below.
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..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
+}
diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme
index f8e75b33..f48f97b2 100755
--- a/powerlevel9k.zsh-theme
+++ b/powerlevel9k.zsh-theme
@@ -123,14 +123,20 @@ CURRENT_BG='NONE'
# Takes four arguments:
# * $1: Name of the function that was orginally invoked (mandatory).
# Necessary, to make the dynamic color-overwrite mechanism work.
-# * $2: A flag if the segment should be joined with the previous one.
+# * $2: The array index of the current segment
# * $3: Background color
# * $4: Foreground color
# * $5: The segment content
# * $6: An identifying icon (must be a key of the icons array)
# The latter three can be omitted,
+set_default last_left_element_index 1
set_default POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS " "
left_prompt_segment() {
+ local current_index=$2
+ # Check if the segment should be joined with the previous one
+ local joined
+ segmentShouldBeJoined $current_index $last_left_element_index "$POWERLEVEL9K_LEFT_PROMPT_ELEMENTS" && joined=true || joined=false
+
# Overwrite given background-color by user defined variable for this segment.
local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_BACKGROUND
local BG_COLOR_MODIFIER=${(P)BACKGROUND_USER_VARIABLE}
@@ -145,7 +151,6 @@ left_prompt_segment() {
[[ -n "$3" ]] && bg="%K{$3}" || bg="%k"
[[ -n "$4" ]] && fg="%F{$4}" || fg="%f"
- local joined=$2
if [[ $CURRENT_BG != 'NONE' ]] && ! isSameColor "$3" "$CURRENT_BG"; then
echo -n "$bg%F{$CURRENT_BG}"
if [[ $joined == false ]]; then
@@ -188,6 +193,7 @@ left_prompt_segment() {
echo -n "${POWERLEVEL9K_WHITESPACE_BETWEEN_LEFT_SEGMENTS}"
CURRENT_BG=$3
+ last_left_element_index=$current_index
}
# End the left prompt, closes the final segment.
@@ -207,14 +213,21 @@ CURRENT_RIGHT_BG='NONE'
# Takes four arguments:
# * $1: Name of the function that was orginally invoked (mandatory).
# Necessary, to make the dynamic color-overwrite mechanism work.
-# * $2: A flag if the segment should be joined with the previous one.
+# * $2: The array index of the current segment
# * $3: Background color
# * $4: Foreground color
# * $5: The segment content
# * $6: An identifying icon (must be a key of the icons array)
# No ending for the right prompt segment is needed (unlike the left prompt, above).
+set_default last_right_element_index 1
set_default POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS " "
right_prompt_segment() {
+ local current_index=$2
+
+ # Check if the segment should be joined with the previous one
+ local joined
+ segmentShouldBeJoined $current_index $last_right_element_index "$POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS" && joined=true || joined=false
+
# Overwrite given background-color by user defined variable for this segment.
local BACKGROUND_USER_VARIABLE=POWERLEVEL9K_${(U)1#prompt_}_BACKGROUND
local BG_COLOR_MODIFIER=${(P)BACKGROUND_USER_VARIABLE}
@@ -229,7 +242,6 @@ right_prompt_segment() {
[[ -n "$3" ]] && bg="%K{$3}" || bg="%k"
[[ -n "$4" ]] && fg="%F{$4}" || fg="%f"
- local joined=$2
# If CURRENT_RIGHT_BG is "NONE", we are the first right segment.
if [[ $joined == false ]] || [[ "$CURRENT_RIGHT_BG" == "NONE" ]]; then
if isSameColor "$CURRENT_RIGHT_BG" "$3"; then
@@ -269,6 +281,7 @@ right_prompt_segment() {
echo -n "${visual_identifier}${POWERLEVEL9K_WHITESPACE_BETWEEN_RIGHT_SEGMENTS}%f"
CURRENT_RIGHT_BG=$3
+ last_right_element_index=$current_index
}
################################################################
@@ -283,8 +296,8 @@ CURRENT_BG='NONE'
# AWS Profile
prompt_aws() {
local aws_profile="$AWS_DEFAULT_PROFILE"
- if [[ -n "$aws_profile" ]];
- then
+
+ if [[ -n "$aws_profile" ]]; then
"$1_prompt_segment" "$0" "$2" red white "$aws_profile" 'AWS_ICON'
fi
}
@@ -398,7 +411,9 @@ prompt_battery() {
fi
# Draw the prompt_segment
- [[ -n $bat_percent ]] && "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON'
+ if [[ -n $bat_percent ]]; then
+ "$1_prompt_segment" "${0}_${current_state}" "$2" "$DEFAULT_COLOR" "${battery_states[$current_state]}" "$message" 'BATTERY_ICON'
+ fi
}
# Context: user@hostname (who am I and where am I)
@@ -427,7 +442,7 @@ prompt_dir() {
local current_path='%~'
if [[ -n "$POWERLEVEL9K_SHORTEN_DIR_LENGTH" ]]; then
- set_default POWERLEVEL9K_SHORTEN_DELIMITER ".."
+ set_default POWERLEVEL9K_SHORTEN_DELIMITER $'\U2026'
case "$POWERLEVEL9K_SHORTEN_STRATEGY" in
truncate_middle)
@@ -574,46 +589,18 @@ prompt_php_version() {
# Show free RAM and used Swap
prompt_ram() {
- defined POWERLEVEL9K_RAM_ELEMENTS || POWERLEVEL9K_RAM_ELEMENTS=(ram_free swap_used)
-
- local rendition base
- for element in "${POWERLEVEL9K_RAM_ELEMENTS[@]}"; do
- case $element in
- ram_free)
- if [[ "$OS" == "OSX" ]]; then
- ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+')
- # Convert pages into Bytes
- ramfree=$(( ramfree * 4096 ))
- base=''
- else
- ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
- base=K
- fi
-
- rendition+="$(printSizeHumanReadable "$ramfree" $base) "
- ;;
- swap_used)
- if [[ "$OS" == "OSX" ]]; then
- raw_swap_used=$(sysctl vm.swapusage | grep -o "used\s*=\s*[0-9,.A-Z]*" | grep -o "[0-9,.A-Z]*$")
- typeset -F 2 swap_used
- swap_used=${$(echo $raw_swap_used | grep -o "[0-9,.]*")//,/.}
- # Replace comma
- swap_used=${swap_used//,/.}
-
- base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$")
- else
- swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
- swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
- swap_used=$(( swap_total - swap_free ))
- base=K
- fi
-
- rendition+="$(printSizeHumanReadable "$swap_used" $base) "
- ;;
- esac
- done
+ local base=''
+ local ramfree=0
+ if [[ "$OS" == "OSX" ]]; then
+ ramfree=$(vm_stat | grep "Pages free" | grep -o -E '[0-9]+')
+ # Convert pages into Bytes
+ ramfree=$(( ramfree * 4096 ))
+ else
+ ramfree=$(grep -o -E "MemFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
+ base='K'
+ fi
- "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "${rendition% }" 'RAM_ICON'
+ "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$ramfree" $base)" 'RAM_ICON'
}
# rbenv information
@@ -678,6 +665,30 @@ prompt_status() {
fi
}
+prompt_swap() {
+ local swap_used=0
+ local base=''
+
+ if [[ "$OS" == "OSX" ]]; then
+ local raw_swap_used
+ raw_swap_used=$(sysctl vm.swapusage | grep -o "used\s*=\s*[0-9,.A-Z]*" | grep -o "[0-9,.A-Z]*$")
+
+ typeset -F 2 swap_used
+ swap_used=${$(echo $raw_swap_used | grep -o "[0-9,.]*")//,/.}
+ # Replace comma
+ swap_used=${swap_used//,/.}
+
+ base=$(echo "$raw_swap_used" | grep -o "[A-Z]*$")
+ else
+ swap_total=$(grep -o -E "SwapTotal:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
+ swap_free=$(grep -o -E "SwapFree:\s+[0-9]+" /proc/meminfo | grep -o "[0-9]*")
+ swap_used=$(( swap_total - swap_free ))
+ base='K'
+ fi
+
+ "$1_prompt_segment" "$0" "$2" "yellow" "$DEFAULT_COLOR" "$(printSizeHumanReadable "$swap_used" $base)" 'SWAP_ICON'
+}
+
# Symfony2-PHPUnit test ratio
prompt_symfony2_tests() {
if [[ (-d src && -d app && -f app/AppKernel.php) ]]; then
@@ -761,8 +772,10 @@ prompt_vcs() {
zstyle ':vcs_info:*' stagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_STAGED_ICON')%f"
zstyle ':vcs_info:*' unstagedstr " %F{$POWERLEVEL9K_VCS_FOREGROUND}$(print_icon 'VCS_UNSTAGED_ICON')%f"
- zstyle ':vcs_info:git*+set-message:*' hooks vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname
- zstyle ':vcs_info:hg*+set-message:*' hooks vcs-detect-changes
+ defined POWERLEVEL9K_VCS_GIT_HOOKS || POWERLEVEL9K_VCS_GIT_HOOKS=(vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname)
+ zstyle ':vcs_info:git*+set-message:*' hooks $POWERLEVEL9K_VCS_GIT_HOOKS
+ defined POWERLEVEL9K_VCS_HG_HOOKS || POWERLEVEL9K_VCS_HG_HOOKS=(vcs-detect-changes)
+ zstyle ':vcs_info:hg*+set-message:*' hooks $POWERLEVEL9K_VCS_HG_HOOKS
# For Hg, only show the branch name
zstyle ':vcs_info:hg*:*' branchformat "$(print_icon 'VCS_BRANCH_ICON')%b"
@@ -822,20 +835,20 @@ prompt_virtualenv() {
build_left_prompt() {
defined POWERLEVEL9K_LEFT_PROMPT_ELEMENTS || POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(context dir rbenv vcs)
+ local index=1
for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do
- # Check if the segment should be joined with the previous one
- local joined=false
- if [[ ${element[-7,-1]} == '_joined' ]]; then
- element="${element[0,-8]}"
- joined=true
- fi
+ # Remove joined information in direct calls
+ element=${element%_joined}
+
# Check if it is a custom command, otherwise interpet it as
# a prompt.
if [[ $element[0,7] =~ "custom_" ]]; then
- "prompt_custom" "left" "$joined" $element[8,-1]
+ "prompt_custom" "left" "$index" $element[8,-1]
else
- "prompt_$element" "left" "$joined"
+ "prompt_$element" "left" "$index"
fi
+
+ index=$((index + 1))
done
left_prompt_end
@@ -845,20 +858,20 @@ build_left_prompt() {
build_right_prompt() {
defined POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS || POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=(status root_indicator background_jobs history time)
+ local index=1
for element in "${POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[@]}"; do
- # Check if the segment should be joined with the previous one
- local joined=false
- if [[ ${element[-7,-1]} == '_joined' ]]; then
- element="${element[0,-8]}"
- joined=true
- fi
+ # Remove joined information in direct calls
+ element=${element%_joined}
+
# Check if it is a custom command, otherwise interpet it as
# a prompt.
if [[ $element[0,7] =~ "custom_" ]]; then
- "prompt_custom" "right" "$joined" $element[8,-1]
+ "prompt_custom" "right" "$index" $element[8,-1]
else
- "prompt_$element" "right" "$joined"
+ "prompt_$element" "right" "$index"
fi
+
+ index=$((index + 1))
done
}