Skip to content
eylles edited this page Sep 7, 2021 · 2 revisions

a more advanced key-handler example, the setbg command isn't a "real" program and instead is a wrapper for setting my background, i reccomend looking on how to set a background image through shell commands for your DE or window manager and perhaps create the corresponding wrapper if you so wish, my setbg wrapper will be linked here when i get around to creating a repo for my dotfiles.

#!/bin/sh

# fix echo
echo () { printf %s\\n "$*" ; }

ifinstalled(){
    # If $1 command is not available, error code and notify.
    command -v "$1" >/dev/null || { notify-send "📦 $1" "must be installed for this function." && exit 1 ;}

}

while read -r file
do
    case "$1" in
        "semicolon") # Information
              ifinstalled mediainfo && notify-send -i "$file" "File information " "$(mediainfo "$file")" ;;
        "w")  setbg "$file" & ;;
        "c")  # copy image to dir
              [ -z "$destdir" ] && destdir="$(awk '!/^#/{sub(/\$HOME/,"~");sub(/.*=/,"");gsub(/"/,"");print $1}' ~/.config/user-dirs.dirs | dmenu -l 20 -i -p "Copy file(s) to where?" | sed "s|~|$HOME|g")"
              [ -z "$destdir" ] && exit
              cp "$file" "$destdir" && notify-send -i "$(readlink -f "$file")" "$file copied to $destdir." &
              ;;
        "m")  # move image to dir
              [ -z "$destdir" ] && destdir="$(awk '!/^#/{sub(/\$HOME/,"~");sub(/.*=/,"");gsub(/"/,"");print $1}' ~/.config/user-dirs.dirs | dmenu -l 20 -i -p "Move file(s) to where?" | sed "s|~|$HOME|g")"
              [ -z "$destdir" ] && exit
              mv "$file" "$destdir" && notify-send -i "$(readlink -f "$file")" "$file moved to $destdir." &
              ;;
        "r")  convert -rotate 90 "$file" "$file" ;;
        "R")  convert -rotate -90 "$file" "$file" ;;
        "f")  convert -flop "$file" "$file" ;;
        "y")  # copy relative path to clipboard
              echo "$file" | xclip -selection clipboard &&
              notify-send -i "$file" "$file copied to clipboard" &
              ;;
        "Y")  # copy full path to clipboard
              readlink -f "$file" | xclip -selection clipboard &&
              notify-send -i "$file" "$(readlink -f "$file") copied to clipboard" &
              ;;
        "d")  [ "$(printf "No\\nYes" | dmenu -i -p "Really delete $file?")" = "Yes" ] && rm "$file" && notify-send "$file deleted." ;;
        "D")  # drag and drop image
              ifinstalled dragon && dragon -x "$file" & ;;
        "p")  # print image
              ifinstalled yad && yad --print --type=image --filename="$file" & ;;
        "g")  ifinstalled gimp && gimp "$file" & ;;
    esac
done
Clone this wiki locally