image-info 964 B

12345678910111213141516171819202122232425262728293031323334353637383940
  1. #!/bin/sh
  2. # Example for $XDG_CONFIG_HOME/sxiv/exec/image-info
  3. # Called by sxiv(1) whenever an image gets loaded.
  4. # The output is displayed in sxiv's status bar.
  5. # Arguments:
  6. # $1: path to image file
  7. # $2: image width
  8. # $3: image height
  9. # $4: image/video
  10. s=" " # field separator
  11. exec 2>/dev/null
  12. video_duration() {
  13. f="$1"
  14. duration=$(ffprobe -v quiet -of default=noprint_wrappers=1:nokey=1 -show_entries format=duration "$f")
  15. h=$(echo "$duration/3600" | bc)
  16. m=$(echo "$duration%3600/60" | bc)
  17. s=$(echo "$duration%60/1" | bc)
  18. if [ "$h" = 0 ]; then
  19. printf '%02d:%02d\n' "$m" "$s"
  20. else
  21. printf '%02d:%02d:%02d\n' "$h" "$m" "$s"
  22. fi
  23. }
  24. path="$1"
  25. filename=$(basename -- "$path")
  26. filesize=$(du -Hh -- "$path" | cut -f 1)
  27. geometry="${2}x${3}"
  28. type=
  29. [ "$4" = video ] && {
  30. dur=$(video_duration "$path")
  31. type="${s}⯈ $dur${s}(play with ctrl-space)"
  32. }
  33. echo "${filename}${s}${filesize}${s}${geometry}${type}"