nsxiv75a6656
Refactored rotation in key-handler
+12 −11
1 file changed
- M exec/key-handler +12 −11
| @@ -11,13 +11,17 @@ | |||
| 11 | 11 | # where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X | |
| 12 | 12 | # keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix. | |
| 13 | 13 | ||
| 14 | + | readonly KEY="$1"; shift | |
| 14 | 15 | readonly TAGFILE="$HOME/.config/sxiv/tags" | |
| 15 | 16 | ||
| 16 | 17 | rotate() { | |
| 17 | − | case "$(file -b -i "$2")" in | |
| 18 | − | image/jpeg*) jpegtran -rotate "$1" -copy all -outfile "$2" "$2" ;; | |
| 19 | − | *) mogrify -rotate "$1" "$2" ;; | |
| 20 | − | esac | |
| 18 | + | degree="$1"; shift | |
| 19 | + | for file in "$@"; do | |
| 20 | + | case "$(file -b -i "$file")" in | |
| 21 | + | image/jpeg*) jpegtran -rotate "$degree" -copy all -outfile "$file" "$file" ;; | |
| 22 | + | *) mogrify -rotate "$degree" "$file" ;; | |
| 23 | + | esac | |
| 24 | + | done | |
| 21 | 25 | } | |
| 22 | 26 | ||
| 23 | 27 | tag_add() { | |
| @@ -35,16 +39,13 @@ tag_del() { | |||
| 35 | 39 | iptckwed -r "$tags" "$@" | |
| 36 | 40 | } | |
| 37 | 41 | ||
| 38 | − | key="$1" | |
| 39 | − | shift | |
| 40 | − | ||
| 41 | − | case "$key" in | |
| 42 | + | case "$KEY" in | |
| 42 | 43 | "C-c") echo -n "$@" | xsel -i ;; | |
| 43 | 44 | "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 ;; | |
| 44 | 45 | "C-g") gimp "$@" & ;; | |
| 45 | − | "C-comma") for file in "$@"; do rotate 270 "$file"; done ;; | |
| 46 | − | "C-period") for file in "$@"; do rotate 90 "$file"; done ;; | |
| 47 | − | "C-slash") for file in "$@"; do rotate 180 "$file"; done ;; | |
| 46 | + | "C-comma") rotate 270 "$@" ;; | |
| 47 | + | "C-period") rotate 90 "$@" ;; | |
| 48 | + | "C-slash") rotate 180 "$@" ;; | |
| 48 | 49 | "C-t") tag_add "$@" ;; | |
| 49 | 50 | "M-T") tag_del "$@" ;; | |
| 50 | 51 | esac | |