Add mplay, use seaprate custom namespace, always transient prompt, add todo.txt parser

This commit is contained in:
Alex 2020-05-24 00:52:10 +02:00
parent 384ee7d385
commit 580b3a9bd9
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
4 changed files with 42 additions and 16 deletions

View File

@ -1,3 +1,9 @@
# Technically a alias on steroids
function mplay() {
busctl call --no-pager --user org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player OpenUri s "$1"
}
compdef _files mplay
alias recordscreen='ffmpeg -hwaccel vdpau -video_size 1920x1080 -framerate 60 -f x11grab -i :0 -c:v libx264rgb -crf 0 -preset ultrafast -movflags +faststart -tune zerolatency' alias recordscreen='ffmpeg -hwaccel vdpau -video_size 1920x1080 -framerate 60 -f x11grab -i :0 -c:v libx264rgb -crf 0 -preset ultrafast -movflags +faststart -tune zerolatency'
alias ytdldown='youtube-dl --no-part --newline -ixcw -R infinite -f bestaudio/best --add-metadata --embed-thumbnail -o "/home/caskd/Media/Music/%(album)s/%(track_number)s - %(track)s.%(ext)s"' alias ytdldown='youtube-dl --no-part --newline -ixcw -R infinite -f bestaudio/best --add-metadata --embed-thumbnail -o "/home/caskd/Media/Music/%(album)s/%(track_number)s - %(track)s.%(ext)s"'
alias ls='ls --color=auto' alias ls='ls --color=auto'

View File

@ -1,8 +1,8 @@
function prompt_docker_host() { function prompt_c_docker_host() {
p10k segment -b blue -i '' -t "${DOCKER_HOST#*://}" -c "${DOCKER_HOST#*://}" p10k segment -b blue -i '' -t "${DOCKER_HOST#*://}" -c "${DOCKER_HOST#*://}"
} }
typeset -g POWERLEVEL9K_DOCKER_HOST_SHOW_ON_COMMAND='docker' typeset -g POWERLEVEL9K_DOCKER_HOST_SHOW_ON_COMMAND='docker'
function prompt_new_mail() { function prompt_c_new_mail() {
if [ ! -v _cprompts_mail_count ]; then if [ ! -v _cprompts_mail_count ]; then
local new_mails=(~/Mail/*/Inbox/new/*(.N)) local new_mails=(~/Mail/*/Inbox/new/*(.N))
typeset -g _cprompts_mail_count=${#new_mails} typeset -g _cprompts_mail_count=${#new_mails}
@ -10,14 +10,14 @@ function prompt_new_mail() {
[[ ${_cprompts_mail_count} -gt 0 ]] || return [[ ${_cprompts_mail_count} -gt 0 ]] || return
p10k segment -b yellow -i '' -t "${_cprompts_mail_count:-unknown}" p10k segment -b yellow -i '' -t "${_cprompts_mail_count:-unknown}"
} }
function prompt_youtube() { function prompt_c_youtube() {
local newsboatdb=~/.newsboat/cache.db local newsboatdb=~/.newsboat/cache.db
if [ ! -v _cprompts_youtube ]; then 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:*"')" typeset -g _cprompts_youtube="$(sqlite3 ${newsboatdb} --ascii 'SELECT COUNT(id) FROM rss_item WHERE unread == 1 AND guid GLOB "yt:video:*"')"
fi fi
p10k segment -b red -i '' -t "${_cprompts_youtube}" p10k segment -b red -i '' -t "${_cprompts_youtube}"
} }
function prompt_covid_19() { function prompt_c_covid_19() {
local tmpfile=${CACHEPATH}/covid local tmpfile=${CACHEPATH}/covid
local -a stats local -a stats
if [ ! -v _cprompts_covid ]; then if [ ! -v _cprompts_covid ]; then
@ -31,7 +31,7 @@ function prompt_covid_19() {
fi fi
p10k segment -b red -i '' -t "${_cprompts_covid:-unknown}" p10k segment -b red -i '' -t "${_cprompts_covid:-unknown}"
} }
function prompt_weather() { function prompt_c_weather() {
local tmpfile=${CACHEPATH}/weather local tmpfile=${CACHEPATH}/weather
local -a stats local -a stats
@ -75,10 +75,31 @@ function prompt_weather() {
p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}" p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}"
} }
function prompt_mpv_mpris() { function prompt_c_mpv_mpris() {
typeset -g _cprompts_mpv 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)" 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 [ -z $busout ] && return
_cprompts_mpv="$(print $busout | jq -er '((.data."xesam:artist".data[0] // empty) + " - " + (.data."xesam:title".data // empty))')" format='((.data."xesam:artist".data[0] // empty) + " - " + (.data."xesam:title".data // empty))'
_cprompts_mpv="$(print $busout | jq -er $format)"
[ -z $_cprompts_mpv ] || p10k segment -b magenta -i '' -t "${_cprompts_mpv:0:40}$([ ${#_cprompts_mpv} -gt 40 ] && print ...)" [ -z $_cprompts_mpv ] || p10k segment -b magenta -i '' -t "${_cprompts_mpv:0:40}$([ ${#_cprompts_mpv} -gt 40 ] && 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 IFS=$'\n'
local todofi=($(< 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}"
}

View File

@ -1,6 +1,6 @@
typeset -g POWERLEVEL9K_DISABLE_HOT_RELOAD=true typeset -g POWERLEVEL9K_DISABLE_HOT_RELOAD=true
typeset -g POWERLEVEL9K_MODE=nerdfont-complete typeset -g POWERLEVEL9K_MODE=nerdfont-complete
typeset -g POWERLEVEL9K_ICON_PADDING=none typeset -g POWERLEVEL9K_ICON_PADDING=none
typeset -g POWERLEVEL9K_TRANSIENT_PROMPT=same-dir typeset -g POWERLEVEL9K_TRANSIENT_PROMPT=always
typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet typeset -g POWERLEVEL9K_INSTANT_PROMPT=quiet
typeset -g POWERLEVEL9K_USE_CACHE=true typeset -g POWERLEVEL9K_USE_CACHE=true

View File

@ -12,19 +12,18 @@ typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=(
dir dir
dir_writable dir_writable
) )
typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=( typeset -g POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS=()
)
if [ ! -v SSH_CONNECTION ]; then if [ ! -v SSH_CONNECTION ]; then
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=( POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=(
mpv_mpris c_mpv_mpris
new_mail c_todo
# youtube c_new_mail
weather # c_youtube
covid_19 c_weather
c_covid_19
) )
fi fi
POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=( POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=(
public_ip
newline newline
command_execution_time command_execution_time
background_jobs background_jobs