Test for new version

This commit is contained in:
Andrea Mistrali 2020-02-12 17:22:56 +01:00
parent 1ab096b65c
commit fe71e0d80b
1 changed files with 608 additions and 601 deletions

View File

@ -48,7 +48,7 @@ prompt_pure_check_cmd_exec_time() {
integer elapsed
(( elapsed = EPOCHSECONDS - ${prompt_pure_cmd_timestamp:-$EPOCHSECONDS} ))
typeset -g prompt_pure_cmd_exec_time=
(( elapsed > ${PURE_CMD_MAX_EXEC_TIME:-5} )) && {
(( elapsed > ${PURE_CMD_MAX_EXEC_TIME:-20} )) && {
prompt_pure_human_time_to_var $elapsed "prompt_pure_cmd_exec_time"
}
}
@ -147,6 +147,10 @@ prompt_pure_preprompt_render() {
# Initialize the preprompt array.
local -a preprompt_parts
[[ $UID -eq 0 ]] && preprompt_parts+='%F{$prompt_pure_colors[user:root]}'"⚡"
[[ ! -z $SSH_CONNECTION ]] && preprompt_parts+='%F{$prompt_pure_colors[host]}'"@%m"
prompt_pure_set_aws
if [[ ! -z $prompt_pure_aws ]]; then
if [[ $prompt_pure_aws_prod -eq 1 ]];then
@ -173,8 +177,8 @@ prompt_pure_preprompt_render() {
preprompt_parts+=('%F{$prompt_pure_colors[git:arrow]}${prompt_pure_git_arrows}%f')
fi
# Username and machine, if applicable.
[[ -n $prompt_pure_state[username] ]] && preprompt_parts+=($prompt_pure_state[username])
# # Username and machine, if applicable.
# [[ -n $prompt_pure_state[username] ]] && preprompt_parts+=($prompt_pure_state[username])
# Execution time.
[[ -n $prompt_pure_cmd_exec_time ]] && preprompt_parts+=('%F{$prompt_pure_colors[execution_time]}${prompt_pure_cmd_exec_time}%f')
@ -617,49 +621,49 @@ prompt_pure_reset_vim_prompt_widget() {
}
prompt_pure_state_setup() {
setopt localoptions noshwordsplit
# setopt localoptions noshwordsplit
# Check SSH_CONNECTION and the current state.
local ssh_connection=${SSH_CONNECTION:-$PROMPT_PURE_SSH_CONNECTION}
local username hostname
if [[ -z $ssh_connection ]] && (( $+commands[who] )); then
# When changing user on a remote system, the $SSH_CONNECTION
# environment variable can be lost. Attempt detection via `who`.
local who_out
who_out=$(who -m 2>/dev/null)
if (( $? )); then
# Who am I not supported, fallback to plain who.
local -a who_in
who_in=( ${(f)"$(who 2>/dev/null)"} )
who_out="${(M)who_in:#*[[:space:]]${TTY#/dev/}[[:space:]]*}"
fi
# # Check SSH_CONNECTION and the current state.
# local ssh_connection=${SSH_CONNECTION:-$PROMPT_PURE_SSH_CONNECTION}
# local username hostname
# if [[ -z $ssh_connection ]] && (( $+commands[who] )); then
# # When changing user on a remote system, the $SSH_CONNECTION
# # environment variable can be lost. Attempt detection via `who`.
# local who_out
# who_out=$(who -m 2>/dev/null)
# if (( $? )); then
# # Who am I not supported, fallback to plain who.
# local -a who_in
# who_in=( ${(f)"$(who 2>/dev/null)"} )
# who_out="${(M)who_in:#*[[:space:]]${TTY#/dev/}[[:space:]]*}"
# fi
local reIPv6='(([0-9a-fA-F]+:)|:){2,}[0-9a-fA-F]+' # Simplified, only checks partial pattern.
local reIPv4='([0-9]{1,3}\.){3}[0-9]+' # Simplified, allows invalid ranges.
# Here we assume two non-consecutive periods represents a
# hostname. This matches `foo.bar.baz`, but not `foo.bar`.
local reHostname='([.][^. ]+){2}'
# local reIPv6='(([0-9a-fA-F]+:)|:){2,}[0-9a-fA-F]+' # Simplified, only checks partial pattern.
# local reIPv4='([0-9]{1,3}\.){3}[0-9]+' # Simplified, allows invalid ranges.
# # Here we assume two non-consecutive periods represents a
# # hostname. This matches `foo.bar.baz`, but not `foo.bar`.
# local reHostname='([.][^. ]+){2}'
# Usually the remote address is surrounded by parenthesis, but
# not on all systems (e.g. busybox).
local -H MATCH MBEGIN MEND
if [[ $who_out =~ "\(?($reIPv4|$reIPv6|$reHostname)\)?\$" ]]; then
ssh_connection=$MATCH
# # Usually the remote address is surrounded by parenthesis, but
# # not on all systems (e.g. busybox).
# local -H MATCH MBEGIN MEND
# if [[ $who_out =~ "\(?($reIPv4|$reIPv6|$reHostname)\)?\$" ]]; then
# ssh_connection=$MATCH
# Export variable to allow detection propagation inside
# shells spawned by this one (e.g. tmux does not always
# inherit the same tty, which breaks detection).
export PROMPT_PURE_SSH_CONNECTION=$ssh_connection
fi
unset MATCH MBEGIN MEND
fi
# # Export variable to allow detection propagation inside
# # shells spawned by this one (e.g. tmux does not always
# # inherit the same tty, which breaks detection).
# export PROMPT_PURE_SSH_CONNECTION=$ssh_connection
# fi
# unset MATCH MBEGIN MEND
# fi
hostname='%F{$prompt_pure_colors[host]}@%m%f'
# Show `username@host` if logged in through SSH.
[[ -n $ssh_connection ]] && username='%F{$prompt_pure_colors[user]}%n%f'"$hostname"
# hostname='%F{$prompt_pure_colors[host]}@%m%f'
# # Show `username@host` if logged in through SSH.
# [[ -n $ssh_connection ]] && username='%F{$prompt_pure_colors[user]}%n%f'"$hostname"
# Show `username@host` if root, with username in default color.
[[ $UID -eq 0 ]] && username='%F{$prompt_pure_colors[user:root]}%n%f'"$hostname"
# # Show `username@host` if root, with username in default color.
# [[ $UID -eq 0 ]] && username='%F{$prompt_pure_colors[user:root]}%n%f'"$hostname"
typeset -gA prompt_pure_state
prompt_pure_state[version]="1.11.0"
@ -669,53 +673,6 @@ prompt_pure_state_setup() {
)
}
prompt_pure_system_report() {
setopt localoptions noshwordsplit
print - "- Zsh: $($SHELL --version) ($SHELL)"
print -n - "- Operating system: "
case "$(uname -s)" in
Darwin) print "$(sw_vers -productName) $(sw_vers -productVersion) ($(sw_vers -buildVersion))";;
*) print "$(uname -s) ($(uname -v))";;
esac
print - "- Terminal program: ${TERM_PROGRAM:-unknown} (${TERM_PROGRAM_VERSION:-unknown})"
print -n - "- Tmux: "
[[ -n $TMUX ]] && print "yes" || print "no"
local git_version
git_version=($(git --version)) # Remove newlines, if hub is present.
print - "- Git: $git_version"
print - "- Pure state:"
for k v in "${(@kv)prompt_pure_state}"; do
print - " - $k: \`${(q)v}\`"
done
print - "- PROMPT: \`$(typeset -p PROMPT)\`"
print - "- Colors: \`$(typeset -p prompt_pure_colors)\`"
print - "- Virtualenv: \`$(typeset -p VIRTUAL_ENV_DISABLE_PROMPT)\`"
print - "- Conda: \`$(typeset -p CONDA_CHANGEPS1)\`"
local ohmyzsh=0
typeset -la frameworks
(( $+ANTIBODY_HOME )) && frameworks+=("Antibody")
(( $+ADOTDIR )) && frameworks+=("Antigen")
(( $+ANTIGEN_HS_HOME )) && frameworks+=("Antigen-hs")
(( $+functions[upgrade_oh_my_zsh] )) && {
ohmyzsh=1
frameworks+=("Oh My Zsh")
}
(( $+ZPREZTODIR )) && frameworks+=("Prezto")
(( $+ZPLUG_ROOT )) && frameworks+=("Zplug")
(( $+ZPLGM )) && frameworks+=("Zplugin")
(( $#frameworks == 0 )) && frameworks+=("None")
print - "- Detected frameworks: ${(j:, :)frameworks}"
if (( ohmyzsh )); then
print - " - Oh My Zsh:"
print - " - Plugins: ${(j:, :)plugins}"
fi
}
prompt_pure_setup() {
# Prevent percentage showing up if output doesn't end with a newline.
@ -827,3 +784,53 @@ prompt_pure_setup() {
}
prompt_pure_setup "$@"
# Utils
prompt_pure_system_report() {
setopt localoptions noshwordsplit
print - "- Zsh: $($SHELL --version) ($SHELL)"
print -n - "- Operating system: "
case "$(uname -s)" in
Darwin) print "$(sw_vers -productName) $(sw_vers -productVersion) ($(sw_vers -buildVersion))";;
*) print "$(uname -s) ($(uname -v))";;
esac
print - "- Terminal program: ${TERM_PROGRAM:-unknown} (${TERM_PROGRAM_VERSION:-unknown})"
print -n - "- Tmux: "
[[ -n $TMUX ]] && print "yes" || print "no"
local git_version
git_version=($(git --version)) # Remove newlines, if hub is present.
print - "- Git: $git_version"
print - "- Pure state:"
for k v in "${(@kv)prompt_pure_state}"; do
print - " - $k: \`${(q)v}\`"
done
print - "- PROMPT: \`$(typeset -p PROMPT)\`"
print - "- Colors: \`$(typeset -p prompt_pure_colors)\`"
print - "- Virtualenv: \`$(typeset -p VIRTUAL_ENV_DISABLE_PROMPT)\`"
print - "- Conda: \`$(typeset -p CONDA_CHANGEPS1)\`"
local ohmyzsh=0
typeset -la frameworks
(( $+ANTIBODY_HOME )) && frameworks+=("Antibody")
(( $+ADOTDIR )) && frameworks+=("Antigen")
(( $+ANTIGEN_HS_HOME )) && frameworks+=("Antigen-hs")
(( $+functions[upgrade_oh_my_zsh] )) && {
ohmyzsh=1
frameworks+=("Oh My Zsh")
}
(( $+ZPREZTODIR )) && frameworks+=("Prezto")
(( $+ZPLUG_ROOT )) && frameworks+=("Zplug")
(( $+ZPLGM )) && frameworks+=("Zplugin")
(( $#frameworks == 0 )) && frameworks+=("None")
print - "- Detected frameworks: ${(j:, :)frameworks}"
if (( ohmyzsh )); then
print - " - Oh My Zsh:"
print - " - Plugins: ${(j:, :)plugins}"
fi
}