Add a readme, shorten MPV size, source plugins only if found, use zstyles

This commit is contained in:
Alex 2020-05-26 12:20:28 +02:00
parent 99abcc5467
commit 46d0108641
Signed by: caskd
GPG Key ID: F92BA85F61F4C173
4 changed files with 58 additions and 22 deletions

35
README.md Normal file
View File

@ -0,0 +1,35 @@
# My ZSH config
This is my daily driver for my shell, it's *heavily customized* and relies on a lot of ZSH features
It is enhanced by a few things which are submodules of this repo:
- Powerlevel10k
- zsh-autosuggestions
- zsh-synthax-highlighting
Some custom prompts depend on these binaries in your path:
- jq *(for JSON parsing)*
- sqlite *(if using the youtube RSS plugin [depends on newsboat cache database])*
- curl *(for fetching external API data)*
- busctl *(for interacting with mpv over mpris dbus IPC, see* [mpv-mpris](https://github.com/hoyon/mpv-mpris)
While i do attempt to make this usable widely, don't rely on it. If you want to use this and have it work as you want it, it's expected that you can read manual pages and know at least a bit of shell scripting.
**These variables should be set in your .zshenv or your profiles/environment files**
## ZDOTDIR
This environment variable should be set to the root of your repository (usually ~/.config/zsh or ~/.zsh)
## zstyles
### :custom:preferences
Because font support detection is a bit complicated, the `prompt` variable in this zstyle allows you to manually toggle on a specific prompt (now only p9k is available)
### :custom:prompts:weather
This should be your location in the `woeid` format. https://en.wikipedia.org/wiki/WOEID
The weather is fetched from [MetaWeather](https://metaweather.com) (props to them for having a API that is authentication-free) every 12h. It is not updated live in the prompt because i don't really expect people to have their terminal open for 12h but it can be updated manually by deleting the disk cache stored at `$CACHEPATH/weather` and unsetting the `_cprompts_weather` variable in this specific order.
### :custom:prompts:covid
This is a country slug for your country. This is used in the `covid_19()` prompt which shows you the daily actively infected people. It behaves the same as the weather one except that it is updated every 24h and is fetched from [Covid19API](https://api.covid19api.com/) which has a really nice JSON api which is completly free and requires no authentication.

View File

@ -33,13 +33,6 @@ function getnhentai {
done
[ ! -z $2 ] && cd ..
}
function gethanime {
local IDS=($(curl -sSL "https://members.hanime.tv/api/v3/videos_manifests/$1" -H 'x-directive: api' | jq -e '.videos_manifest.servers[].streams | sort_by(.width) | .[].id'))
[ ! -z $2 ] && print "https://hanime.tv/api/v1/m3u8s/$i.m3u8" && return
for i in $IDS; do
[ ! -z $i ] && ffmpeg -i "https://hanime.tv/api/v1/m3u8s/$i.m3u8" -c:v copy ${2:-$1.mkv} && break
done
}
function man {
LESS_TERMCAP_md=$'\e[01;31m' \
LESS_TERMCAP_me=$'\e[0m' \

View File

@ -19,11 +19,13 @@ function prompt_c_youtube() {
}
function prompt_c_covid_19() {
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
typeset -g _cprompts_covid=$(curl -sL https://api.covid19api.com/country/germany | jq -e '. |= sort_by (.Date) | .[-1].Active')
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
else
typeset -g _cprompts_covid=$(< $tmpfile)
@ -62,7 +64,9 @@ function prompt_c_weather() {
if [ ! -v _cprompts_weather ]; then
zstat -A stats +mtime -- $tmpfile 2>/dev/null
if [[ $stats[1] < $(($epochtime[1]-21600)) ]]; then
local result=$(curl -sL https://www.metaweather.com/api/location/${_cprompts_weather_loc:-1339615}/ | jq -e '.consolidated_weather[0] | {"temp": .the_temp, "icon": .weather_state_abbr}')
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]:-?})
@ -80,7 +84,7 @@ function prompt_c_mpv_mpris() {
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:40}$([ ${#_cprompts_mpv} -gt 40 ] && print ...)"
[ -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

View File

@ -5,16 +5,17 @@ typeset -g SAVEHIST=1000
typeset -g ZLE_RPROMPT_INDENT=0
setopt appendhistory autocd extendedglob nomatch notify hist_ignore_all_dups hist_ignore_space nobeep
if [[ $_set_prompt == "p9k" ]]; then
zstyle -s ':custom:preferences' prompt REPLY
if [[ $REPLY == "p9k" ]] && [[ -r "${ZDOTDIR}/powerlevel10k/powerlevel10k.zsh-theme" ]]; then
source ${ZDOTDIR}/powerlevel10k/powerlevel10k.zsh-theme
source ${ZDOTDIR}/powerlevel-config/all.zsh
else
export TERM="xterm";
autoload -Uz promptinit
promptinit
prompt clint
fi
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
@ -22,7 +23,10 @@ typeset -g ZSH_HIGHLIGHT_HIGHLIGHTERS=(
pattern
cursor
)
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
fi