summaryrefslogtreecommitdiff
path: root/ar/.config/nsxiv/exec/key-handler
blob: a315b021dd5ae2b704690d69a45faff34738e73c (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
#!/bin/sh

while read -r file; do
  case "$1" in
  "h")
    notify-send "Macro <C-x> key bindings:" "\- b: Set as wallpaper
- c: Copy file
- d: Delete file
- h: Help key bindings
- f: Flip file horizontally
- g: Edit in GIMP
- i: Show file information
- m: Move file
- r: Rotate file 90 degrees
- R: Rotate file -90 degrees
- s: Resize file
- S: Change resolution
- y: Copy file name to clipboard
- Y: Copy file path to clipboard" &
    ;;
  "b") setbg "$file" & ;;
  "c")
    [ -z "$destdir" ] && destdir="$(sed "s/#.*$//;/^\s*$/d" ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | awk '{print $2}' | dmenu -l 20 -i -p "Copy file(s) to where?" | sed "s|~|$HOME|g")"
    [ ! -d "$destdir" ] && notify-send "$destdir is not a directory, cancelled." && exit
    cp "$file" "$destdir" && notify-send -i "$(readlink -f "$file")" "$file copied to $destdir." &
    ;;
  "d")
    [ "$(printf "No\\nYes" | dmenu -i -p "Really delete $file?")" = "Yes" ] && rm "$file" && notify-send "$file deleted."
    ;;
  "f") magick "$file" -flop "$file" ;;
  "g") ifinstalled gimp && setsid -f gimp "$file" ;;
  "i") notify-send "File information" "$(mediainfo "$file" | sed "s/[ ]\+:/:/g;s/: /: <b>/;s/$/<\/b>/" | grep "<b>")" ;;
  "m")
    [ -z "$destdir" ] && destdir="$(sed "s/#.*$//;/^\s*$/d" ${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs | awk '{print $2}' | dmenu -l 20 -i -p "Move file(s) to where?" | sed "s|~|$HOME|g")"
    [ ! -d "$destdir" ] && notify-send "$destdir is not a directory, cancelled." && exit
    mv "$file" "$destdir" && notify-send -i "$(readlink -f "$file")" "$file moved to $destdir." &
    ;;
  "r") magick "$file" -rotate 90 "$file" ;;
  "R") magick "$file" -rotate -90 "$file" ;;
  "s")
    size="$(echo "" | dmenu -i -p "Enter a size to resize $file ($(identify -format "%wx%h" $file)): ")"
    magick "$file" -resize "$size" "$file" && notify-send "$file size has changed to $size."
    ;;
  "S")
    resolution="$(printf low\\nmedium\\nhigh | dmenu -i -p "Choose a resolution: ")"
    case "$resolution" in
    low) magick "$file" -resample 72 "$file" ;;
    medium) magick "$file" -resample 150 "$file" ;;
    high) magick "$file" -resample 300 "$file" ;;
    esac && notify-send "Changed $file resolution to $resolution."
    ;;
  "y")
    printf "%s" "$file" | tr -d '\n' | xclip -selection clipboard &&
      notify-send "$file copied to clipboard" &
    ;;
  "Y")
    readlink -f "$file" | tr -d '\n' | xclip -selection clipboard &&
      notify-send "$(readlink -f "$file") copied to clipboard" &
    ;;
  esac
done