diff --git a/README.md b/README.md index bc3db6b..05aa4ba 100644 --- a/README.md +++ b/README.md @@ -5,9 +5,10 @@ Multiple scripts that are useful but don't deserve their own repository. A wrapper for youtube-dl to make easier (and automate) some things. -## copy_image.sh +## clipimg.sh -Use with CopyQ to get an image onto the clipboard and select it for pasting +Uses fzf, rofi, fd (optional), and CopyQ to choose an image, get it onto the +clipboard, and select it for pasting. ## tmux_devour.sh diff --git a/clipimg.sh b/clipimg.sh new file mode 100755 index 0000000..6035f92 --- /dev/null +++ b/clipimg.sh @@ -0,0 +1,84 @@ +#!/bin/bash + +############################################################################## +# Uses fzf or rofi to choose a clipart emoji (or reaction image) from a list, +# then copies it to the clipboard (using CopyQ) and selects it for pasting. +############################################################################## + +############################################################################## +# Init +############################################################################## +EmojiPath="/home/steven/images2/emojis/" +ReactionPath="/home/steven/images2/all_reactions/" +FD_FIND=$(which fdfind) + +############################################################################## +# Show the Help +############################################################################## +display_help(){ + echo "###################################################################" + echo "# copyimage.sh [-h|-c]" + echo "# -h show help " + echo "# -c cli/tui interface only. Default is GUI. " + echo "# -e select emoji. Default is reaction. " + echo "###################################################################" +} + + + #uses copyq to select image and copy it to clipboard for pasting + while [ $# -gt 0 ]; do + option="$1" + case $option in + -h) display_help + exit + shift ;; + -e) Emoji="true" + shift ;; + -c) CliOnly="true" + shift ;; + esac + done + + # If you have a lot of options, you could use a case statement here + if [ "$Emoji" == "true" ];then + SearchPath="$EmojiPath" + else + SearchPath="$ReactionPath" + fi + +############################################################################## +# Select that Image! +# +# add +# --preview 'chafa {}' +# to the fzf string to get the preview window +# +# If fdfind (what "fd" is called on Debian) is installed, it will be used preferentially +# +############################################################################## + + if [ -f "$FD_FIND" ];then + if [ "$CliOnly" == "true" ];then + SelectedImage=$(fdfind -a -e png -e jpg -e gif . "$SearchPath" | fzf --no-hscroll -m --height 50% --border --ansi --no-bold --header "Which Reaction?" | realpath -p ) + else + #use ROFI, not zenity + SelectedImage=$(fdfind -a -e png -e jpg -e gif . "$SearchPath" | rofi -i -dmenu -p "Which Reaction?" -theme DarkBlue | realpath -p) + fi + else + if [ "$CliOnly" == "true" ];then + SelectedImage=$(find -H "$SearchPath" -type f -iname "*.png" -or -iname "*.gif" -or -iname "*.jpg" | fzf --no-hscroll -m --height 50% --border --ansi --no-bold --header "Which Reaction?" | realpath -p ) + else + #use ROFI, not zenity + SelectedImage=$(find -H "$SearchPath" -type f -iname "*.png" -or -iname "*.gif" -or -iname "*.jpg" | rofi -i -dmenu -p "Which Reaction?" -theme DarkBlue | realpath -p) + fi + fi + +############################################################################## +# Slap that sucker on the clipboard and select it +############################################################################## + +if [ -f "$SelectedImage" ];then + mime=$(mimetype "$SelectedImage" | awk -F ': ' '{print $2}') + /usr/bin/copyq write 0 "$mime" - < "$SelectedImage" + /usr/bin/copyq select 0 +fi \ No newline at end of file diff --git a/copy_image.sh b/copy_image.sh deleted file mode 100755 index 052b5e8..0000000 --- a/copy_image.sh +++ /dev/null @@ -1,10 +0,0 @@ -#!/bin/bash - -#uses copyq to select image and copy it to clipboard for pasting - -filename=$(realpath $1) -if [ -f "$filename" ];then - mime=$(mimetype "$filename" | awk -F ': ' '{print $2}') - /usr/bin/copyq write 0 "$mime" - < "$filename" - /usr/bin/copyq select 0 -fi \ No newline at end of file