2024-06-16 00:26:14 +01:00
|
|
|
{ pkgs, ... }:
|
|
|
|
{
|
|
|
|
home.packages = with pkgs; [
|
|
|
|
(writeShellScriptBin "clipboard-save" ''
|
|
|
|
# Script to automatically save copied images and text in specified directories
|
|
|
|
while ${clipnotify}/bin/clipnotify
|
|
|
|
do
|
|
|
|
image_location="/tmp/clipboard/images"
|
|
|
|
text_location="/tmp/clipboard/text"
|
|
|
|
[[ -d $image_location ]] || mkdir -p $image_location
|
|
|
|
[[ -d $text_location ]] || mkdir -p $text_location
|
|
|
|
|
|
|
|
case "$(xclip -selection clipboard -t TARGETS -o)" in
|
|
|
|
*image*)
|
|
|
|
echo "$(${xclip}/bin/xclip -selection clipboard -t TARGETS -o)"
|
|
|
|
filename=$(${xclip}/bin/xclip -selection clipboard -t image/png -o | ${openssl}/bin/openssl sha1 | cut -b 49-)
|
2024-08-15 13:32:04 +01:00
|
|
|
file_exists=$(ls $image_location | grep $filename | sed "s/\..*//")
|
2024-06-16 00:26:14 +01:00
|
|
|
[[ $filename != "$file_exists" ]] &&
|
|
|
|
xclip -selection clipboard -t image/png -o > "$image_location/$filename.png" &&
|
|
|
|
notify-send -t 5000 "Image Copied" "$image_location/$filename.png"
|
|
|
|
;;
|
|
|
|
*UTF8_STRING*)
|
|
|
|
echo "$(${xclip}/bin/xclip -selection clipboard -t TARGETS -o)"
|
|
|
|
filename=$(${xclip}/bin/xclip -selection clipboard -t UTF8_STRING -o | ${openssl}/bin/openssl sha1 | cut -b 49-)
|
2024-08-15 13:32:04 +01:00
|
|
|
file_exists=$(ls "$text_location" | grep "$filename" | sed "s/\..*//")
|
2024-06-16 00:26:14 +01:00
|
|
|
echo "$filename" "$file_exists"
|
|
|
|
[[ "$filename" != "$file_exists" ]] &&
|
|
|
|
xclip -selection clipboard -t UTF8_STRING -o > "$text_location/$filename"
|
|
|
|
echo "$text_location/$filename"
|
|
|
|
touch "$text_location/$filename"
|
|
|
|
;;
|
|
|
|
esac
|
|
|
|
done
|
|
|
|
|
|
|
|
'')
|
|
|
|
];
|
|
|
|
}
|