From 22b844df2cd7d22518f9a4f58d64a70c5a6ea19d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Thu, 7 Nov 2024 14:47:39 +0100 Subject: [PATCH] Misc fixes --- hm/desktop/frobar/frobar/providers.py | 6 +- hm/scripts/jlab | 4 +- hm/scripts/optimize | 136 +++++++++++++------------- 3 files changed, 75 insertions(+), 71 deletions(-) diff --git a/hm/desktop/frobar/frobar/providers.py b/hm/desktop/frobar/frobar/providers.py index c4dca97..7f9345c 100644 --- a/hm/desktop/frobar/frobar/providers.py +++ b/hm/desktop/frobar/frobar/providers.py @@ -874,7 +874,7 @@ class MprisProvider(Section, ThreadedUpdater): "{{ playerName }} {{ status }}", "{{ album }}", "{{ artist }}", - "{{ duration(position) }}|{{ duration(mpris:length) }}" " {{ title }}", + "{{ duration(position) }}/{{ duration(mpris:length) }}" " {{ title }}", ] # nf-fd icons don't work (UTF-16?) @@ -894,6 +894,8 @@ class MprisProvider(Section, ThreadedUpdater): 3: "", } + MAX_SECTION_LENGTH = 40 + def __init__(self, theme: int | None = None): ThreadedUpdater.__init__(self) Section.__init__(self, theme) @@ -926,6 +928,8 @@ class MprisProvider(Section, ThreadedUpdater): if text: if i in self.ICONS: text = f"{self.ICONS[i]} {text}" + if len(text) > self.MAX_SECTION_LENGTH: + text = text[: self.MAX_SECTION_LENGTH - 1] + "…" section.updateText(text) else: section.updateText(None) diff --git a/hm/scripts/jlab b/hm/scripts/jlab index fd1deb5..8357b12 100755 --- a/hm/scripts/jlab +++ b/hm/scripts/jlab @@ -213,13 +213,13 @@ elif sys.argv[1] in ("merge", "mr"): # so jj has a current bookmark. mr = glab_get_mr(sys.argv[3]) jj.run("git", "fetch") - if len(JujutsuCommit.log(f"{mr.source_branch} | {mr.target_branch}")) == 1: + if len(jj.log(f"{mr.source_branch} | {mr.target_branch}")) == 1: title = re.sub(r"^(WIP|Draft): ", "", mr.title) jj.run("new", mr.source_branch) jj.run("describe", "-m", title) jj.run("bookmark", "move", mr.source_branch) else: - jj.run("bookmark", "edit", mr.source_branch) + jj.run("edit", mr.source_branch) elif sys.argv[2] in ( # If no MR number/branch is given, insert the current bookmark, # as the current branch concept doesn't exist in jj diff --git a/hm/scripts/optimize b/hm/scripts/optimize index e28594e..97fb4f3 100755 --- a/hm/scripts/optimize +++ b/hm/scripts/optimize @@ -1,7 +1,9 @@ #!/usr/bin/env nix-shell #! nix-shell -i bash --pure #! nix-shell -p bash coreutils imagemagick libjpeg optipng ffmpeg diffutils +# vim: filetype=sh +set -euo pipefail # Optimizes everything the script can find in a folder, # meaning it will compress files as much as possible, @@ -13,14 +15,13 @@ # TODO Lots of dupplicated code there # TODO Maybe replace part with https://github.com/toy/image_optim? -SCRIPT_DIR=$( cd -- "$( dirname -- "${BASH_SOURCE[0]}" )" &> /dev/null && pwd ) dir=${1:-$PWD} total=$(mktemp) -echo -n 0 > $total +echo -n 0 > "$total" function showtotal { echo "Total saved: $(cat "$total") bytes" - rm $total + rm "$total" exit } @@ -28,11 +29,11 @@ trap showtotal SIGTERM SIGINT SIGFPE function doReplace { # candidate original mv "$c" "$o" - saved=$(($os - $cs)) - perc=$((100 * $saved / $os)) + saved=$((os - cs)) + perc=$((100 * saved / os)) echo "→ $os ⇒ $cs (saved $saved bytes, or ${perc}%)" - newtotal=$(($(cat $total) + $saved)) - echo -n $newtotal > $total + newtotal=$(($(cat "$total") + saved)) + echo -n $newtotal > "$total" } function replace { # candidate original @@ -52,17 +53,17 @@ function replace { # candidate original # Size verifications cs=$(wc -c "$c" | cut -d' ' -f1) os=$(wc -c "$o" | cut -d' ' -f1) - if [ $cs -le 0 ]; then + if [ "$cs" -le 0 ]; then echo "→ Candidate is empty, skipping!" rm "$c" return fi - if [ $cs -eq $os ]; then + if [ "$cs" -eq "$os" ]; then echo "→ Candidate weight the same, skipping." rm "$c" return fi - if [ $cs -gt $os ]; then + if [ "$cs" -gt "$os" ]; then echo "→ Candidate is larger, skipping." rm "$c" return @@ -71,76 +72,75 @@ function replace { # candidate original doReplace "$c" "$o" } -function replaceImg { # candidate original - # With bitmap verification - - c="$1" - o="$2" - - # File verifications - if [ ! -f "$o" ]; then - echo "→ Original is inexistant, skipping!" - return - fi - if [ ! -f "$c" ]; then - echo "→ Candidate is inexistant, skipping!" - return - fi - - # Size verifications - cs=$(wc -c "$c" | cut -d' ' -f1) - os=$(wc -c "$o" | cut -d' ' -f1) - if [ $cs -le 0 ]; then - echo "→ Candidate is empty, skipping!" - rm "$c" - return - fi - if [ $cs -eq $os ]; then - echo "→ Candidate weight the same, skipping." - rm "$c" - return - fi - if [ $cs -gt $os ]; then - echo "→ Candidate is larger, skipping." - rm "$c" - return - fi - - # Bitmap verification - ppmc="$(mktemp --suffix .ppm)" - ppmo="$(mktemp --suffix .ppm)" - convert "$c" "$ppmc" - convert "$o" "$ppmo" - - if cmp --silent "$ppmo" "$ppmc"; then - doReplace "$c" "$o" - else - echo "→ Candidate don't have the same bit map as original, skipping!" - fi - rm -f "$ppmc" "$ppmo" "$c" - -} +# function replaceImg { # candidate original +# # With bitmap verification +# +# c="$1" +# o="$2" +# +# # File verifications +# if [ ! -f "$o" ]; then +# echo "→ Original is inexistant, skipping!" +# return +# fi +# if [ ! -f "$c" ]; then +# echo "→ Candidate is inexistant, skipping!" +# return +# fi +# +# # Size verifications +# cs=$(wc -c "$c" | cut -d' ' -f1) +# os=$(wc -c "$o" | cut -d' ' -f1) +# if [ $cs -le 0 ]; then +# echo "→ Candidate is empty, skipping!" +# rm "$c" +# return +# fi +# if [ $cs -eq $os ]; then +# echo "→ Candidate weight the same, skipping." +# rm "$c" +# return +# fi +# if [ $cs -gt $os ]; then +# echo "→ Candidate is larger, skipping." +# rm "$c" +# return +# fi +# +# # Bitmap verification +# ppmc="$(mktemp --suffix .ppm)" +# ppmo="$(mktemp --suffix .ppm)" +# convert "$c" "$ppmc" +# convert "$o" "$ppmo" +# +# if cmp --silent "$ppmo" "$ppmc"; then +# doReplace "$c" "$o" +# else +# echo "→ Candidate don't have the same bit map as original, skipping!" +# fi +# rm -f "$ppmc" "$ppmo" "$c" +# +# } # JPEG (requires jpegtran) -while read image +while read -r image do if [ -z "$image" ]; then continue; fi - echo Processing $image + echo Processing "$image" prog=$(mktemp --suffix .jpg) jpegtran -copy all -progressive "$image" > "$prog" echo "→ Progressive done" - progs=$(wc -c "$prog" | cut -d' ' -f1) replace "$prog" "$image" done <<< "$(find "$dir/" -type f -iregex ".+.jpe?g$")" # PNG (requires optipng) -while read image +while read -r image do if [ -z "$image" ]; then continue; fi - echo Processing $image + echo Processing "$image" temp=$(mktemp --suffix .png) cp "$image" "$temp" @@ -152,13 +152,13 @@ do done <<< "$(find "$dir/" -type f -iname "*.png")" # FLAC (requires ffmpeg) -while read music +while read -r music do if [ -z "$music" ]; then continue; fi - echo Processing $music + echo "Processing $music" temp=$(mktemp --suffix .flac) - ffmpeg -y -i "$music" -compression_level 8 "$temp" + ffmpeg -nostdin -y -i "$music" -compression_level 8 "$temp" echo "→ Optimize done" replace "$temp" "$music" @@ -186,6 +186,6 @@ done <<< "$(find "$dir/" -type f -iname "*.flac")" # - I might want to keep editor data and/or ids for some of them # So rather use scour explicitely when needed -${SCRIPT_DIR}/cleandev +cleandev showtotal