major zsh cleanup

This commit is contained in:
sebastian committed 2026-09-17 13:20:08 +02:00
1 parent c9ab492c60
commit a9ef0503c7
4 files changed
+335 -210

No files matched your search

+85
View File
@@ -0,0 +1,85 @@
# --- Bandcamp ----------------------------------------------------------------
# bandcampdl <url>: download an album/track as MP3 (best quality) with
# metadata and cover art, sorted into Artist/Year - Album/
bandcampdl() {
if [[ -z "$1" ]]; then
echo "Usage: bandcampdl <bandcamp-url>"
return 1
fi
yt-dlp \
-x \
--audio-format mp3 \
--audio-quality 0 \
--embed-metadata \
--embed-thumbnail \
--convert-thumbnails jpg \
-o "%(album_artist)s/%(release_year)s - %(album)s/%(album_artist)s - %(album)s - %(track_number)02d - %(title)s.%(ext)s" \
"$1"
}
# bandcampbatch <file>: run bandcampdl for every URL in a file
# (empty lines and lines starting with # are skipped)
bandcampbatch() {
local file="$1" url
if [[ ! -r "$file" ]]; then
echo "Usage: bandcampbatch <url-file>"
return 1
fi
while IFS= read -r url; do
[[ -z "$url" || "$url" == \#* ]] && continue
bandcampdl "$url"
done < "$file"
}
# bandcamplist <https://band.bandcamp.com/music> [output.txt]:
# write all album/track URLs of an artist to a file
# (default: bandcamp-<band>.txt) - input for bandcampbatch
bandcamplist() {
local url outfile tmpfile band count
if (( ! $+commands[yt-dlp] )); then
echo "Fehler: yt-dlp wurde nicht gefunden."
return 1
fi
if (( $# < 1 || $# > 2 )); then
echo "Usage:"
echo " bandcamplist <https://band.bandcamp.com/music> [output.txt]"
return 1
fi
url="$1"
# zsh stores capture groups of =~ in $match
if [[ ! "$url" =~ ^https?://([^.]+)\.bandcamp\.com/music/?$ ]]; then
echo "Fehler: Keine gueltige Bandcamp-/music-URL:"
echo " $url"
return 1
fi
band="${match[1]}"
outfile="${2:-bandcamp-${band}.txt}"
tmpfile=$(mktemp)
if ! yt-dlp --flat-playlist --print webpage_url "$url" | sort -u > "$tmpfile"; then
rm -f "$tmpfile"
echo "Fehler beim Abrufen der Links."
return 1
fi
count=$(wc -l < "$tmpfile")
if (( count == 0 )); then
rm -f "$tmpfile"
echo "Keine Album- oder Track-Links gefunden."
return 1
fi
mv "$tmpfile" "$outfile"
echo "✓ $count Links nach '$outfile' geschrieben."
}
+118
View File
@@ -0,0 +1,118 @@
if [[ -n "$TMUX" ]]; then
autoload -Uz add-zsh-hook
# -------------------------------------------------------------------------
# Basisname des Windows aus aktuellem Verzeichnis
# -------------------------------------------------------------------------
_tmux_set_base_window_name() {
local name
if [[ "$PWD" == "$HOME" ]]; then
name="sebastian"
else
name="${PWD:t}"
fi
# Basisnamen separat merken
tmux set-option \
-w \
-t "$TMUX_PANE" \
@base_window_name "$name" \
2>/dev/null
_tmux_update_window_name
}
# -------------------------------------------------------------------------
# Window-Name aus Basisname + allen SSH-Sessions dieses Windows bauen
#
# Beispiel:
# projects 🔐 P1→labgw P4→prod
# -------------------------------------------------------------------------
_tmux_update_window_name() {
local base ssh_info line
base="$(
tmux show-options \
-w \
-v \
-t "$TMUX_PANE" \
@base_window_name \
2>/dev/null
)"
[[ -z "$base" ]] && base="${PWD:t}"
ssh_info=""
while IFS= read -r line; do
[[ -z "$line" ]] && continue
if [[ -n "$ssh_info" ]]; then
ssh_info+=" "
fi
ssh_info+="$line"
done < <(
tmux list-panes \
-t "$TMUX_PANE" \
-F '#{?@ssh_host,P#{pane_index}→#{@ssh_host},}' \
2>/dev/null
)
if [[ -n "$ssh_info" ]]; then
tmux rename-window \
-t "$TMUX_PANE" \
"${base} 🔐 ${ssh_info}" \
2>/dev/null
else
tmux rename-window \
-t "$TMUX_PANE" \
"$base" \
2>/dev/null
fi
}
add-zsh-hook chpwd _tmux_set_base_window_name
_tmux_set_base_window_name
# -------------------------------------------------------------------------
# SSH wrapper
# -------------------------------------------------------------------------
ssh() {
local host rc
# Bewusst SSH-Alias nehmen:
# ssh labgw
# zeigt "labgw", nicht die dahinterliegende IP.
host="$(
command ssh -G "$@" 2>/dev/null |
awk '$1 == "host" { print $2; exit }'
)"
if [[ -n "$host" ]]; then
tmux set-option \
-p \
-t "$TMUX_PANE" \
@ssh_host "$host" \
2>/dev/null
_tmux_update_window_name
fi
command ssh "$@"
rc=$?
# SSH-Markierung dieses Panes entfernen
tmux set-option \
-p \
-u \
-t "$TMUX_PANE" \
@ssh_host \
2>/dev/null
_tmux_update_window_name
return $rc
}
fi