From 13467890d6d7400328e6db6ba47675f7c9fd500d Mon Sep 17 00:00:00 2001 From: Alex Denes Date: Sat, 26 Sep 2020 19:17:43 +0200 Subject: [PATCH] Update lots of things, rename custom prompts, move active prompts out of tree and update commits --- .zshenv | 2 -- custom.zsh | 2 +- custom/aliases.zsh | 1 - custom/functions/ffmpeg-compress | 2 +- custom/functions/formatirc | 9 ++++++ custom/functions/getgbooru | 7 +++- custom/functions/mplay | 5 ++- custom/functions/recordscreen | 1 + custom/functions/sendirc | 2 ++ custom/prependsudo.zsh | 9 ++++-- custom/segments/cprompts:cache:async:weather | 4 +-- custom/segments/prompt_c_irc_mentions | 5 +++ custom/segments/prompt_c_mpv | 6 ++++ custom/segments/prompt_c_mpv_mpris | 6 ---- custom/segments/prompt_c_new_mail | 4 ++- custom/segments/prompt_c_newsboat | 5 +-- custom/segments/prompt_c_todo | 2 +- custom/segments/prompt_c_weather | 4 +-- powerlevel-config/all.zsh | 1 - powerlevel-config/prompt-elements.zsh | 34 -------------------- powerlevel10k | 2 +- preferences.zsh | 10 +++--- zsh-syntax-highlighting | 2 +- 23 files changed, 59 insertions(+), 66 deletions(-) delete mode 100644 .zshenv create mode 100644 custom/functions/formatirc create mode 100644 custom/functions/recordscreen create mode 100644 custom/functions/sendirc create mode 100644 custom/segments/prompt_c_irc_mentions create mode 100644 custom/segments/prompt_c_mpv delete mode 100644 custom/segments/prompt_c_mpv_mpris delete mode 100644 powerlevel-config/prompt-elements.zsh diff --git a/.zshenv b/.zshenv deleted file mode 100644 index fb04142..0000000 --- a/.zshenv +++ /dev/null @@ -1,2 +0,0 @@ -export PATH=$HOME/bin:$HOME/.local/bin:/usr/local/bin:$PATH -export EDITOR=vim diff --git a/custom.zsh b/custom.zsh index b393107..db52bf3 100644 --- a/custom.zsh +++ b/custom.zsh @@ -3,6 +3,6 @@ source "${ZDOTDIR}/custom/aliases.zsh" source "${ZDOTDIR}/custom/gpg.zsh" fpath+=("${ZDOTDIR}/custom/functions" "${ZDOTDIR}/custom/segments") compdef _files mplay -function {prompt_c_{covid_19,docker_host,mpv_mpris,new_mail,todo,weather,newsboat,mumble,sfeed},cprompts:cache:async:{covid,weather,rss},get{gbooru,mangareader,nhentai},gitsubrepo,osutab,ffmpeg-{compress,gif},prettygitlog,paste,mplay,qff}() { +function {prompt_c_{covid_19,docker_host,mpv,new_mail,todo,weather,newsboat,mumble,sfeed},cprompts:cache:async:{covid,weather,rss},get{gbooru,mangareader,nhentai},gitsubrepo,osutab,prettygitlog,paste,mplay,qff,recordscreen,{send,format}irc}() { autoload -X } diff --git a/custom/aliases.zsh b/custom/aliases.zsh index 469fd5b..16bed39 100644 --- a/custom/aliases.zsh +++ b/custom/aliases.zsh @@ -1,4 +1,3 @@ -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 ls='ls --color=auto' alias grep='grep --color=auto' diff --git a/custom/functions/ffmpeg-compress b/custom/functions/ffmpeg-compress index f250570..677655b 100644 --- a/custom/functions/ffmpeg-compress +++ b/custom/functions/ffmpeg-compress @@ -1 +1 @@ -ffmpeg -hwaccel cuda -i $1 -c:v h264 -crf 30 -vf "normalize,scale=480:-1:flags=spline,mpdecimate" $2 +ffmpeg -hwaccel vdpau -i $1 -c:v h264 -crf 30 -movflags +faststart $2 diff --git a/custom/functions/formatirc b/custom/functions/formatirc new file mode 100644 index 0000000..1844e5d --- /dev/null +++ b/custom/functions/formatirc @@ -0,0 +1,9 @@ +local -A colormap +while read LINE; do + NICK="${${${=LINE#:}[1]%\!*}#:}" + CHAN="${${=LINE#:}[3]}" + RANDS=($RANDOM $RANDOM) + [ -z $colormap["$NICK"] ] && colormap["$NICK"]=${(%)$(<<< %F\{$(( $RANDS[1] % 6 + 1 ))\} )} + [ -z $colormap["$CHAN"] ] && colormap["$CHAN"]=${(%)$(<<< %F\{$(( $RANDS[2] % 6 + 1 ))\} )} + <<< "${colormap["$CHAN"]}${(l:10:)${CHAN}:0:10}${(%)$(<<< %F\{default\})} | ${colormap["$NICK"]}${(l:14:)${NICK}:0:14}${(%)$(<<< %F\{default\})} | ${${=LINE#:}[4,-1]#:}"; +done diff --git a/custom/functions/getgbooru b/custom/functions/getgbooru index 5a6eafe..a5a2067 100644 --- a/custom/functions/getgbooru +++ b/custom/functions/getgbooru @@ -2,8 +2,13 @@ local -a urls local -a fetch local page=0 while [ ${page} -eq 0 ] || [ ${#fetch} -eq 100 ]; do + <<< "Fetching page $page" fetch=($(curl -sZSGL "https://gelbooru.com/index.php?q=index&s=post&page=dapi&json=1&pid=$page&tags=${1}" | jq -r ".[].file_url")) urls+=($fetch) page=$(($page + 1)) done -[ ${#urls} -gt 0 ] && curl -L\# --remote-name-all $urls +if [[ $2 == "mpv" ]]; then + [ ${#urls} -gt 0 ] && mpv --loop $urls +else + [ ${#urls} -gt 0 ] && curl -RL\#C - --remote-name-all $urls +fi diff --git a/custom/functions/mplay b/custom/functions/mplay index 43561c3..a5758a2 100644 --- a/custom/functions/mplay +++ b/custom/functions/mplay @@ -1 +1,4 @@ -busctl call --no-pager --user org.mpris.MediaPlayer2.mpv /org/mpris/MediaPlayer2 org.mpris.MediaPlayer2.Player OpenUri s "$1" +local REPLY +zsocket ~/.mpvsock 2>/dev/null || return +print -u $REPLY "loadfile $@" +exec {REPLY}>&- diff --git a/custom/functions/recordscreen b/custom/functions/recordscreen new file mode 100644 index 0000000..a444a0c --- /dev/null +++ b/custom/functions/recordscreen @@ -0,0 +1 @@ +ffmpeg -hwaccel vdpau -y -filter_threads 4 -v warning -thread_queue_size 8 -f pulse -i default -video_size 1920x1080 -framerate 60 -thread_queue_size 8 -f x11grab -i :0 -c:v h264 -crf 30 -preset ultrafast -movflags +faststart -tune zerolatency $1 diff --git a/custom/functions/sendirc b/custom/functions/sendirc new file mode 100644 index 0000000..64060dc --- /dev/null +++ b/custom/functions/sendirc @@ -0,0 +1,2 @@ +([ -z $1 ] || [ -z $2 ]) && return +printf "PRIVMSG %s :%s\r\n" "$1" "${argv[2,-1]}" diff --git a/custom/prependsudo.zsh b/custom/prependsudo.zsh index 49178a1..d1299ae 100644 --- a/custom/prependsudo.zsh +++ b/custom/prependsudo.zsh @@ -1,10 +1,13 @@ # https://github.com/robbyrussell/oh-my-zsh/blob/master/plugins/sudo/sudo.plugin.zsh sudo-command-line() { [[ -z $BUFFER ]] && zle up-history - if [[ $BUFFER == sudo\ * ]]; then - LBUFFER="${LBUFFER#sudo }" + local rootcmd + [ -v commands\[sudo\] ] && rootcmd=sudo + [ -v commands\[doas\] ] && rootcmd=doas + if [[ $BUFFER == $rootcmd\ * ]]; then + LBUFFER="${LBUFFER#$rootcmd }" else - LBUFFER="sudo $LBUFFER" + LBUFFER="$rootcmd $LBUFFER" fi } zle -N sudo-command-line diff --git a/custom/segments/cprompts:cache:async:weather b/custom/segments/cprompts:cache:async:weather index 83f9fd4..cb1e826 100644 --- a/custom/segments/cprompts:cache:async:weather +++ b/custom/segments/cprompts:cache:async:weather @@ -1,8 +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": {"min": .min_temp, "max": .max_temp}, "icon": .weather_state_abbr}') +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=($(jq -r '.temp.min' <<< $result) $(jq -r '.temp.max' <<< $result) ${colors[$ico]:-white} ${icons[${ico:-X}]}) + typeset -g _cprompts_weather=($(( int(rint($(jq -r '.temp' <<< $result))) )) ${colors[$ico]:-white} ${icons[${ico:-X}]}) print ${_cprompts_weather} > $tmpfile fi diff --git a/custom/segments/prompt_c_irc_mentions b/custom/segments/prompt_c_irc_mentions new file mode 100644 index 0000000..d45663d --- /dev/null +++ b/custom/segments/prompt_c_irc_mentions @@ -0,0 +1,5 @@ +ROOT=~/IRC +[ -r $ROOT ] || return +for i in $ROOT/*/channels/*; do + if [ ${stats[1]:-0} -lt $(($epochtime[1]-86400)) ]; then +done diff --git a/custom/segments/prompt_c_mpv b/custom/segments/prompt_c_mpv new file mode 100644 index 0000000..0feadde --- /dev/null +++ b/custom/segments/prompt_c_mpv @@ -0,0 +1,6 @@ +local REPLY +zstyle -s ':custom:prompts:mpv' socket REPLY +[ -S $REPLY ] && zsocket $REPLY 2>/dev/null || return +_cprompts_mpv[2]="${${$(print -u $REPLY '{ "command": ["get_property", "media-title"] }' && read -eEu $REPLY)#*\"data\"([^[:print:]])#:([^[:print:]])#\"}%%(\"~\\\")*}" +exec {REPLY}>&- +[ -z $_cprompts_mpv[2] ] || p10k segment -b magenta -i '' -t "${_cprompts_mpv[2]}" diff --git a/custom/segments/prompt_c_mpv_mpris b/custom/segments/prompt_c_mpv_mpris deleted file mode 100644 index 878b287..0000000 --- a/custom/segments/prompt_c_mpv_mpris +++ /dev/null @@ -1,6 +0,0 @@ -local REPLY -zsocket ~/.mpvsock 2>/dev/null || return -typeset -ga _cprompts_mpv=($REPLY) -_cprompts_mpv[2]="${${$(print -u $_cprompts_mpv[1] '{ "command": ["get_property", "media-title"] }' && read -Eu $_cprompts_mpv[1])#*\"data\"([^[:print:]])#:([^[:print:]])#\"}%%(\"~\\\")*}" -exec {REPLY}>&- -[ -z $_cprompts_mpv[2] ] || p10k segment -b magenta -i '' -t "${_cprompts_mpv[2]:0:20}$([ ${#_cprompts_mpv[2]} -gt 20 ] && print ...)" diff --git a/custom/segments/prompt_c_new_mail b/custom/segments/prompt_c_new_mail index 00d5314..b17b9c3 100644 --- a/custom/segments/prompt_c_new_mail +++ b/custom/segments/prompt_c_new_mail @@ -1,4 +1,6 @@ -local new_mails=(~/Mail/*/Inbox/new/*(.N)) +local REPLY +zstyle -s ':custom:prompts:mail' glob REPLY +local new_mails=(${~REPLY}(.N)) typeset -g _cprompts_mail_count=${#new_mails} [[ ${_cprompts_mail_count} -gt 0 ]] || return p10k segment -b yellow -i '' -t "${_cprompts_mail_count:-unknown}" diff --git a/custom/segments/prompt_c_newsboat b/custom/segments/prompt_c_newsboat index d885431..b3aa64b 100644 --- a/custom/segments/prompt_c_newsboat +++ b/custom/segments/prompt_c_newsboat @@ -1,6 +1,7 @@ [ -v commands\[sqlite3\] ] || return -local newsboatdb=~/.newsboat/cache.db +local REPLY +zstyle -s ':custom:prompts:newsboat' database REPLY if [ ! -v _cprompts_newsboat ]; then - typeset -g _cprompts_newsboat="$(sqlite3 ${newsboatdb} --ascii 'SELECT COUNT(id) FROM rss_item WHERE unread == 1 AND guid GLOB "yt:video:*"')" + typeset -g _cprompts_newsboat="$(sqlite3 $REPLY --ascii 'SELECT COUNT(id) FROM rss_item WHERE unread == 1 AND guid GLOB "yt:video:*"')" fi p10k segment -b red -i '' -t "${_cprompts_newsboat}" diff --git a/custom/segments/prompt_c_todo b/custom/segments/prompt_c_todo index 7bc38d9..29d4edf 100644 --- a/custom/segments/prompt_c_todo +++ b/custom/segments/prompt_c_todo @@ -2,7 +2,7 @@ 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 todofi=(${(f@)$(< todo.txt)}) local t_nf=0 local t_f=0 local colors=(red yellow green) diff --git a/custom/segments/prompt_c_weather b/custom/segments/prompt_c_weather index 36e2359..df31128 100644 --- a/custom/segments/prompt_c_weather +++ b/custom/segments/prompt_c_weather @@ -28,10 +28,10 @@ colors[sn]="white" if [ ! -v _cprompts_weather ]; then zstat -A stats +mtime -- $tmpfile 2>/dev/null - if [ ${stats[1]:-0} -lt $(($epochtime[1]-21600)) ]; then + if [ ${stats[1]:-0} -lt $(($epochtime[1]-3600)) ]; then cprompts:cache:async:weather &! else typeset -g _cprompts_weather=($(< $tmpfile)) fi fi -[ -v _cprompts_weather ] && p10k segment -b ${_cprompts_weather[3]:-white} -i ${_cprompts_weather[4]:-\?} -t "${_cprompts_weather[1]:-unknown} - ${_cprompts_weather[2]:-unknown}" +[ -v _cprompts_weather ] && p10k segment -b ${_cprompts_weather[2]:-white} -i ${_cprompts_weather[3]:-\?} -t "${_cprompts_weather[1]:-unknown}" diff --git a/powerlevel-config/all.zsh b/powerlevel-config/all.zsh index 4b3ccd0..c6781ee 100644 --- a/powerlevel-config/all.zsh +++ b/powerlevel-config/all.zsh @@ -4,7 +4,6 @@ source ${ZDOTDIR}/powerlevel-config/dir.zsh source ${ZDOTDIR}/powerlevel-config/disk.zsh source ${ZDOTDIR}/powerlevel-config/misc.zsh source ${ZDOTDIR}/powerlevel-config/prompt-char.zsh -source ${ZDOTDIR}/powerlevel-config/prompt-elements.zsh source ${ZDOTDIR}/powerlevel-config/separators.zsh source ${ZDOTDIR}/powerlevel-config/status.zsh source ${ZDOTDIR}/powerlevel-config/time.zsh diff --git a/powerlevel-config/prompt-elements.zsh b/powerlevel-config/prompt-elements.zsh deleted file mode 100644 index d3b3bb4..0000000 --- a/powerlevel-config/prompt-elements.zsh +++ /dev/null @@ -1,34 +0,0 @@ -typeset -g POWERLEVEL9K_LEFT_PROMPT_ELEMENTS=( - os_icon - time - battery - disk_usage - ssh - root_indicator - vim_shell - newline - vi_mode - status - dir - dir_writable -) -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 - c_new_mail - c_sfeed -# c_newsboat -# c_mumble - c_weather - c_covid_19 -) -fi -POWERLEVEL9K_RIGHT_PROMPT_ELEMENTS+=( - newline - command_execution_time - background_jobs - vcs -) diff --git a/powerlevel10k b/powerlevel10k index 6c9d097..71b39f0 160000 --- a/powerlevel10k +++ b/powerlevel10k @@ -1 +1 @@ -Subproject commit 6c9d0977a6378239f4153f5d3700bc5f70b36c3d +Subproject commit 71b39f0da9236acb1323f2833e7cec3ef3eda365 diff --git a/preferences.zsh b/preferences.zsh index 1653bf9..3c6dc06 100644 --- a/preferences.zsh +++ b/preferences.zsh @@ -16,25 +16,25 @@ export LESS_TERMCAP_us=$'\e[01;32m' setopt appendhistory autocd auto_param_slash c_bases extendedglob nomatch notify hist_ignore_all_dups hist_ignore_space share_history nobeep if [[ -r "${ZDOTDIR}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh" ]]; then - source ${ZDOTDIR}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh typeset -g ZSH_HIGHLIGHT_HIGHLIGHTERS=( main brackets pattern cursor ) + source ${ZDOTDIR}/zsh-syntax-highlighting/zsh-syntax-highlighting.zsh fi if [[ -r "${ZDOTDIR}/zsh-autosuggestions/zsh-autosuggestions.zsh" ]]; then - source ${ZDOTDIR}/zsh-autosuggestions/zsh-autosuggestions.zsh typeset -g ZSH_AUTOSUGGEST_STRATEGY=(history completion) typeset -g ZSH_AUTOSUGGEST_USE_ASYNC=true + source ${ZDOTDIR}/zsh-autosuggestions/zsh-autosuggestions.zsh fi -zstyle -s ':custom:preferences' prompt REPLY -if [[ $REPLY == "p9k" ]] && [[ -r "${ZDOTDIR}/powerlevel10k/powerlevel10k.zsh-theme" ]]; then - source ${ZDOTDIR}/powerlevel10k/powerlevel10k.zsh-theme +zstyle -s ':custom:preferences' prompt _cur_prompt +if [[ $_cur_prompt == "p9k" ]] && [[ -r "${ZDOTDIR}/powerlevel10k/powerlevel10k.zsh-theme" ]]; then source ${ZDOTDIR}/powerlevel-config/all.zsh + source ${ZDOTDIR}/powerlevel10k/powerlevel10k.zsh-theme else autoload -Uz promptinit promptinit diff --git a/zsh-syntax-highlighting b/zsh-syntax-highlighting index fb929ed..62c5575 160000 --- a/zsh-syntax-highlighting +++ b/zsh-syntax-highlighting @@ -1 +1 @@ -Subproject commit fb929edc30192407a9298aad64f55ca1b19a464e +Subproject commit 62c5575848f1f0a96161243d18497c247c9f52df