A Simple X Image Viewer
Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

key-handler 1.7 KiB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #!/bin/sh
  2. # Example for $XDG_CONFIG_HOME/sxiv/exec/key-handler
  3. # Called by sxiv(1) after the external prefix key (C-x by default) is pressed.
  4. # The next key combo is passed as its first argument, followed by the paths of
  5. # all marked images or the path of the current image, if no image is marked.
  6. # sxiv(1) blocks until this script terminates. It then checks which images
  7. # have been modified and reloads them.
  8. # The key combo argument has the following form: "[C-][M-][S-]KEY",
  9. # where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X
  10. # keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix.
  11. readonly TAGFILE="$HOME/.config/sxiv/tags"
  12. rotate() {
  13. case "$(file -b -i "$2")" in
  14. image/jpeg*) jpegtran -rotate "$1" -copy all -outfile "$2" "$2" ;;
  15. *) mogrify -rotate "$1" "$2" ;;
  16. esac
  17. }
  18. tag_add() {
  19. >>"$TAGFILE"
  20. tags=$(dmenu <"$TAGFILE" | tr '\n' ',')
  21. [ -z "$tags" ] && return
  22. iptckwed -a "$tags" "$@"
  23. echo -n "$tags" | tr ',' '\n' | sort - "$TAGFILE" | uniq >"$TAGFILE.new"
  24. mv -f "$TAGFILE"{.new,}
  25. }
  26. tag_del() {
  27. tags=$(iptckwed -ql "$@" | cut -f 2 | tr ',' '\n' | sort | uniq | dmenu | tr '\n' ',')
  28. [ -z "$tags" ] && return
  29. iptckwed -r "$tags" "$@"
  30. }
  31. key="$1"
  32. shift
  33. case "$key" in
  34. "C-c") echo -n "$@" | xsel -i ;;
  35. "C-e") for file in "$@"; do urxvt -bg "#444" -fg "#eee" -sl 0 -title "$file" -e sh -c "exiv2 pr -q -pa '$file' | less" & done ;;
  36. "C-g") gimp "$@" & ;;
  37. "C-comma") for file in "$@"; do rotate 270 "$file"; done ;;
  38. "C-period") for file in "$@"; do rotate 90 "$file"; done ;;
  39. "C-slash") for file in "$@"; do rotate 180 "$file"; done ;;
  40. "C-t") tag_add "$@" ;;
  41. "M-T") tag_del "$@" ;;
  42. esac