Last active
March 5, 2025 08:21
-
-
Save heikomat/e09d45b6cee2bb8a9aff889bf0b7af0b to your computer and use it in GitHub Desktop.
my zshrc for iterm2
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# enable colors and prompt substitution (so the git_prompt_info function can be used) | |
autoload -U colors && colors | |
setopt PROMPT_SUBST | |
# enable bash-style completions | |
autoload -Uz compinit | |
compinit | |
autoload -U +X bashcompinit && bashcompinit | |
# define some aliases | |
alias nom='npm' | |
alias gco='git checkout' | |
alias gst='git status' | |
# style the prompt | |
function parse_git_dirty() { | |
local STATUS=$(git status --porcelain 2> /dev/null | tail -n 1) | |
if [[ -n $STATUS ]]; then | |
echo "\033[38;5;3m" # yellow | |
else | |
echo "\033[38;5;49m" # light green | |
fi | |
} | |
function git_prompt_info() { | |
local ref=$(git symbolic-ref --quiet HEAD 2>/dev/null \ | |
|| git rev-parse --short HEAD 2>/dev/null) | |
[[ -n $ref ]] || return | |
echo "%{$fg[green]%}@$(parse_git_dirty)${ref#refs/heads/}%{$reset_color%}" | |
} | |
PROMPT='%{$fg[cyan]%}%c%{$reset_color%}$(git_prompt_info) ' | |
# some hommade functions | |
mp4() {ffmpeg -i "$1" -crf 18 -threads $(sysctl -n hw.ncpu) -preset veryslow -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" "${1%.*}.mp4"} | |
mp42() {ffmpeg -i "$1" -crf 18 -threads $(sysctl -n hw.ncpu) -preset veryslow -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" "${1%.*}_2.mp4"} | |
mp41080() {ffmpeg -i "$1" -crf 18 -threads $(sysctl -n hw.ncpu) -preset veryslow -vf "zscale=width='min(1920,iw)':height=-2:filter=lanczos" "${1%.*}_1080.mp4"} | |
mp41080low() {ffmpeg -i "$1" -crf 24 -threads $(sysctl -n hw.ncpu) -preset veryslow -vf "zscale=width='min(1920,iw)':height=-2:filter=lanczos" "${1%.*}_1080_low.mp4"} | |
mp41080lowest() {ffmpeg -i "$1" -crf 28 -threads $(sysctl -n hw.ncpu) -preset veryslow -vf "zscale=width='min(1920,iw)':height=-2:filter=lanczos" "${1%.*}_1080_low.mp4"} | |
mp4720() {ffmpeg -i "$1" -crf 18 -threads $(sysctl -n hw.ncpu) -preset veryslow -vf "zscale=width='min(1280,iw)':height=-2:filter=lanczos" "${1%.*}_720.mp4"} | |
mp4720low() {ffmpeg -i "$1" -crf 24 -threads $(sysctl -n hw.ncpu) -preset veryslow -vf "zscale=width='min(1280,iw)':height=-2:filter=lanczos" "${1%.*}_720.mp4"} | |
mp4720lowest() {ffmpeg -i "$1" -crf 28 -threads $(sysctl -n hw.ncpu) -preset veryslow -vf "zscale=width='min(1280,iw)':height=-2:filter=lanczos" "${1%.*}_720_low.mp4"} | |
mp4med() {ffmpeg -i "$1" -crf 22 -threads $(sysctl -n hw.ncpu) -preset veryslow "${1%.*}.mp4"} | |
mp4low() {ffmpeg -i "$1" -crf 26 -threads $(sysctl -n hw.ncpu) -preset veryslow "${1%.*}.mp4"} | |
h264() {ffmpeg -i "$1" -crf 18 -threads $(sysctl -n hw.ncpu) -preset veryslow "${1%.*}_h264.mp4"} | |
mp4tiny() {ffmpeg -i "$1" -crf 32 -threads $(sysctl -n hw.ncpu) -preset veryslow "${1%.*}_tiny.mp4"} | |
h265() {ffmpeg -i "$1" -c:v libx265 -crf 24 -threads $(sysctl -n hw.ncpu) -preset slow "${1%.*}_h265.mp4"} | |
h265720() {ffmpeg -i "$1" -c:v libx265 -crf 24 -threads $(sysctl -n hw.ncpu) -preset slow -vf "pad=ceil(iw/2)*2:ceil(ih/2)*2" "${1%.*}_h265.mp4"} | |
h265low() {ffmpeg -i "$1" -c:v libx265 -crf 32 -threads $(sysctl -n hw.ncpu) -preset veryslow "${1%.*}_h265.mp4"} | |
forcekill() {kill -9 $(ps -A | grep -i "$1" | cut -d ' ' -f 1)} | |
clean_branches() {git remote prune origin && (git branch -vv | grep 'origin/.*: gone]' | awk '{print $1}' | xargs git branch -d)} | |
get_seconds_from_string() { | |
TIME="0" | |
TIME_PARTS=$1 | |
SECONDS_FACTORS=("3600" "60" "1" "0.033") | |
IFS=':' read -rA TIME_PARTS <<< "${1}" | |
for i in {1..$#TIME_PARTS}; do | |
TIME_PART=${TIME_PARTS[$i]} | |
TIME=$(bc -l <<< "${TIME}+${TIME_PART}*${SECONDS_FACTORS[$i]}") | |
done | |
echo -n "${TIME}" | |
} | |
vcut() { | |
base_filename="${1%.*}" | |
file_extension="${1##*.}" | |
start_time="${2}" | |
start_time_seconds=$(get_seconds_from_string "$2") | |
end_time_seconds=$(get_seconds_from_string "$3") | |
duration_seconds=$(bc -l <<< "${end_time_seconds}-${start_time_seconds}") | |
start_time_name=$(echo "${start_time//;/_}") | |
ffmpeg -hide_banner -y -ss ${start_time_seconds} -i "$1" -to ${duration_seconds} -c copy "${base_filename}_${start_time_name}.${file_extension}" | |
echo "${base_filename}_${start_time_name}.${file_extension}" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment