Autoload functions on call and tweak gpg stuff around
This commit is contained in:
parent
9177967124
commit
e006f98367
|
@ -16,4 +16,3 @@ zstyle ':completion:*:functions' ignored-patterns '_*'
|
|||
zstyle ':completion:*:descriptions' format '%U%B%d%b%u'
|
||||
zstyle ':completion:*:warnings' format '%BSorry, no matches for: %d%b'
|
||||
autoload -Uz +X compinit && compinit
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
source "${ZDOTDIR}/custom/segments.zsh"
|
||||
source "${ZDOTDIR}/custom/prependsudo.zsh"
|
||||
source "${ZDOTDIR}/custom/aliases.zsh"
|
||||
source "${ZDOTDIR}/custom/dirstack.zsh"
|
||||
source "${ZDOTDIR}/custom/docker.zsh"
|
||||
source "${ZDOTDIR}/custom/gpg.zsh"
|
||||
fpath+="${ZDOTDIR}/custom/functions"
|
||||
fpath+=("${ZDOTDIR}/custom/functions" "${ZDOTDIR}/custom/segments")
|
||||
function {prompt_c_{covid_19,docker_host,mpv_mpris,new_mail,todo,weather,youtube},cprompts:cache:async:{covid,weather},get{mangareader,nhentai},gitsubrepo,osutab,ffmpeg-{compress,gif}}() {
|
||||
autoload -X
|
||||
}
|
||||
|
|
|
@ -1 +0,0 @@
|
|||
|
|
@ -1,5 +0,0 @@
|
|||
export DOCKER_HOST=ssh://nbg-0
|
||||
|
||||
function build-n-push {
|
||||
docker build ${1} --tag=localhost:5000/${2} --force-rm --compress && docker push localhost:5000/${2} # --squash can eat disk space quickly due to diffs not being taken in calculation
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
# GPG SSH
|
||||
unset SSH_AGENT_PID
|
||||
if [ "${gnupg_SSH_AUTH_SOCK_by:-0}" -ne $$ ]; then
|
||||
if [ ! -v SSH_AUTH_SOCK ]; then
|
||||
unset SSH_AGENT_PID
|
||||
export SSH_AUTH_SOCK="$(gpgconf --list-dirs agent-ssh-socket)"
|
||||
export GPG_TTY=$TTY
|
||||
gpg-connect-agent updatestartuptty /bye >/dev/null
|
||||
fi
|
||||
export GPG_TTY=$TTY
|
||||
gpg-connect-agent updatestartuptty /bye >/dev/null
|
||||
|
|
|
@ -1,118 +0,0 @@
|
|||
function prompt_c_docker_host() {
|
||||
p10k segment -b blue -i '' -t "${DOCKER_HOST#*://}" -c "${DOCKER_HOST#*://}"
|
||||
}
|
||||
typeset -g POWERLEVEL9K_DOCKER_HOST_SHOW_ON_COMMAND='docker'
|
||||
function prompt_c_new_mail() {
|
||||
if [ ! -v _cprompts_mail_count ]; then
|
||||
local new_mails=(~/Mail/*/Inbox/new/*(.N))
|
||||
typeset -g _cprompts_mail_count=${#new_mails}
|
||||
fi
|
||||
[[ ${_cprompts_mail_count} -gt 0 ]] || return
|
||||
p10k segment -b yellow -i '' -t "${_cprompts_mail_count:-unknown}"
|
||||
}
|
||||
function prompt_c_youtube() {
|
||||
[ -v commands\[sqlite3\] ] || return
|
||||
local newsboatdb=~/.newsboat/cache.db
|
||||
if [ ! -v _cprompts_youtube ]; then
|
||||
typeset -g _cprompts_youtube="$(sqlite3 ${newsboatdb} --ascii 'SELECT COUNT(id) FROM rss_item WHERE unread == 1 AND guid GLOB "yt:video:*"')"
|
||||
fi
|
||||
p10k segment -b red -i '' -t "${_cprompts_youtube}"
|
||||
}
|
||||
function prompt_c_covid_19() {
|
||||
([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
|
||||
local tmpfile=${CACHEPATH}/covid
|
||||
local REPLY
|
||||
zstyle -s ':custom:prompts:covid' country REPLY
|
||||
local -a stats
|
||||
if [ ! -v _cprompts_covid ]; then
|
||||
zstat -A stats +mtime -- $tmpfile 2>/dev/null
|
||||
if [[ $stats[1] < $(($epochtime[1]-86400)) ]]; then
|
||||
cprompts:cache:async:covid &!
|
||||
else
|
||||
typeset -g _cprompts_covid=$(< $tmpfile)
|
||||
fi
|
||||
fi
|
||||
[ -v _cprompts_covid ] && p10k segment -b red -i '' -t "${_cprompts_covid:-unknown}"
|
||||
}
|
||||
function cprompts:cache:async:covid() {
|
||||
typeset -g _cprompts_covid=$(curl -sL https://api.covid19api.com/country/${REPLY:-germany} | jq -e '. |= sort_by (.Date) | .[-1].Active')
|
||||
[ ! -z $_cprompts_covid ] && print ${_cprompts_covid} > $tmpfile
|
||||
}
|
||||
function prompt_c_weather() {
|
||||
([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
|
||||
local tmpfile=${CACHEPATH}/weather
|
||||
local -a stats
|
||||
|
||||
# Fancy stuff
|
||||
local -A icons
|
||||
local -A colors
|
||||
icons[c]=''
|
||||
colors[c]="yellow"
|
||||
icons[lc]=''
|
||||
colors[lc]="yellow"
|
||||
icons[hc]=''
|
||||
colors[hc]="cyan"
|
||||
icons[s]='🌢'
|
||||
colors[s]="yellow"
|
||||
icons[lr]='🌢'
|
||||
colors[lr]="cyan"
|
||||
icons[hr]=''
|
||||
colors[hr]="blue"
|
||||
icons[t]=''
|
||||
colors[t]="white"
|
||||
icons[h]=''
|
||||
colors[h]="white"
|
||||
icons[sl]=''
|
||||
colors[sl]="blue"
|
||||
icons[sn]=''
|
||||
colors[sn]="white"
|
||||
|
||||
if [ ! -v _cprompts_weather ]; then
|
||||
zstat -A stats +mtime -- $tmpfile 2>/dev/null
|
||||
if [[ $stats[1] < $(($epochtime[1]-21600)) ]]; then
|
||||
cprompts:cache:async:weather &!
|
||||
else
|
||||
typeset -g _cprompts_weather=($(< $tmpfile))
|
||||
fi
|
||||
fi
|
||||
[ -v _cprompts_weather ] && p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}"
|
||||
|
||||
}
|
||||
function cprompts:cache:async:weather() {
|
||||
local REPLY
|
||||
zstyle -s ':custom:prompts:weather' location REPLY
|
||||
local result=$(curl -sL https://www.metaweather.com/api/location/${REPLY:-1339615}/ | jq -e '.consolidated_weather[0] | {"temp": .the_temp, "icon": .weather_state_abbr}')
|
||||
if [ ! -z $result ]; then
|
||||
local ico=$(print $result | jq -r '.icon')
|
||||
typeset -g _cprompts_weather=($(print $result | jq -r '.temp') ${colors[$ico]} ${icons[$ico]:-?})
|
||||
print ${_cprompts_weather%%.*} > $tmpfile
|
||||
fi
|
||||
}
|
||||
|
||||
function prompt_c_mpv_mpris() {
|
||||
([ -v commands\[busctl\] ] && [ -v commands\[jq\] ]) || return
|
||||
typeset -g _cprompts_mpv
|
||||
local busout="$(busctl get-property -j --no-pager --timeout=300ms --user org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Metadata 2>/dev/null)"
|
||||
[ -z $busout ] && return
|
||||
_cprompts_mpv="$(print $busout | jq -er '(.data."xesam:title".data // empty)')"
|
||||
[ -z $_cprompts_mpv ] || p10k segment -b magenta -i '' -t "${_cprompts_mpv:0:20}$([ ${#_cprompts_mpv} -gt 20 ] && print ...)"
|
||||
}
|
||||
function prompt_c_todo() {
|
||||
[ -r todo.txt ] || return
|
||||
local -a stats
|
||||
zstat -A stats +mtime -- todo.txt 2>/dev/null
|
||||
if [ ! -v _cprompts_todo ] || [ $_cprompts_todo[4] -ne $stats[1] ]; then
|
||||
local todofi=(${(f@)${mapfile[todo.txt]}})
|
||||
local t_nf=0
|
||||
local t_f=0
|
||||
local colors=(red yellow green)
|
||||
for i in $todofi; do
|
||||
[ ${i:0:1} = "-" ] && ((t_nf++))
|
||||
[ ${i:0:1} = "+" ] && ((t_f++))
|
||||
done
|
||||
local t_tot=$(($t_f+$t_nf))
|
||||
[ $t_tot -gt 0 ] || return
|
||||
typeset -g _cprompts_todo=($t_f $t_tot ${colors[$(( 1+int( $t_f / $t_tot.0 * 2 ) ))]} $stats[1])
|
||||
fi
|
||||
p10k segment -b ${_cprompts_todo[3]:-white} -i '' -t "${_cprompts_todo[1]:-unknown} / ${_cprompts_todo[2]:-unknown}"
|
||||
}
|
|
@ -0,0 +1,2 @@
|
|||
typeset -g _cprompts_covid=$(curl -sL https://api.covid19api.com/country/${REPLY:-germany} | jq -e '. |= sort_by (.Date) | .[-1].Active')
|
||||
[ ! -z $_cprompts_covid ] && print ${_cprompts_covid} > $tmpfile
|
|
@ -0,0 +1,8 @@
|
|||
local REPLY
|
||||
zstyle -s ':custom:prompts:weather' location REPLY
|
||||
local result=$(curl -sL https://www.metaweather.com/api/location/${REPLY:-1339615}/ | jq -e '.consolidated_weather[0] | {"temp": .the_temp, "icon": .weather_state_abbr}')
|
||||
if [ ! -z $result ]; then
|
||||
local ico=$(print $result | jq -r '.icon')
|
||||
typeset -g _cprompts_weather=($(print $result | jq -r '.temp') ${colors[$ico]} ${icons[$ico]:-?})
|
||||
print ${_cprompts_weather%%.*} > $tmpfile
|
||||
fi
|
|
@ -0,0 +1,14 @@
|
|||
([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
|
||||
local tmpfile=${CACHEPATH}/covid
|
||||
local REPLY
|
||||
zstyle -s ':custom:prompts:covid' country REPLY
|
||||
local -a stats
|
||||
if [ ! -v _cprompts_covid ]; then
|
||||
zstat -A stats +mtime -- $tmpfile 2>/dev/null
|
||||
if [[ $stats[1] < $(($epochtime[1]-86400)) ]]; then
|
||||
cprompts:cache:async:covid &!
|
||||
else
|
||||
typeset -g _cprompts_covid=$(< $tmpfile)
|
||||
fi
|
||||
fi
|
||||
[ -v _cprompts_covid ] && p10k segment -b red -i '' -t "${_cprompts_covid:-unknown}"
|
|
@ -0,0 +1,2 @@
|
|||
p10k segment -b blue -i '' -t "${DOCKER_HOST#*://}" -c "${DOCKER_HOST#*://}"
|
||||
typeset -g POWERLEVEL9K_DOCKER_HOST_SHOW_ON_COMMAND='docker'
|
|
@ -0,0 +1,6 @@
|
|||
([ -v commands\[busctl\] ] && [ -v commands\[jq\] ]) || return
|
||||
typeset -g _cprompts_mpv
|
||||
local busout="$(busctl get-property -j --no-pager --timeout=300ms --user org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player Metadata 2>/dev/null)"
|
||||
[ -z $busout ] && return
|
||||
_cprompts_mpv="$(print $busout | jq -er '(.data."xesam:title".data // empty)')"
|
||||
[ -z $_cprompts_mpv ] || p10k segment -b magenta -i '' -t "${_cprompts_mpv:0:20}$([ ${#_cprompts_mpv} -gt 20 ] && print ...)"
|
|
@ -0,0 +1,4 @@
|
|||
local new_mails=(~/Mail/*/Inbox/new/*(.N))
|
||||
typeset -g _cprompts_mail_count=${#new_mails}
|
||||
[[ ${_cprompts_mail_count} -gt 0 ]] || return
|
||||
p10k segment -b yellow -i '' -t "${_cprompts_mail_count:-unknown}"
|
|
@ -0,0 +1,17 @@
|
|||
[ -r todo.txt ] || return
|
||||
local -a stats
|
||||
zstat -A stats +mtime -- todo.txt 2>/dev/null
|
||||
if [ ! -v _cprompts_todo ] || [ $_cprompts_todo[4] -ne $stats[1] ]; then
|
||||
local todofi=(${(f@)${mapfile[todo.txt]}})
|
||||
local t_nf=0
|
||||
local t_f=0
|
||||
local colors=(red yellow green)
|
||||
for i in $todofi; do
|
||||
[ ${i:0:1} = "-" ] && ((t_nf++))
|
||||
[ ${i:0:1} = "+" ] && ((t_f++))
|
||||
done
|
||||
local t_tot=$(($t_f+$t_nf))
|
||||
[ $t_tot -gt 0 ] || return
|
||||
typeset -g _cprompts_todo=($t_f $t_tot ${colors[$(( 1+int( $t_f / $t_tot.0 * 2 ) ))]} $stats[1])
|
||||
fi
|
||||
p10k segment -b ${_cprompts_todo[3]:-white} -i '' -t "${_cprompts_todo[1]:-unknown} / ${_cprompts_todo[2]:-unknown}"
|
|
@ -0,0 +1,37 @@
|
|||
([ -v commands\[curl\] ] && [ -v commands\[jq\] ]) || return
|
||||
local tmpfile=${CACHEPATH}/weather
|
||||
local -a stats
|
||||
|
||||
# Fancy stuff
|
||||
local -A icons
|
||||
local -A colors
|
||||
icons[c]=''
|
||||
colors[c]="yellow"
|
||||
icons[lc]=''
|
||||
colors[lc]="yellow"
|
||||
icons[hc]=''
|
||||
colors[hc]="cyan"
|
||||
icons[s]='🌢'
|
||||
colors[s]="yellow"
|
||||
icons[lr]='🌢'
|
||||
colors[lr]="cyan"
|
||||
icons[hr]=''
|
||||
colors[hr]="blue"
|
||||
icons[t]=''
|
||||
colors[t]="white"
|
||||
icons[h]=''
|
||||
colors[h]="white"
|
||||
icons[sl]=''
|
||||
colors[sl]="blue"
|
||||
icons[sn]=''
|
||||
colors[sn]="white"
|
||||
|
||||
if [ ! -v _cprompts_weather ]; then
|
||||
zstat -A stats +mtime -- $tmpfile 2>/dev/null
|
||||
if [[ $stats[1] < $(($epochtime[1]-21600)) ]]; then
|
||||
cprompts:cache:async:weather &!
|
||||
else
|
||||
typeset -g _cprompts_weather=($(< $tmpfile))
|
||||
fi
|
||||
fi
|
||||
[ -v _cprompts_weather ] && p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}"
|
|
@ -0,0 +1,6 @@
|
|||
[ -v commands\[sqlite3\] ] || return
|
||||
local newsboatdb=~/.newsboat/cache.db
|
||||
if [ ! -v _cprompts_youtube ]; then
|
||||
typeset -g _cprompts_youtube="$(sqlite3 ${newsboatdb} --ascii 'SELECT COUNT(id) FROM rss_item WHERE unread == 1 AND guid GLOB "yt:video:*"')"
|
||||
fi
|
||||
p10k segment -b red -i '' -t "${_cprompts_youtube}"
|
|
@ -14,6 +14,7 @@ typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
|
|||
)
|
||||
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
|
||||
if [ ! -v SSH_CONNECTION ]; then
|
||||
zmodload zsh/mapfile # Required by the todo segment, is way faster
|
||||
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=(
|
||||
c_mpv_mpris
|
||||
c_todo
|
||||
|
@ -22,7 +23,6 @@ POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=(
|
|||
c_weather
|
||||
c_covid_19
|
||||
)
|
||||
zmodload zsh/mapfile # Required by the todo segment, is way faster
|
||||
fi
|
||||
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=(
|
||||
newline
|
||||
|
|
Loading…
Reference in New Issue