dots

my dotfiles
git clone https://git.awy.one/dots
Log | Files | Refs | Submodules | README | LICENSE

key-handler (1988B) - View raw


 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
#!/bin/sh
file=$1
[ -z "$selection" ] && selection=$(printf "w - Set as wallpaper\nc - Copy to dir\nm - Move to dir\nr - Rotate 90°\nR - Rotate -90°\nf - Flip horizontal\ny - Copy filename to clipboard\nY - Copy full path to clipboard\nd - Delete\ng - Open in GIMP\ni - Show media info" |
  mew -i -l 12 -p "Choose action for selected files:")
action=$(printf "%s" "$selection" | cut -d'-' -f1 | tr -d ' ')
case "$action" in
"w") setbg "$file" & ;;
"c")
  [ -z "$destdir" ] && destdir="$(
    sed 's/#.*$//;/^[[:space:]]*$/d' \
      "${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" |
      envsubst |
      mew -c -l 20 -i -p "Copy file(s) to where?" |
      awk '{ $1=""; sub(/^ +/, ""); print }'
  )"
  [ ! -d "$destdir" ] && notify-send "$destdir is not a directory, cancelled." && exit
  cp "$file" "$destdir" && notify-send "$file copied to $destdir." &
  ;;
"m")
  [ -z "$destdir" ] && destdir="$(
    sed 's/#.*$//;/^[[:space:]]*$/d' \
      "${XDG_CONFIG_HOME:-$HOME/.config}/shell/bm-dirs" |
      envsubst |
      mew -c -l 20 -i -p "Copy file(s) to where?" |
      awk '{ $1=""; sub(/^ +/, ""); print }'
  )"
  [ ! -d "$destdir" ] && notify-send "$destdir is not a directory, cancelled." && exit
  mv "$file" "$destdir" && notify-send "$file moved to $destdir." &
  ;;
"r")
  magick "$file" -rotate 90 "$file"
  ;;
"R")
  magick "$file" -rotate -90 "$file"
  ;;
"f")
  magick "$file" -flop "$file"
  ;;
"y")
  printf "%s" "$file" | tr -d '\n' | wl-copy &&
    notify-send "$file copied to clipboard" &
  ;;
"Y")
  readlink -f "$file" | tr -d '\n' | wl-copy &&
    notify-send "$(readlink -f "$file") copied to clipboard" &
  ;;
"d")
  [ "$(printf "No\\nYes" | mew -i -p "Really delete $file?")" = "Yes" ] && rm "$file" && notify-send "$file deleted."
  ;;
"g") ifinstalled gimp && setsid -f gimp "$file" ;;
"i") notify-send "File information" "$(mediainfo "$file" | sed "s/[ ]\+:/:/g;s/: /: <b>/;s/$/<\/b>/" | rg "<b>")" ;;
*) notify-send "No keybind for that key" ;;
esac