aboutsummaryrefslogtreecommitdiff
path: root/functions/utilities.zsh
diff options
context:
space:
mode:
authorromkatv <roman.perepelitsa@gmail.com>2019-07-24 16:01:26 +0300
committerromkatv <roman.perepelitsa@gmail.com>2019-07-24 16:01:26 +0300
commitbe1a97bf4715a50f792bd19330cc1f22109bfb07 (patch)
tree5bdb91cc92cd8bf7b437343d79c156e1f34ea89c /functions/utilities.zsh
parent4a9f441c7b1772eb2cb861ff06e13f0836b8ab3a (diff)
inline colors.zsh, utilities.zsh and vcs.zsh
Diffstat (limited to 'functions/utilities.zsh')
-rwxr-xr-xfunctions/utilities.zsh137
1 files changed, 0 insertions, 137 deletions
diff --git a/functions/utilities.zsh b/functions/utilities.zsh
deleted file mode 100755
index dea4d3bd..00000000
--- a/functions/utilities.zsh
+++ /dev/null
@@ -1,137 +0,0 @@
-# _p9k_declare <type> <uppercase-name> [default]...
-function _p9k_declare() {
- local -i set=$+parameters[$2]
- (( ARGC > 2 || set )) || return 0
- case $1 in
- -b)
- if (( set )); then
- [[ ${(P)2} == true ]] && typeset -gi _$2=1 || typeset -gi _$2=0
- else
- typeset -gi _$2=$3
- fi
- ;;
- -a)
- local -a v=(${(P)2})
- if (( set )); then
- eval "typeset -ga _${(q)2}=(${(@qq)v})";
- else
- if [[ $3 != '--' ]]; then
- echo "internal error in _p9k_declare " "${(qqq)@}" >&2
- fi
- eval "typeset -ga _${(q)2}=(${(@qq)*[4,-1]})"
- fi
- ;;
- -i)
- (( set )) && typeset -gi _$2=$2 || typeset -gi _$2=$3
- ;;
- -F)
- (( set )) && typeset -gF _$2=$2 || typeset -gF _$2=$3
- ;;
- -s)
- (( set )) && typeset -g _$2=${(P)2} || typeset -g _$2=$3
- ;;
- -e)
- if (( set )); then
- local v=${(P)2}
- typeset -g _$2=${(g::)v}
- else
- typeset -g _$2=${(g::)3}
- fi
- ;;
- *)
- echo "internal error in _p9k_declare " "${(qqq)@}" >&2
- esac
-}
-
-# If we execute `print -P $1`, how many characters will be printed on the last line?
-# Assumes that `%{%}` and `%G` don't lie.
-#
-# _p9k_prompt_length '' => 0
-# _p9k_prompt_length 'abc' => 3
-# _p9k_prompt_length $'abc\nxy' => 2
-# _p9k_prompt_length $'\t' => 8
-# _p9k_prompt_length '%F{red}abc' => 3
-# _p9k_prompt_length $'%{a\b%Gb%}' => 1
-function _p9k_prompt_length() {
- emulate -L zsh
- local COLUMNS=1024
- local -i x y=$#1 m
- if (( y )); then
- while (( ${${(%):-$1%$y(l.1.0)}[-1]} )); do
- x=y
- (( y *= 2 ));
- done
- local xy
- while (( y > x + 1 )); do
- m=$(( x + (y - x) / 2 ))
- typeset ${${(%):-$1%$m(l.x.y)}[-1]}=$m
- done
- fi
- _p9k_ret=$x
-}
-
-typeset -gr __p9k_byte_suffix=('B' 'K' 'M' 'G' 'T' 'P' 'E' 'Z' 'Y')
-
-# 42 => 42B
-# 1536 => 1.5K
-function _p9k_human_readable_bytes() {
- typeset -F 2 n=$1
- local suf
- for suf in $__p9k_byte_suffix; do
- (( n < 100 )) && break
- (( n /= 1024 ))
- done
- _p9k_ret=$n$suf
-}
-
-# Determine if the passed segment is used in the prompt
-#
-# Pass the name of the segment to this function to test for its presence in
-# either the LEFT or RIGHT prompt arrays.
-# * $1: The segment to be tested.
-segment_in_use() {
- (( $_POWERLEVEL9K_LEFT_PROMPT_ELEMENTS[(I)$1(|_joined)] ||
- $_POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS[(I)$1(|_joined)] ))
-}
-
-function _p9k_parse_ip() {
- local desiredInterface=${1:-'^[^ ]+'}
-
- if [[ $_p9k_os == OSX ]]; then
- [[ -x /sbin/ifconfig ]] || return
- local rawInterfaces && rawInterfaces="$(/sbin/ifconfig -l 2>/dev/null)" || return
- local -a interfaces=(${(A)=rawInterfaces})
- local pattern="${desiredInterface}[^ ]?"
- local -a relevantInterfaces
- for rawInterface in $interfaces; do
- [[ "$rawInterface" =~ $pattern ]] && relevantInterfaces+=$MATCH
- done
- local newline=$'\n'
- local interfaceName interface
- for interfaceName in $relevantInterfaces; do
- interface="$(/sbin/ifconfig $interfaceName 2>/dev/null)" || continue
- [[ "${interface}" =~ "lo[0-9]*" ]] && continue
- if [[ "${interface//${newline}/}" =~ "<([^>]*)>(.*)inet[ ]+([^ ]*)" ]]; then
- local ipFound="${match[3]}"
- local -a interfaceStates=(${(s:,:)match[1]})
- if (( ${interfaceStates[(I)UP]} )); then
- _p9k_ret=$ipFound
- return
- fi
- fi
- done
- else
- [[ -x /sbin/ip ]] || return
- local -a interfaces=( "${(f)$(/sbin/ip -brief -4 a show 2>/dev/null)}" )
- local pattern="^${desiredInterface}[[:space:]]+UP[[:space:]]+([^/ ]+)"
- local interface
- for interface in "${(@)interfaces}"; do
- if [[ "$interface" =~ $pattern ]]; then
- _p9k_ret=$match[1]
- return
- fi
- done
- fi
-
- return 1
-}