change igm2clip scripts to good old bash

This commit is contained in:
Q
2020-05-13 11:31:25 +03:00
parent cc4e6b42dc
commit cd2b1df8ed
2 changed files with 40 additions and 43 deletions

View File

@@ -1,33 +1,24 @@
#!/usr/bin/env python #!/bin/bash
import pygtk,gtk,os,sys
pygtk.require('2.0')
from argparse import ArgumentParser
function usage {
echo -e ' Copy clipboard to image
def write_image(f): Usage: clip2img path-to-image
'
}
clipboard = gtk.clipboard_get() while getopts h opt
image = clipboard.wait_for_image() do case "$opt" in
if image==None: h)
sys.stderr.write("No image in clipboard!\n") usage
sys.exit(1) exit
image.save(f, type_str(f)) ;;
esac
done
if [[ -z "$1" ]]; then
usage
exit
fi
def type_str(f): xclip -selection clipboard -o | convert - "$1"
filename, file_extension = os.path.splitext(f.lower())
file_extension=file_extension[1:]
if file_extension=="jpg":
return 'jpeg'
if file_extension=="tif":
return 'tiff'
return file_extension
parser=ArgumentParser(description="Write image from clipboard to image file. Extension jpg/png/tif/ico/bmp.")
parser.add_argument('image', action="store")
opts=parser.parse_args()
if (os.path.exists(opts.image)):
sys.stderr.write("Image already exists!\n")
sys.exit(1)
write_image(opts.image);

View File

@@ -1,20 +1,26 @@
#!/usr/bin/env python #!/bin/bash
import pygtk,gtk,os,sys
pygtk.require('2.0')
from argparse import ArgumentParser
function usage {
echo -e ' Copy image to clipboard
def copy_image(f): Usage: img2clip path-to-image
assert os.path.exists(f), "file does not exist" '
image = gtk.gdk.pixbuf_new_from_file(f) }
clipboard = gtk.clipboard_get() while getopts h opt
clipboard.set_image(image) do case "$opt" in
clipboard.store() h)
usage
exit
;;
esac
done
if [[ -z "$1" ]]; then
usage
exit
fi
parser=ArgumentParser(description="Copy image to clipboard.") mime=$( file -b --mime-type "$1" )
parser.add_argument('image', action="store") xclip -selection primary -t "$mime" -i "$1"
opts=parser.parse_args() xclip -selection clipboard -t "$mime" -i "$1"
copy_image(opts.image);