1
0
Fork 0
mirror of https://github.com/romkatv/powerlevel10k.git synced 2024-12-18 21:41:57 +00:00

stop using typeset when declaring functions; it's stupid

This commit is contained in:
romkatv 2019-03-21 15:02:41 +01:00
parent fc178e9916
commit 0ecf2636b4

View file

@ -1671,13 +1671,15 @@ function _p9k_vcs_render() {
local -a cur_prompt local -a cur_prompt
local -a stale_prompt local -a stale_prompt
typeset -lf fmt() { function _$0_fmt() {
_p9k_vcs_style $state $1 _p9k_vcs_style $state $1
cur_prompt+=$_P9K_RETVAL$2 cur_prompt+=$_P9K_RETVAL$2
_p9k_vcs_style LOADING $1 _p9k_vcs_style LOADING $1
stale_prompt+=$_P9K_RETVAL$2 stale_prompt+=$_P9K_RETVAL$2
} }
trap "unfunction _$0_fmt" EXIT
if (( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)vcs-detect-changes]} )); then if (( ${POWERLEVEL9K_VCS_GIT_HOOKS[(I)vcs-detect-changes]} )); then
if [[ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ]]; then if [[ $VCS_STATUS_HAS_STAGED != 0 || $VCS_STATUS_HAS_UNSTAGED != 0 ]]; then
state=MODIFIED state=MODIFIED
@ -1689,70 +1691,70 @@ function _p9k_vcs_render() {
# of the GIT icon. That's what vcs_info does, so we do the same in the name of compatiblity. # of the GIT icon. That's what vcs_info does, so we do the same in the name of compatiblity.
if [[ "$VCS_STATUS_REMOTE_URL" == *github* ]] then if [[ "$VCS_STATUS_REMOTE_URL" == *github* ]] then
_p9k_get_icon VCS_GIT_GITHUB_ICON _p9k_get_icon VCS_GIT_GITHUB_ICON
fmt REMOTE_URL $_P9K_RETVAL _$0_fmt REMOTE_URL $_P9K_RETVAL
elif [[ "$VCS_STATUS_REMOTE_URL" == *bitbucket* ]] then elif [[ "$VCS_STATUS_REMOTE_URL" == *bitbucket* ]] then
_p9k_get_icon VCS_GIT_BITBUCKET_ICON _p9k_get_icon VCS_GIT_BITBUCKET_ICON
fmt REMOTE_URL $_P9K_RETVAL _$0_fmt REMOTE_URL $_P9K_RETVAL
elif [[ "$VCS_STATUS_REMOTE_URL" == *stash* ]] then elif [[ "$VCS_STATUS_REMOTE_URL" == *stash* ]] then
_p9k_get_icon VCS_GIT_GITHUB_ICON _p9k_get_icon VCS_GIT_GITHUB_ICON
fmt REMOTE_URL $_P9K_RETVAL _$0_fmt REMOTE_URL $_P9K_RETVAL
elif [[ "$VCS_STATUS_REMOTE_URL" == *gitlab* ]] then elif [[ "$VCS_STATUS_REMOTE_URL" == *gitlab* ]] then
_p9k_get_icon VCS_GIT_GITLAB_ICON _p9k_get_icon VCS_GIT_GITLAB_ICON
fmt REMOTE_URL $_P9K_RETVAL _$0_fmt REMOTE_URL $_P9K_RETVAL
else else
_p9k_get_icon VCS_GIT_ICON _p9k_get_icon VCS_GIT_ICON
fmt REMOTE_URL $_P9K_RETVAL _$0_fmt REMOTE_URL $_P9K_RETVAL
fi fi
fi fi
local ws local ws
if [[ $POWERLEVEL9K_SHOW_CHANGESET == true || -z $VCS_STATUS_LOCAL_BRANCH ]]; then if [[ $POWERLEVEL9K_SHOW_CHANGESET == true || -z $VCS_STATUS_LOCAL_BRANCH ]]; then
_p9k_get_icon VCS_COMMIT_ICON _p9k_get_icon VCS_COMMIT_ICON
fmt COMMIT "$_P9K_RETVAL${VCS_STATUS_COMMIT:0:$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH}" _$0_fmt COMMIT "$_P9K_RETVAL${VCS_STATUS_COMMIT:0:$POWERLEVEL9K_VCS_INTERNAL_HASH_LENGTH}"
ws=' ' ws=' '
fi fi
if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then if [[ -n $VCS_STATUS_LOCAL_BRANCH ]]; then
_p9k_get_icon VCS_BRANCH_ICON _p9k_get_icon VCS_BRANCH_ICON
fmt BRANCH "$ws$_P9K_RETVAL${VCS_STATUS_LOCAL_BRANCH//\%/%%}" _$0_fmt BRANCH "$ws$_P9K_RETVAL${VCS_STATUS_LOCAL_BRANCH//\%/%%}"
fi fi
if [[ $POWERLEVEL9K_VCS_HIDE_TAGS == false && -n $VCS_STATUS_TAG ]]; then if [[ $POWERLEVEL9K_VCS_HIDE_TAGS == false && -n $VCS_STATUS_TAG ]]; then
_p9k_get_icon VCS_TAG_ICON _p9k_get_icon VCS_TAG_ICON
fmt TAG " $_P9K_RETVAL${VCS_STATUS_TAG//\%/%%}" _$0_fmt TAG " $_P9K_RETVAL${VCS_STATUS_TAG//\%/%%}"
fi fi
if [[ -n $VCS_STATUS_ACTION ]]; then if [[ -n $VCS_STATUS_ACTION ]]; then
fmt ACTION " | ${VCS_STATUS_ACTION//\%/%%}" _$0_fmt ACTION " | ${VCS_STATUS_ACTION//\%/%%}"
else else
if [[ -n $VCS_STATUS_REMOTE_BRANCH && if [[ -n $VCS_STATUS_REMOTE_BRANCH &&
$VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then $VCS_STATUS_LOCAL_BRANCH != $VCS_STATUS_REMOTE_BRANCH ]]; then
_p9k_get_icon VCS_REMOTE_BRANCH_ICON _p9k_get_icon VCS_REMOTE_BRANCH_ICON
fmt REMOTE_BRANCH " $_P9K_RETVAL${VCS_STATUS_REMOTE_BRANCH//\%/%%}" _$0_fmt REMOTE_BRANCH " $_P9K_RETVAL${VCS_STATUS_REMOTE_BRANCH//\%/%%}"
fi fi
if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then if [[ $VCS_STATUS_HAS_STAGED == 1 ]]; then
_p9k_get_icon VCS_STAGED_ICON _p9k_get_icon VCS_STAGED_ICON
fmt STAGED " $_P9K_RETVAL" _$0_fmt STAGED " $_P9K_RETVAL"
fi fi
if [[ $VCS_STATUS_HAS_UNSTAGED == 1 ]]; then if [[ $VCS_STATUS_HAS_UNSTAGED == 1 ]]; then
_p9k_get_icon VCS_UNSTAGED_ICON _p9k_get_icon VCS_UNSTAGED_ICON
fmt UNSTAGED " $_P9K_RETVAL" _$0_fmt UNSTAGED " $_P9K_RETVAL"
fi fi
if [[ $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then if [[ $VCS_STATUS_HAS_UNTRACKED == 1 ]]; then
_p9k_get_icon VCS_UNTRACKED_ICON _p9k_get_icon VCS_UNTRACKED_ICON
fmt UNTRACKED " $_P9K_RETVAL" _$0_fmt UNTRACKED " $_P9K_RETVAL"
fi fi
if [[ $VCS_STATUS_COMMITS_AHEAD -gt 0 ]]; then if [[ $VCS_STATUS_COMMITS_AHEAD -gt 0 ]]; then
_p9k_get_icon VCS_OUTGOING_CHANGES_ICON _p9k_get_icon VCS_OUTGOING_CHANGES_ICON
fmt OUTGOING_CHANGES " $_P9K_RETVAL$VCS_STATUS_COMMITS_AHEAD" _$0_fmt OUTGOING_CHANGES " $_P9K_RETVAL$VCS_STATUS_COMMITS_AHEAD"
fi fi
if [[ $VCS_STATUS_COMMITS_BEHIND -gt 0 ]]; then if [[ $VCS_STATUS_COMMITS_BEHIND -gt 0 ]]; then
_p9k_get_icon VCS_INCOMING_CHANGES_ICON _p9k_get_icon VCS_INCOMING_CHANGES_ICON
fmt INCOMING_CHANGES " $_P9K_RETVAL$VCS_STATUS_COMMITS_BEHIND" _$0_fmt INCOMING_CHANGES " $_P9K_RETVAL$VCS_STATUS_COMMITS_BEHIND"
fi fi
if [[ $VCS_STATUS_STASHES -gt 0 ]]; then if [[ $VCS_STATUS_STASHES -gt 0 ]]; then
_p9k_get_icon VCS_STASH_ICON _p9k_get_icon VCS_STASH_ICON
fmt STASH " $_P9K_RETVAL$VCS_STATUS_STASHES" _$0_fmt STASH " $_P9K_RETVAL$VCS_STATUS_STASHES"
fi fi
fi fi
@ -1769,7 +1771,7 @@ function _p9k_vcs_render() {
return 0 return 0
} }
typeset -fH _p9k_vcs_resume() { function _p9k_vcs_resume() {
emulate -L zsh emulate -L zsh
if [[ $VCS_STATUS_RESULT == ok-async ]]; then if [[ $VCS_STATUS_RESULT == ok-async ]]; then
@ -1802,7 +1804,7 @@ typeset -fH _p9k_vcs_resume() {
fi fi
} }
typeset -fH _p9k_vcs_gitstatus() { function _p9k_vcs_gitstatus() {
[[ $POWERLEVEL9K_DISABLE_GITSTATUS == true ]] && return 1 [[ $POWERLEVEL9K_DISABLE_GITSTATUS == true ]] && return 1
if [[ $_P9K_REFRESH_REASON == precmd ]]; then if [[ $_P9K_REFRESH_REASON == precmd ]]; then
if [[ -v _P9K_NEXT_VCS_DIR ]]; then if [[ -v _P9K_NEXT_VCS_DIR ]]; then
@ -2046,7 +2048,7 @@ typeset -g _P9K_RIGHT_PREFIX
typeset -g _P9K_RIGHT_SUFFIX typeset -g _P9K_RIGHT_SUFFIX
set_default POWERLEVEL9K_DISABLE_RPROMPT false set_default POWERLEVEL9K_DISABLE_RPROMPT false
typeset -fH _p9k_set_prompt() { function _p9k_set_prompt() {
emulate -L zsh emulate -L zsh
_P9K_PROMPT='' _P9K_PROMPT=''
@ -2200,45 +2202,47 @@ _p9k_init() {
_p9k_init_icons _p9k_init_icons
_p9k_init_strings _p9k_init_strings
typeset -lf set_os() { function _$0_set_os() {
OS=$1 OS=$1
_p9k_get_icon $2 _p9k_get_icon $2
OS_ICON=$_P9K_RETVAL OS_ICON=$_P9K_RETVAL
} }
trap "unfunction _$0_set_os" EXIT
if [[ $(uname -o 2>/dev/null) == Android ]]; then if [[ $(uname -o 2>/dev/null) == Android ]]; then
set_os Android ANDROID_ICON _$0_set_os Android ANDROID_ICON
else else
case $(uname) in case $(uname) in
SunOS) set_os Solaris SUNOS_ICON;; SunOS) _$0_set_os Solaris SUNOS_ICON;;
Darwin) set_os OSX APPLE_ICON;; Darwin) _$0_set_os OSX APPLE_ICON;;
CYGWIN_NT-* | MSYS_NT-*) set_os Windows WINDOWS_ICON;; CYGWIN_NT-* | MSYS_NT-*) _$0_set_os Windows WINDOWS_ICON;;
FreeBSD|OpenBSD|DragonFly) set_os BSD FREEBSD_ICON;; FreeBSD|OpenBSD|DragonFly) _$0_set_os BSD FREEBSD_ICON;;
Linux) Linux)
OS='Linux' OS='Linux'
local os_release_id local os_release_id
[[ -f /etc/os-release && [[ -f /etc/os-release &&
"${(f)$((</etc/os-release) 2>/dev/null)}" =~ "ID=([A-Za-z]+)" ]] && os_release_id="${match[1]}" "${(f)$((</etc/os-release) 2>/dev/null)}" =~ "ID=([A-Za-z]+)" ]] && os_release_id="${match[1]}"
case "$os_release_id" in case "$os_release_id" in
*arch*) set_os Linux LINUX_ARCH_ICON;; *arch*) _$0_set_os Linux LINUX_ARCH_ICON;;
*debian*) set_os Linux LINUX_DEBIAN_ICON;; *debian*) _$0_set_os Linux LINUX_DEBIAN_ICON;;
*ubuntu*) set_os Linux LINUX_UBUNTU_ICON;; *ubuntu*) _$0_set_os Linux LINUX_UBUNTU_ICON;;
*elementary*) set_os Linux LINUX_ELEMENTARY_ICON;; *elementary*) _$0_set_os Linux LINUX_ELEMENTARY_ICON;;
*fedora*) set_os Linux LINUX_FEDORA_ICON;; *fedora*) _$0_set_os Linux LINUX_FEDORA_ICON;;
*coreos*) set_os Linux LINUX_COREOS_ICON;; *coreos*) _$0_set_os Linux LINUX_COREOS_ICON;;
*gentoo*) set_os Linux LINUX_GENTOO_ICON;; *gentoo*) _$0_set_os Linux LINUX_GENTOO_ICON;;
*mageia*) set_os Linux LINUX_MAGEIA_ICON;; *mageia*) _$0_set_os Linux LINUX_MAGEIA_ICON;;
*centos*) set_os Linux LINUX_CENTOS_ICON;; *centos*) _$0_set_os Linux LINUX_CENTOS_ICON;;
*opensuse*|*tumbleweed*) set_os Linux LINUX_OPENSUSE_ICON;; *opensuse*|*tumbleweed*) _$0_set_os Linux LINUX_OPENSUSE_ICON;;
*sabayon*) set_os Linux LINUX_SABAYON_ICON;; *sabayon*) _$0_set_os Linux LINUX_SABAYON_ICON;;
*slackware*) set_os Linux LINUX_SLACKWARE_ICON;; *slackware*) _$0_set_os Linux LINUX_SLACKWARE_ICON;;
*linuxmint*) set_os Linux LINUX_MINT_ICON;; *linuxmint*) _$0_set_os Linux LINUX_MINT_ICON;;
*alpine*) set_os Linux LINUX_ALPINE_ICON;; *alpine*) _$0_set_os Linux LINUX_ALPINE_ICON;;
*aosc*) set_os Linux LINUX_AOSC_ICON;; *aosc*) _$0_set_os Linux LINUX_AOSC_ICON;;
*nixos*) set_os Linux LINUX_NIXOS_ICON;; *nixos*) _$0_set_os Linux LINUX_NIXOS_ICON;;
*devuan*) set_os Linux LINUX_DEVUAN_ICON;; *devuan*) _$0_set_os Linux LINUX_DEVUAN_ICON;;
*manjaro*) set_os Linux LINUX_MANJARO_ICON;; *manjaro*) _$0_set_os Linux LINUX_MANJARO_ICON;;
*) set_os Linux LINUX_ICON;; *) _$0_set_os Linux LINUX_ICON;;
esac esac
;; ;;
esac esac