key-handler 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  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. Passed via stdin are the
  5. # images to act upon, one path per line: all marked images, if in thumbnail
  6. # mode and at least one image has been marked, otherwise the current image.
  7. # sxiv(1) blocks until this script terminates. It then checks which images
  8. # have been modified and reloads them.
  9. # The key combo argument has the following form: "[C-][M-][S-]KEY",
  10. # where C/M/S indicate Ctrl/Meta(Alt)/Shift modifier states and KEY is the X
  11. # keysym as listed in /usr/include/X11/keysymdef.h without the "XK_" prefix.
  12. ALPHA_COLOUR="#352f2f"
  13. readonly KEY="$1";
  14. FNAME="$(xargs -0 echo)"
  15. BNAME="$(basename "$FNAME")"
  16. SDIR="/mnt/toshstor/i/s"
  17. PBDIR="/mnt/toshstor/i/pb"
  18. NTFR=/usr/local/bin/notify-send
  19. EXT=$(file -i "$FNAME" | grep -o "image/.*;" | sed -e 's/image\///' -e 's/;//')
  20. WALLSET_FILL="feh --bg-fill"
  21. WALLSET_TILE="hsetroot -solid $ALPHA_COLOUR -tile"
  22. copyto()
  23. {
  24. DNAME="$1"
  25. if [ -e $DNAME/"$BNAME" ]
  26. then
  27. cp -T -- "$FNAME" $DNAME/$(date "+%s")_"$BNAME".$EXT
  28. $NTFR "cp picture dublicate: $DNAME done!" &
  29. else
  30. cp -- "$FNAME" $DNAME
  31. $NTFR "cp picture: $DNAME/$BNAME done!" &
  32. fi
  33. }
  34. moveto()
  35. {
  36. DNAME="$1"
  37. if [ -e $DNAME/"$BNAME" ]
  38. then
  39. mv -T -- "$FNAME" $DNAME/$(date "+%s")_"$BNAME".$EXT
  40. $NTFR "mv picture dublicate: $DNAME done!" &
  41. else
  42. mv -- "$FNAME" $DNAME
  43. $NTFR "mv picture: $DNAME/$BNAME done!" &
  44. fi
  45. }
  46. deletefile()
  47. {
  48. rm "$FNAME"
  49. $NTFR "removing: $FNAME" &
  50. }
  51. wallpf()
  52. {
  53. WALLPLACE="$HOME/.config/wallpaper"
  54. cp -f -T "$FNAME" $WALLPLACE
  55. $WALLSET_FILL $WALLPLACE
  56. sed -i.back -e 's/solid \\#/solid #/i' -e "s/$WALLSET_TILE/$WALLSET_FILL/i" ~/bin/pathadd/wxrandr.sh
  57. $NTFR "wallpaper (fill) set!" &
  58. }
  59. wallpt()
  60. {
  61. WALLPLACE="$HOME/.config/wallpaper"
  62. cp -f -T "$FNAME" $WALLPLACE
  63. $WALLSET_TILE $WALLPLACE
  64. sed -i.back -e "s/$WALLSET_FILL/$WALLSET_TILE/i" -e 's/solid #/solid \\#/i' ~/bin/pathadd/wxrandr.sh
  65. $NTFR "wallpaper (tiles) set!ss" &
  66. }
  67. help()
  68. {
  69. sxiv -b ~/.config/sxiv/cheatsheet.png
  70. }
  71. echo "$KEY"
  72. case "$KEY" in
  73. "F1") help ;;
  74. "F4") copyto $HOME ;;
  75. "F5") copyto $PBDIR ;;
  76. "KP_Enter") copyto $PBDIR ;;
  77. "F6") copyto $PBDIR/dolor ;;
  78. "KP_Add") copyto $PBDIR/dolor ;;
  79. "F7") copyto $PBDIR/consectetur ;;
  80. "KP_Subtract") copyto $PBDIR/consectetur ;;
  81. "F8") copyto $HOME/tmp ;;
  82. "1") moveto $SDIR/msc ;;
  83. "KP_1") moveto $SDIR/msc ;;
  84. "4") moveto $SDIR/cat ;;
  85. "KP_4") moveto $SDIR/cat ;;
  86. "5") moveto $SDIR/inf ;;
  87. "KP_5") moveto $SDIR/inf ;;
  88. "8") moveto $SDIR/sws ;;
  89. "KP_8") moveto $SDIR/sws ;;
  90. "9") moveto $SDIR/wh4 ;;
  91. "KP_9") moveto $SDIR/wh4 ;;
  92. "0") moveto $SDIR/trb ;;
  93. "c") moveto $SDIR/wll ;;
  94. "Z") wallpf ;;
  95. "X") wallpt ;;
  96. "KP_0") deletefile ;;
  97. "Delete") deletefile ;;
  98. esac