From 95183069cedd8feb540588440630403771792155 Mon Sep 17 00:00:00 2001 From: Hannes Date: Fri, 14 Aug 2026 13:39:41 +0200 Subject: [PATCH] some additions --- completions/copytime.fish | 4 + completions/vrot.fish | 5 + configs/alias_useful.fish | 3 +- configs/arch_config.fish | 9 ++ functions/copytime.fish | 267 +++++++++++++++++++++++++++++++ functions/vrot.fish | 319 ++++++++++++++++++++++++++++++++++++++ 6 files changed, 606 insertions(+), 1 deletion(-) create mode 100644 completions/copytime.fish create mode 100644 completions/vrot.fish create mode 100644 functions/copytime.fish create mode 100644 functions/vrot.fish diff --git a/completions/copytime.fish b/completions/copytime.fish new file mode 100644 index 0000000..de882f1 --- /dev/null +++ b/completions/copytime.fish @@ -0,0 +1,4 @@ +complete -c copytime -f -a '(__fish_complete_path)' -d 'Source file' +complete -c copytime -f -a '(__fish_complete_path)' -d 'Destination file' +complete -c copytime -s d -l date -x -d 'Set container creation date directly (e.g. 2020-01-02 03:04:05)' +complete -c copytime -s h -l help -d 'Show help' diff --git a/completions/vrot.fish b/completions/vrot.fish new file mode 100644 index 0000000..f0e00d3 --- /dev/null +++ b/completions/vrot.fish @@ -0,0 +1,5 @@ +complete -c vrot -f -a '(__fish_complete_suffix .mp4 .mkv .mov .m4v .webm .avi .ts .mts .m2ts .flv .wmv .mpg .mpeg .vob .3gp)' -d 'Video file' +complete -c vrot -s h -l help -d 'Show help' +complete -c vrot -s r -l reencode -d 'Re-encode the video (rotate pixels, works everywhere)' +complete -c vrot -s a -l angle -x -a '90 180 270' -d 'Rotation angle (degrees clockwise)' +complete -c vrot -s p -l preset -x -a 'ultrafast superfast veryfast faster fast medium slow slower veryslow' -d 'x264/x265 encoder preset' diff --git a/configs/alias_useful.fish b/configs/alias_useful.fish index 00fd99d..55c15ad 100755 --- a/configs/alias_useful.fish +++ b/configs/alias_useful.fish @@ -71,6 +71,7 @@ if test -e /usr/bin/nano echo "Usage: nanorm {FILE}" return 1 end + rm $argv[1] nano $argv[1] end else @@ -364,4 +365,4 @@ function git_cred echo "no .git/config file" echo "could not add the credentials helper" end -end \ No newline at end of file +end diff --git a/configs/arch_config.fish b/configs/arch_config.fish index cd4d728..a0adf9a 100755 --- a/configs/arch_config.fish +++ b/configs/arch_config.fish @@ -165,3 +165,12 @@ if test -e /usr/bin/reflector alias mirrord='sudo reflector --latest 50 --number 20 --sort delay --save /etc/pacman.d/mirrorlist' alias mirrors='sudo reflector --latest 50 --number 20 --sort score --save /etc/pacman.d/mirrorlist' end + +function pacman-autoremove + set -l orphans (pacman -Qtdq) + if test (count $orphans) -gt 0 + sudo pacman -Rns $orphans + else + echo "No orphaned packages." + end +end \ No newline at end of file diff --git a/functions/copytime.fish b/functions/copytime.fish new file mode 100644 index 0000000..1f5f2bf --- /dev/null +++ b/functions/copytime.fish @@ -0,0 +1,267 @@ +function copytime -d 'Copy timestamps between files; for media files also copies the container creation date' + argparse -n copytime 'h/help' 'd/date=' -- $argv + or return 2 + + if set -q _flag_help + __copytime_usage + return 0 + end + + if test (count $argv) -lt 1 + __copytime_usage + return 2 + end + + __copytime_colors + + if set -q _flag_date + set -l rc 0 + for f in $argv + __copytime_setdate "$f" "$_flag_date" + or set rc 1 + end + return $rc + end + + if test (count $argv) -lt 2 + __copytime_usage + return 2 + end + + set -l src $argv[1] + set -l dsts $argv[2..-1] + + if not test -e "$src" + __copytime_error "no such source: '$src'" + return 1 + end + + switch (uname -s) + case Linux + __copytime_linux "$src" $dsts + case Darwin + __copytime_darwin "$src" $dsts + case '*' + __copytime_error "unsupported platform '(uname -s)'" + return 1 + end +end + +function __copytime_linux + set -l src $argv[1] + set -l rc 0 + + set -l mtime (stat -c '%y' -- "$src" | string replace -r '\.[0-9]+' '') + set -l atime (stat -c '%x' -- "$src" | string replace -r '\.[0-9]+' '') + echo "$vrot_c_dim source: $src$vrot_c_reset" + echo "$vrot_c_dim modified: $mtime$vrot_c_reset" + echo "$vrot_c_dim accessed: $atime$vrot_c_reset" + + set -l birth (stat -c '%w' -- "$src") + if test -n "$birth"; and string match -q '*[-Unknown]*' "$birth" + set birth '' + end + if test -n "$birth" + set -l btime (string replace -r '\.[0-9]+' '' -- "$birth") + echo "$vrot_c_dim created: $btime (filesystem creation time cannot be set on Linux)$vrot_c_reset" + end + + set -l created (__copytime_mediadate "$src") + if test -n "$created" + set -l ctime (string replace 'T' ' ' -- "$created" | string replace -r '\.\d+Z?$' '') + echo "$vrot_c_dim container created: $ctime$vrot_c_reset" + end + + for dst in $argv[2..-1] + if not test -e "$dst" + __copytime_error "skipping missing destination: '$dst'" + set rc 1 + continue + end + touch -a -m -r "$src" "$dst" + if test $status -ne 0 + __copytime_error "failed to copy timestamps to '$dst'" + set rc 1 + continue + end + set -l dm (stat -c '%y' -- "$dst" | string replace -r '\.[0-9]+' '') + echo "$vrot_c_ok ✔ $dst$vrot_c_dim ← modified $dm$vrot_c_reset" + if test -n "$created" + __copytime_meta "$dst" "$created" + or set rc 1 + end + end + return $rc +end + +function __copytime_darwin + set -l src $argv[1] + set -l rc 0 + + set -l mtime (stat -f '%Sm' -t '%Y-%m-%d %H:%M:%S' -- "$src") + set -l btime (stat -f '%SB' -t '%Y-%m-%d %H:%M:%S' -- "$src") + echo "$vrot_c_dim source: $src$vrot_c_reset" + echo "$vrot_c_dim modified: $mtime$vrot_c_reset" + echo "$vrot_c_dim created: $btime$vrot_c_reset" + + set -l created (__copytime_mediadate "$src") + if test -n "$created" + set -l ctime (string replace 'T' ' ' -- "$created" | string replace -r '\.\d+Z?$' '') + echo "$vrot_c_dim container created: $ctime$vrot_c_reset" + end + + set -l birth (stat -f '%SB' -t '%m/%d/%Y %H:%M:%S' -- "$src") + + for dst in $argv[2..-1] + if not test -e "$dst" + __copytime_error "skipping missing destination: '$dst'" + set rc 1 + continue + end + touch -a -m -r "$src" "$dst" + if test $status -ne 0 + set rc 1 + continue + end + if command -q SetFile + SetFile -d "$birth" "$dst" + if test $status -ne 0 + __copytime_error "failed to set creation time on '$dst'" + set rc 1 + end + else + echo "$vrot_c_warn ⚠ SetFile not found — creation time not copied to $dst$vrot_c_reset" >&2 + end + set -l db (stat -f '%SB' -t '%Y-%m-%d %H:%M:%S' -- "$dst") + echo "$vrot_c_ok ✔ $dst$vrot_c_dim ← created $db$vrot_c_reset" + if test -n "$created" + __copytime_meta "$dst" "$created" + or set rc 1 + end + end + return $rc +end + +function __copytime_mediadate + if not command -q ffprobe + return 0 + end + if not __copytime_media "$argv[1]" + return 0 + end + set -l d (ffprobe -v error -show_entries format_tags=creation_time \ + -of default=noprint_wrappers=1:nokey=1 "$argv[1]")[1] + string match -rq '^[0-9]{4}-[0-9]{2}-[0-9]{2}' "$d"; and echo "$d" +end + +function __copytime_meta + set -l dst $argv[1] + set -l date $argv[2] + + if not command -q ffmpeg + return 0 + end + if not __copytime_media "$dst" + return 0 + end + + set -l tmp (string join '' "$dst" .ct. (random) (path extension "$dst")) + ffmpeg -hide_banner -loglevel error -y -i "$dst" -map 0 -map '-0:d' -map '-0:t' \ + -c copy -metadata creation_time="$date" "$tmp" + if test $status -ne 0 + rm -f "$tmp" + __copytime_error "failed to copy container creation date to '$dst'" + return 1 + end + mv -f -- "$tmp" "$dst" + if test $status -ne 0 + rm -f "$tmp" + __copytime_error "failed to replace '$dst'" + return 1 + end + set -l ctime (string replace 'T' ' ' -- "$date" | string replace -r '\.\d+Z?$' '') + echo "$vrot_c_dim container created: $ctime$vrot_c_reset" +end + +function __copytime_setdate + set -l file $argv[1] + set -l date $argv[2] + + if not test -e "$file" + __copytime_error "no such file: '$file'" + return 1 + end + if not __copytime_media "$file" + __copytime_error "'$file' is not a supported media file" + return 1 + end + if not command -q ffmpeg + __copytime_error "ffmpeg is required to set container dates" + return 1 + end + + set -l tmp (string join '' "$file" .ct. (random) (path extension "$file")) + ffmpeg -hide_banner -loglevel error -y -i "$file" -map 0 -map '-0:d' -map '-0:t' \ + -c copy -metadata creation_time="$date" "$tmp" + if test $status -ne 0 + rm -f "$tmp" + __copytime_error "failed to write creation date to '$file'" + return 1 + end + mv -f -- "$tmp" "$file" + if test $status -ne 0 + rm -f "$tmp" + __copytime_error "failed to replace '$file'" + return 1 + end + set -l dsp (string replace 'T' ' ' -- "$date") + echo "$vrot_c_ok ✔ $file$vrot_c_dim ← container creation date $dsp$vrot_c_reset" +end + +function __copytime_media + set -l ext (string lower (path extension "$argv[1]")) + switch "$ext" + case '.mp4' '.mov' '.m4v' '.mkv' '.webm' '.avi' '.ts' '.mts' '.m2ts' '.flv' '.wmv' '.mpg' '.mpeg' '.3gp' '.vob' '.ogv' + return 0 + end + return 1 +end + +function __copytime_colors + set -q vrot_colors_set; and return 0 + set -g vrot_colors_set 1 + if isatty stdout + set -g vrot_c_ok (set_color brgreen) + set -g vrot_c_dim (set_color brblack) + set -g vrot_c_warn (set_color bryellow) + set -g vrot_c_err (set_color brred) + set -g vrot_c_reset (set_color normal) + else + for c in ok dim warn err reset + set -g vrot_c_$c '' + end + end +end + +function __copytime_error + echo "$vrot_c_err""copytime: "$argv"$vrot_c_reset" >&2 +end + +function __copytime_usage + echo 'usage: copytime [ ...]' + echo ' copytime --date