Update scripts in ~/.local/bin/

This commit is contained in:
2026-03-09 09:27:31 +01:00
parent eacecdd006
commit 98053491b3
2 changed files with 306 additions and 63 deletions

View File

@@ -250,6 +250,17 @@ bgloc="${XDG_CACHE_HOME:-$HOME/.cache/}/bg"
xwallpaper --zoom "$bgloc"
#+end_src
* =get-otp=
#+begin_src bash :tangle ~/.local/bin/get-otp
passname=$(ls ~/.local/share/pass/totp-* | xargs -n 1 basename | sed -e 's/\..*$//' | rofi -p "TOPT" -dmenu)
if [ -n "$passname" ]; then
otpnumber=`pass otp $passname`
echo $otpnumber | xsel -i
dunstify 'OTP' "$otpnumber" &
fi
#+end_src
* =insert-unicode= - Insert Unicode Icon
:PROPERTIES:
:CUSTOM_ID: insert-unicode
@@ -313,7 +324,7 @@ case "$1" in
,*mkv|*webm|*mp4|*youtube.com/watch*|*youtube.com/playlist*|*youtu.be*|*gif)
setsid mpv -quiet "$1" >/dev/null 2>&1 & ;;
,*png|*jpg|*jpe|*jpeg)
curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && sxiv -a "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && nsxiv -a "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
,*pdf|*cbz|*cbr)
curl -sL "$1" > "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" && zathura "/tmp/$(echo "$1" | sed "s/.*\///;s/%20/ /g")" >/dev/null 2>&1 & ;;
,*svg)
@@ -391,7 +402,7 @@ done
echo "Killed mopidy."
echo "Restarting mopidy..."
mopidy --config ~/.config/mopidy/mopidy.conf >/dev/null 2>&1 &
~/.local/soft/mopidy-jellyfin/env/bin/mopidy -v >/tmp/mopidy.log 2>&1 &
echo "Done"
#+end_src
@@ -427,11 +438,11 @@ else
address="wttr.in/"
fi
if type sxiv > /dev/null 2>&1; then
if type nsxiv > /dev/null 2>&1; then
address+=".png"
wget -qO- "$address" > /tmp/weather.png && \
sxiv -b /tmp/weather.png
nsxiv -b /tmp/weather.png
elif type feh > /dev/null 2>&1; then
address+=".png"
@@ -463,6 +474,15 @@ filename_without_extension=${filename_with_extension%.*}
List of useful programs:
- =inkscape=
*** SVG to JPG
#+begin_src bash
svg2jpg_function() { \
if command -v inkscape &> /dev/null; then
inkscape --export-type="png" --export-filename=- --export-dpi=500 --export-area-drawing "$filename_with_extension" | convert - "$filename_without_extension.jpg"
fi
}
#+end_src
*** SVG to PNG
#+begin_src bash
svg2png_function() { \
@@ -481,23 +501,38 @@ svg2pdf_function() { \
}
#+end_src
*** SVG to EMF
#+begin_src bash
svg2emf_function() { \
if command -v inkscape &> /dev/null; then
inkscape --export-type="emf" --export-filename="$filename_without_extension.emf" "$filename_with_extension"
fi
}
#+end_src
*** Main function
#+begin_src bash
# Convert SVG Files
svg2() { \
out_ext=$(echo -e "pdf\npng" | rofi -i -dmenu -p "Convert SVG to")
out_ext=$(echo -e "pdf\njpg\npng\nemf" | rofi -i -dmenu -p "Convert SVG to")
if [ -z "$out_ext" ]; then
exit;
fi
case "$out_ext" in
"jpg")
svg2jpg_function
;;
"png")
svg2png_function
;;
"pdf")
svg2pdf_function
;;
"emf")
svg2emf_function
;;
esac
}
#+end_src
@@ -522,7 +557,7 @@ pdf2png_function() { \
elif command -v convert &> /dev/null; then
convert -density 100 -trim -antialias "$filename_with_extension" -quality 100 "$filename_without_extension.png"
elif command -v inkscape &> /dev/null; then
inkscape --export-type="$out_ext" --export-dpi=200 --export-area-drawing "$filename_with_extension"
inkscape --export-type="$out_ext" --export-dpi=500 --export-area-drawing "$filename_with_extension"
fi
}
#+end_src
@@ -540,6 +575,15 @@ pdf2svg_function() { \
}
#+end_src
*** PDF to EMF
#+begin_src bash
pdf2emf_function() { \
if command -v inkscape &> /dev/null; then
inkscape --export-type="emf" --export-filename="$filename_without_extension.emf" "$filename_with_extension"
fi
}
#+end_src
*** PDF Reduce Size
#+begin_src bash
pdfreduce_function() { \
@@ -615,11 +659,21 @@ pdf_remove_annotations_function() { \
}
#+end_src
*** Rasterize
#+begin_src bash
pdf_rasterize_function() { \
if command -v convert &> /dev/null; then
convert -density 600 +antialias "$filename_with_extension" /tmp/pdf_rasterized.pdf && \
gs -sDEVICE=pdfwrite -dCompatibilityLevel=1.4 -dPDFSETTINGS=/printer -dNOPAUSE -dQUIET -dBATCH -sOutputFile="$filename_without_extension.red.pdf" /tmp/pdf_rasterized.pdf
fi
}
#+end_src
*** Main function
#+begin_src bash
# Convert PDF Files
pdf2() { \
out_ext=$(echo -e "svg\npng\nreduce size\ntrim\nextract pages\ndelete first page\nremove annotations" | rofi -i -dmenu -p "Convert PDF to")
out_ext=$(echo -e "svg\npng\nemf\nreduce size\ntrim\nextract pages\ndelete first page\nrasterize\nremove annotations" | rofi -i -dmenu -p "Convert PDF to")
if [ -z "$out_ext" ]; then
exit;
@@ -629,6 +683,9 @@ pdf2() { \
"svg")
pdf2svg_function
;;
"emf")
pdf2emf_function
;;
"png")
pdf2png_function
;;
@@ -644,6 +701,9 @@ pdf2() { \
"delete first page")
pdf_delete_first_page_function
;;
"rasterize")
pdf_rasterize_function
;;
"remove annotations")
pdf_remove_annotations_function
;;
@@ -797,14 +857,17 @@ pngtrim_function() { \
#+begin_src bash
pngresize_function() { \
if command -v convert &> /dev/null; then
size_type=$(echo -e "width\nheight" | rofi -i -dmenu -p "Maximum:")
size_px=$(rofi -dmenu -p "Number of px:")
if [ "$size_type" = "width" ]; then
convert -resize "$size_px"x "$filename_with_extension" "$filename_with_extension"
elif [ "$size_type" = "height" ]; then
convert -resize x"$size_px" "$filename_with_extension" "$filename_with_extension"
fi
size_type=$(echo -e "width\nheight" | rofi -i -dmenu -p "Maximum:")
size_px=$(rofi -dmenu -p "Number of px:")
# Check if size_px is indeed a number
re='^[0-9]+$'
if [[ $size_px =~ $re ]] ; then
if [ "$size_type" = "width" ]; then
convert -resize "$size_px"x "$filename_with_extension" "$filename_with_extension"
elif [ "$size_type" = "height" ]; then
convert -resize x"$size_px" "$filename_with_extension" "$filename_with_extension"
fi
fi
fi
}
#+end_src
@@ -871,14 +934,17 @@ jpg2png_function() { \
#+begin_src bash
jpgresize_function() { \
if command -v convert &> /dev/null; then
size_type=$(echo -e "width\nheight" | rofi -i -dmenu -p "Maximum:")
size_px=$(rofi -dmenu -p "Number of px:")
if [ "$size_type" = "width" ]; then
convert -resize "$size_px"x "$filename_with_extension" "$filename_with_extension"
elif [ "$size_type" = "height" ]; then
convert -resize x"$size_px" "$filename_with_extension" "$filename_with_extension"
fi
size_type=$(echo -e "width\nheight" | rofi -i -dmenu -p "Maximum:")
size_px=$(rofi -dmenu -p "Number of px:")
# Check if size_px is indeed a number
re='^[0-9]+$'
if [[ $size_px =~ $re ]] ; then
if [ "$size_type" = "width" ]; then
convert -resize "$size_px"x "$filename_with_extension" "$filename_with_extension"
elif [ "$size_type" = "height" ]; then
convert -resize x"$size_px" "$filename_with_extension" "$filename_with_extension"
fi
fi
fi
}
#+end_src
@@ -893,6 +959,15 @@ jpgrotate_function() { \
}
#+end_src
*** JPG Horizontal Flip
#+begin_src bash
jpgfliphor_function() { \
if command -v convert &> /dev/null; then
convert -flop "$filename_with_extension" "$filename_with_extension"
fi
}
#+end_src
*** JPG Trim
#+begin_src bash
jpgtrim_function() { \
@@ -915,7 +990,7 @@ jpgcrop_function() { \
#+begin_src bash
# Convert JPG Files
jpg2() { \
out_ext=$(echo -e "pdf\npng\nresize\ncrop\ntrim\nrotate" | rofi -i -dmenu -p "Convert JPG to")
out_ext=$(echo -e "pdf\npng\nresize\ncrop\ntrim\nrotate\nflip" | rofi -i -dmenu -p "Convert JPG to")
if [ -z "$out_ext" ]; then
exit;
@@ -940,6 +1015,65 @@ jpg2() { \
"rotate")
jpgrotate_function
;;
"flip")
jpgfliphor_function
;;
esac
}
#+end_src
** BMP files
*** BMP to PNG
#+begin_src bash
bmp2png_function() { \
if command -v convert &> /dev/null; then
convert "$filename_with_extension" "$filename_without_extension.png"
fi
}
#+end_src
*** Main function
#+begin_src bash
# Convert BMP Files
bmp2() { \
out_ext=$(echo -e "png" | rofi -i -dmenu -p "Convert BMP to")
if [ -z "$out_ext" ]; then
exit;
fi
case "$out_ext" in
"png")
bmp2png_function
;;
esac
}
#+end_src
** WEBP files
*** WEBP to PNG
#+begin_src bash
webp2png_function() { \
if command -v convert &> /dev/null; then
convert "$filename_with_extension" "$filename_without_extension.png"
fi
}
#+end_src
*** Main function
#+begin_src bash
# Convert WEBP Files
webp2() { \
out_ext=$(echo -e "png" | rofi -i -dmenu -p "Convert WEBP to")
if [ -z "$out_ext" ]; then
exit;
fi
case "$out_ext" in
"png")
webp2png_function
;;
esac
}
#+end_src
@@ -973,6 +1107,15 @@ xopp2() { \
#+end_src
** MP4 files
*** MP4 to AVI (powerpoint)
#+begin_src bash
mp42avi_powerpoint_function() { \
if command -v ffmpeg &> /dev/null; then
ffmpeg -v warning -i "$filename_with_extension" -q:a 2 -q:v 4 -vcodec wmv2 -an -y "$filename_without_extension.avi"
fi
}
#+end_src
*** MP4 to GIF
#+begin_src bash
mp42gif_function() { \
@@ -1028,7 +1171,7 @@ mp4nosound_function() { \
#+begin_src bash
# Convert MP4 Files
mp42() { \
out_ext=$(echo -e "gif\ngif loop\nremove sound" | rofi -i -dmenu -p "Convert MP4 to")
out_ext=$(echo -e "gif\ngif loop\nremove sound\navi" | rofi -i -dmenu -p "Convert MP4 to")
if [ -z "$out_ext" ]; then
exit;
@@ -1041,6 +1184,9 @@ mp42() { \
"gif loop")
mp42gifloop_function
;;
"avi")
mp42avi_powerpoint_function
;;
"remove sound")
mp4nosound_function
;;
@@ -1049,6 +1195,22 @@ mp42() { \
#+end_src
** AVI files
*** Crop AVI
#+begin_src bash
avi2crop_function() { \
if command -v ffmpeg &> /dev/null; then
cropvalue=$(ffmpeg -i "$filename_with_extension" -frames:v 3 -vf "negate,cropdetect=limit=0:round=2" -f null - 2>&1 | awk '/crop/ { print $NF }' | tail -1)
# Step 2: Apply crop
if [ -n "$cropvalue" ]; then
ffmpeg -i "$filename_with_extension" -q:a 2 -q:v 4 -vcodec wmv2 -an -y -vf "$cropvalue" "${filename_without_extension}_crop.avi"
else
echo "Could not detect crop value."
fi
fi
}
#+end_src
*** AVI to MP4
#+begin_src bash
avi2mp4_function() { \
@@ -1100,7 +1262,7 @@ avi2gifloop_function() { \
#+begin_src bash
# Convert AVI Files
avi2() { \
out_ext=$(echo -e "gif\ngif loop\nmp4" | rofi -i -dmenu -p "Convert AVI to")
out_ext=$(echo -e "gif\ngif loop\nmp4\ncrop" | rofi -i -dmenu -p "Convert AVI to")
if [ -z "$out_ext" ]; then
exit;
@@ -1116,6 +1278,9 @@ avi2() { \
"mp4")
avi2mp4_function
;;
"crop")
avi2crop_function
;;
esac
}
#+end_src
@@ -1153,6 +1318,12 @@ case "$in_ext" in
"docx")
docx2
;;
"webp")
webp2
;;
"bmp")
bmp2
;;
"pptx")
docx2
;;