diff options
author | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-11-12 12:45:51 +0100 |
---|---|---|
committer | Raymaekers Luca <raymaekers.luca@gmail.com> | 2024-11-12 12:45:51 +0100 |
commit | fde23996e410c11ee82491380630f9cb8b02e9f8 (patch) | |
tree | ec0b1b6b2baf6d2c774034770628edc7ebf06061 /bin | |
parent | a1afaeffef5caa2cf9e97b10ed0667a2b2df604e (diff) |
checkpoint
Diffstat (limited to 'bin')
-rwxr-xr-x | bin/guiscripts/dmclip | 41 |
1 files changed, 27 insertions, 14 deletions
diff --git a/bin/guiscripts/dmclip b/bin/guiscripts/dmclip index 71ccd34..dbdb193 100755 --- a/bin/guiscripts/dmclip +++ b/bin/guiscripts/dmclip @@ -1,24 +1,37 @@ #!/bin/sh -tmp="/tmp/dmclip" +# dmclip is a menu script to operate on the clipboard selections it can do following operations +# - image to text +# - save clipboard +# - load saved clipboard, caveat: paste must be a single line +# - text replace +# +# arguments: +# - if '$1' is '-p' then dmclip will use the primary selection +# +# dependencies: +# - 'clipp' +# - 'clipo' for pasting +# - 'tesseract' for image to text +# - 'dmenu' as the menu script -choice="$(printf 'swap\nimage\nload\nsave\nreplace\n' | dmenu -c -g 5 -l 1)" -[ "$choice" ] || exit 1 +tmp="/tmp/dmclip" -clipboard="$(printf 'primary\nclipboard\n' | dmenu -c -g 2 -l 1)" -[ "$clipboard" ] || exit 1 +clipopt="$1" -# For clipo and clipp -if [ "$clipboard" = 'primary' ]; then - clipopt='-p' +# preview string for choosing choice +mime="$(clipo "$clipopt" | file --brief --mime-type -)" +if [ "${mime%%/*}" = "image" ]; then + display_clip="IMAGE" else - clipopt='' + display_clip="$(clipo "$clipopt" | head -c 48)" fi + +choice="$(printf 'image\nload\nsave\nreplace\n' | dmenu -p "$display_clip" -c -g 5 -l 1)" +[ "$choice" ] || exit 1 case "$choice" in - swap) swclip ;; image) - mime="$(clipo "$clipopt" | file --brief --mime-type -)" [ "${mime%%/*}" != "image" ] && exit 1 clipo "$clipopt" | tesseract - stdout | sed '/^$/d' > "$tmp" @@ -30,9 +43,9 @@ case "$choice" in clipp "$clipopt" < "$tmp" ;; load) - choice="$(sort "${tmp}.txt" | uniq | - dmenu -c -g 1 -l 5)" + choice="$(sort "${tmp}.txt" | uniq | dmenu -c -g 1 -l 5)" [ "$choice" ] || exit 1 + printf '%s' "$choice" | clipp "$clipopt" ;; save) clipo "$clipopt" >> "${tmp}.txt" ;; @@ -43,7 +56,7 @@ case "$choice" in replacement="$(dmenu -c -l 0 -p "by:" < /dev/null)" [ "$replacement" ] || exit 1 - clipo "$clipopt" | + clipo "$clipopt" | sed "s/$match/$replacement/g" | clipp "$clipopt" ;; |