2024-07-11 11:53:41 +00:00
|
|
|
#!/usr/bin/env zsh
|
|
|
|
|
2024-08-16 13:47:18 +00:00
|
|
|
y() { # a yazi wrapper that returns last dir
|
|
|
|
local tmp="$(mktemp -t "yazi-cwd.XXXXXX")"
|
|
|
|
yazi "$@" --cwd-file="$tmp"
|
|
|
|
if cwd="$(cat -- "$tmp")" && [ -n "$cwd" ] && [ "$cwd" != "$PWD" ]; then
|
|
|
|
builtin cd -- "$cwd"
|
|
|
|
fi
|
|
|
|
rm -f -- "$tmp"
|
|
|
|
}
|
|
|
|
|
|
|
|
take() { # shortcut for creating and going into dir
|
2024-07-11 11:53:41 +00:00
|
|
|
mkdir -p $1
|
|
|
|
cd $1
|
|
|
|
}
|
|
|
|
|
|
|
|
# terminal weather shortcut
|
2024-08-16 13:47:18 +00:00
|
|
|
wttr() {
|
2024-07-11 11:53:41 +00:00
|
|
|
if [[ -n "$1" ]]
|
2024-08-16 13:47:18 +00:00
|
|
|
then
|
2024-07-11 11:53:41 +00:00
|
|
|
curl "wttr.in/$1?format=v2"
|
2024-08-16 13:47:18 +00:00
|
|
|
else
|
2024-07-11 11:53:41 +00:00
|
|
|
curl "wttr.in/Leipzig?format=v2"
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# function for easily converting a video for web
|
2024-08-16 13:47:18 +00:00
|
|
|
webvideo() {
|
2024-07-11 11:53:41 +00:00
|
|
|
if [ $# -eq 0 ]; then
|
|
|
|
echo "No arguments supplied, example usage: webvideo FILENAME --resize 1920 --mute"
|
|
|
|
else
|
|
|
|
zparseopts -E -D -- -resize:=opt_resize -mute=opt_mute
|
|
|
|
|
|
|
|
file=$(basename -- "$1")
|
|
|
|
extension="${file##*.}"
|
|
|
|
filename="${file%.*}"
|
|
|
|
width="${opt_resize[2]}"
|
|
|
|
w="${width:-trunc(iw/2)*2}"
|
|
|
|
h="trunc(ih/2)*2"
|
|
|
|
|
|
|
|
if [[ -n "$width" ]]
|
|
|
|
then
|
|
|
|
h="trunc(ow/a/2)*2"
|
|
|
|
fi
|
|
|
|
|
|
|
|
scale="scale=$w\:$h"
|
|
|
|
ffmpeg -ss 00:00:02 -i $1 -frames:v 1 -vf $scale $filename.jpg
|
|
|
|
|
|
|
|
if [ -z "${opt_mute}" ]; then
|
|
|
|
ffmpeg -i $1 -map_metadata -1 -c:a copy -c:v libx264 -crf 26 -preset veryslow -profile:v main -pix_fmt yuv420p -movflags +faststart -vf $scale $filename.h264.mp4
|
|
|
|
ffmpeg -i $1 -map_metadata -1 -c:a libopus -b:a 64k -c:v libaom-av1 -crf 50 -b:v 0 -pix_fmt yuv420p -movflags +faststart -cpu-used 8 -vf $scale $filename.av1.webm
|
|
|
|
else
|
|
|
|
ffmpeg -i $1 -map_metadata -1 -an -c:v libx264 -crf 26 -preset veryslow -profile:v main -pix_fmt yuv420p -movflags +faststart -vf $scale $filename.h264.mp4
|
|
|
|
ffmpeg -i $1 -map_metadata -1 -an -c:v libaom-av1 -crf 50 -b:v 0 -pix_fmt yuv420p -movflags +faststart -cpu-used 8 -vf $scale $filename.av1.webm
|
|
|
|
fi
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
2024-08-16 13:47:18 +00:00
|
|
|
pdf() {
|
2024-07-24 11:36:04 +00:00
|
|
|
gallery
|
2024-07-11 11:53:41 +00:00
|
|
|
convert *.jpg -auto-orient -monochrome temp.pdf
|
|
|
|
ocrmypdf --rotate-pages --optimize 3 --jpeg-quality 70 temp.pdf document.pdf
|
|
|
|
rm temp.pdf
|
|
|
|
}
|
2024-07-11 12:08:31 +00:00
|
|
|
|
|
|
|
# fancy vim/shell switch with ctrl-z (see zshrc)
|
2024-08-16 13:47:18 +00:00
|
|
|
fancy-ctrl-z() {
|
2024-07-11 12:08:31 +00:00
|
|
|
if [[ $#BUFFER -eq 0 ]]; then
|
|
|
|
BUFFER="fg"
|
|
|
|
zle accept-line
|
|
|
|
else
|
|
|
|
zle push-input
|
|
|
|
zle clear-screen
|
|
|
|
fi
|
|
|
|
}
|
|
|
|
|
|
|
|
# easy vim/terminal switch after loading zsh-functions
|
|
|
|
zle -N fancy-ctrl-z
|
|
|
|
bindkey '^Z' fancy-ctrl-z
|