diff options
-rw-r--r-- | .gitignore | 1 | ||||
-rw-r--r-- | README.md | 11 | ||||
-rw-r--r-- | functions/icons.zsh | 8 | ||||
-rwxr-xr-x | powerlevel9k.zsh-theme | 70 | ||||
-rwxr-xr-x | test/segments/vcs.spec | 6 |
5 files changed, 56 insertions, 40 deletions
@@ -1 +1,2 @@ test-vm/.vagrant +*.swp @@ -407,7 +407,7 @@ You can also configure the `dir` segment to show when you are in a directory wit | Variable | Default Value | Description | |----------|---------------|-------------| -|`POWERLEVEL9K_DIR_SHOW_WRITABLE`|`false`|If set to `true` and you are in a directory that you do not have write permissions for, this segment will display a lock icon and enter the `NOT_WRITABLE` state (which can be customized per [our usual process](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization). Note that this functionality is also available in a separate segment, `dir_writable`.| +|`POWERLEVEL9K_DIR_SHOW_WRITABLE`|`false`|If set to `true` and you are in a directory that you do not have write permissions for, this segment will display a lock icon and enter the `NOT_WRITABLE` state (which can be customized per [our usual process](https://github.com/bhilburn/powerlevel9k/wiki/Stylizing-Your-Prompt#segment-color-customization)). Note that this functionality is also available in a separate segment, `dir_writable`.| ##### disk_usage @@ -436,8 +436,8 @@ POWERLEVEL9K_HOST_TEMPLATE="%2m" By default, LOCAL hosts will show the host icon and remote hosts will show the SSH icon. You can override them by setting ``` -POWERLEVEL9K_HOST_ICON="\uF109 " # -POWERLEVEL9K_SSH_ICON="\uF489 " # +POWERLEVEL9K_HOST_ICON="\uF109 " +POWERLEVEL9K_SSH_ICON="\uF489 " ``` @@ -451,7 +451,7 @@ specify the correct network interface by setting: |----------|---------------|-------------| |`POWERLEVEL9K_IP_INTERFACE`|None|The NIC for which you wish to display the IP address. Example: `eth0`.| -##### vpn +##### vpn_ip This segment tries to extract the VPN related IP addresses from nmcli, based on the NIC type: @@ -582,6 +582,9 @@ customization is provided via: |`POWERLEVEL9K_CHANGESET_HASH_LENGTH`|`12`|How many characters of the hash / changeset to display in the segment.| |`POWERLEVEL9K_VCS_SHOW_SUBMODULE_DIRTY`|`true`|Set to `false` to not reflect submodule status in the top-level repository prompt.| |`POWERLEVEL9K_VCS_HIDE_TAGS`|`false`|Set to `true` to stop tags being displayed in the segment.| +|`POWERLEVEL9K_VCS_GIT_HOOKS`|`(vcs-detect-changes git-untracked git-aheadbehind git-stash git-remotebranch git-tagname)`|Layout of the segment for git repositories.| +|`POWERLEVEL9K_VCS_HG_HOOKS`|`(vcs-detect-changes)`|Layout of the segment for Mercurial repositories.| +|`POWERLEVEL9K_VCS_SVN_HOOKS`|`(vcs-detect-changes svn-detect-changes)`|Layout of the segment for SVN repositories.| ##### vcs symbols diff --git a/functions/icons.zsh b/functions/icons.zsh index 3a4909f7..7124386b 100644 --- a/functions/icons.zsh +++ b/functions/icons.zsh @@ -69,7 +69,7 @@ case $POWERLEVEL9K_MODE in VCS_TAG_ICON $'\uE817 ' # VCS_BOOKMARK_ICON $'\uE87B' # VCS_COMMIT_ICON $'\uE821 ' # - VCS_BRANCH_ICON $'\uE220' # + VCS_BRANCH_ICON $'\uE220 ' # VCS_REMOTE_BRANCH_ICON $'\u2192' # → VCS_GIT_ICON $'\uE20E ' # VCS_GIT_GITHUB_ICON $'\uE20E ' # @@ -140,7 +140,7 @@ case $POWERLEVEL9K_MODE in VCS_TAG_ICON $'\uF217 ' # VCS_BOOKMARK_ICON $'\uF27B' # VCS_COMMIT_ICON $'\uF221 ' # - VCS_BRANCH_ICON $'\uF126' # + VCS_BRANCH_ICON $'\uF126 ' # VCS_REMOTE_BRANCH_ICON $'\u2192' # → VCS_GIT_ICON $'\uF1D3 ' # VCS_GIT_GITHUB_ICON $'\uF113 ' # @@ -153,7 +153,7 @@ case $POWERLEVEL9K_MODE in SWIFT_ICON '' GO_ICON '' PUBLIC_IP_ICON '' - LOCK_ICON $'\UE138' # + LOCK_ICON $'\UF023' # EXECUTION_TIME_ICON $'\uF253' SSH_ICON '(ssh)' VPN_ICON $'\uF023' @@ -282,7 +282,7 @@ case $POWERLEVEL9K_MODE in VCS_TAG_ICON '' VCS_BOOKMARK_ICON $'\u263F' # ☿ VCS_COMMIT_ICON '' - VCS_BRANCH_ICON $'\uE0A0' # + VCS_BRANCH_ICON $'\uE0A0 ' # VCS_REMOTE_BRANCH_ICON $'\u2192' # → VCS_GIT_ICON '' VCS_GIT_GITHUB_ICON '' diff --git a/powerlevel9k.zsh-theme b/powerlevel9k.zsh-theme index 5ba9e43d..f33d5a9a 100755 --- a/powerlevel9k.zsh-theme +++ b/powerlevel9k.zsh-theme @@ -507,7 +507,11 @@ prompt_public_ip() { if [[ -f $POWERLEVEL9K_PUBLIC_IP_FILE ]]; then typeset -i timediff # if saved IP is more than - timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s))) + if [[ "$OS" == "OSX" ]]; then + timediff=$(($(date +%s) - $(stat -f "%m" $POWERLEVEL9K_PUBLIC_IP_FILE))) + else + timediff=$(($(date +%s) - $(date -r $POWERLEVEL9K_PUBLIC_IP_FILE +%s))) + fi [[ $timediff -gt $POWERLEVEL9K_PUBLIC_IP_TIMEOUT ]] && refresh_ip=true # If tmp file is empty get a fresh IP [[ -z $(cat $POWERLEVEL9K_PUBLIC_IP_FILE) ]] && refresh_ip=true @@ -570,7 +574,7 @@ prompt_context() { local content="" - if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_CONTEXT" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]] || [[ -n "$SSH_CLIENT" || -n "$SSH_TTY" ]]; then if [[ $(print -P "%#") == '#' ]]; then current_state="ROOT" @@ -579,7 +583,7 @@ prompt_context() { content="${POWERLEVEL9K_CONTEXT_TEMPLATE}" elif [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]]; then - content="$USER" + content="$(whoami)" else return fi @@ -594,7 +598,7 @@ set_default POWERLEVEL9K_USER_TEMPLATE "%n" prompt_user() { local current_state="DEFAULT" typeset -AH user_state - if [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]] || [[ "$USER" != "$DEFAULT_USER" ]]; then + if [[ "$POWERLEVEL9K_ALWAYS_SHOW_USER" == true ]] || [[ "$(whoami)" != "$DEFAULT_USER" ]]; then if [[ $(print -P "%#") == '#' ]]; then user_state=( "STATE" "ROOT" @@ -606,7 +610,7 @@ prompt_user() { else user_state=( "STATE" "DEFAULT" - "CONTENT" "$USER" + "CONTENT" "$(whoami)" "BACKGROUND_COLOR" "${DEFAULT_COLOR}" "FOREGROUND_COLOR" "011" "VISUAL_IDENTIFIER" "USER_ICON" @@ -932,13 +936,14 @@ prompt_vpn_ip() { done } +set_default POWERLEVEL9K_LOAD_WHICH 5 prompt_load() { # The load segment can have three different states local current_state="unknown" + local load_select=2 + local load_avg local cores - set_default POWERLEVEL9K_LOAD_WHICH 5 - typeset -AH load_states load_states=( 'critical' 'red' @@ -946,32 +951,38 @@ prompt_load() { 'normal' 'green' ) - if [[ "$OS" == "OSX" ]] || [[ "$OS" == "BSD" ]]; then - - if [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 1 ]]; then - load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 1p) - elif [[ "$POWERLEVEL9K_LOAD_WHICH" -eq 5 ]]; then - load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 2p) - else - load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | head -n 3 | sed -n 3p) - fi + case "$POWERLEVEL9K_LOAD_WHICH" in + 1) + load_select=1 + ;; + 5) + load_select=2 + ;; + 15) + load_select=3 + ;; + esac - if [[ "$OS" == "OSX" ]]; then - cores=$(sysctl -n hw.logicalcpu) - else - cores=$(sysctl -n hw.ncpu) - fi - else - load_avg=$(grep -o "[0-9.]*" /proc/loadavg | head -n 1) - cores=$(nproc) - fi + case "$OS" in + OSX|BSD) + load_avg=$(sysctl vm.loadavg | grep -o -E '[0-9]+(\.|,)[0-9]+' | sed -n ${load_select}p) + if [[ "$OS" == "OSX" ]]; then + cores=$(sysctl -n hw.logicalcpu) + else + cores=$(sysctl -n hw.ncpu) + fi + ;; + *) + load_avg=$(cut -d" " -f${load_select} /proc/loadavg) + cores=$(nproc) + esac # Replace comma load_avg=${load_avg//,/.} if [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.7") ]]; then current_state="critical" -elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then + elif [[ "$load_avg" -gt $(bc -l <<< "${cores} * 0.5") ]]; then current_state="warning" else current_state="normal" @@ -1321,7 +1332,7 @@ powerlevel9k_vcs_init() { prompt_vcs() { VCS_WORKDIR_DIRTY=false VCS_WORKDIR_HALF_DIRTY=false - current_state="" + local current_state="" # Actually invoke vcs_info manually to gather all information. vcs_info @@ -1401,7 +1412,7 @@ prompt_dir_writable() { # Kubernetes Current Context prompt_kubecontext() { - local kubectl_version=$(kubectl version --client 2>/dev/null) + local kubectl_version="$(kubectl version --client 2>/dev/null)" if [[ -n "$kubectl_version" ]]; then # Get the current Kubernetes config context's namespaece @@ -1423,6 +1434,7 @@ prompt_kubecontext() { # Main prompt build_left_prompt() { local index=1 + local element for element in "${POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[@]}"; do # Remove joined information in direct calls element=${element%_joined} @@ -1526,7 +1538,7 @@ prompt_powerlevel9k_setup() { local term_colors term_colors=$(echotc Co 2>/dev/null) if (( ! $? && ${term_colors:-0} < 256 )); then - print -P "%F{red}WARNING!%f Your terminal appears to support less than 256 colors!" + print -P "%F{red}WARNING!%f Your terminal appears to support fewer than 256 colors!" print -P "If your terminal supports 256 colors, please export the appropriate environment variable" print -P "_before_ loading this theme in your \~\/.zshrc. In most terminal emulators, putting" print -P "%F{blue}export TERM=\"xterm-256color\"%f at the top of your \~\/.zshrc is sufficient." diff --git a/test/segments/vcs.spec b/test/segments/vcs.spec index 4467145e..c33b564d 100755 --- a/test/segments/vcs.spec +++ b/test/segments/vcs.spec @@ -21,7 +21,7 @@ function testColorOverridingForCleanStateWorks() { cd $FOLDER git init 1>/dev/null - assertEquals "%K{white} %F{cyan}master %k%F{white}%f " "$(build_left_prompt)" + assertEquals "%K{white} %F{cyan} master %k%F{white}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -47,7 +47,7 @@ function testColorOverridingForModifiedStateWorks() { git commit -m "test" 1>/dev/null echo "test" > testfile - assertEquals "%K{yellow} %F{red}master ● %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{red} master ● %k%F{yellow}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test @@ -68,7 +68,7 @@ function testColorOverridingForUntrackedStateWorks() { git init 1>/dev/null touch testfile - assertEquals "%K{yellow} %F{cyan}master ? %k%F{yellow}%f " "$(build_left_prompt)" + assertEquals "%K{yellow} %F{cyan} master ? %k%F{yellow}%f " "$(build_left_prompt)" cd - rm -fr /tmp/powerlevel9k-test |