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