2024-11-06 13:40:30 -05:00
|
|
|
{
|
|
|
|
|
writeShellScriptBin,
|
|
|
|
|
gnupg,
|
|
|
|
|
neovim,
|
|
|
|
|
coreutils,
|
|
|
|
|
wl-clipboard,
|
|
|
|
|
xclip,
|
|
|
|
|
}:
|
|
|
|
|
writeShellScriptBin "enc" ''
|
|
|
|
|
#!${coreutils}/bin/env zsh
|
|
|
|
|
|
|
|
|
|
# Check if recipients were provided
|
|
|
|
|
if [[ $# -eq 0 ]]; then
|
|
|
|
|
echo "Usage: $0 recipient1@example.com [recipient2@example.com ...]"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
|
|
|
|
|
# Create a temporary file
|
|
|
|
|
temp_file=$(${coreutils}/bin/mktemp)
|
2024-11-13 20:35:13 -05:00
|
|
|
trap "${coreutils}/bin/rm -f $temp_file $temp_file.asc" EXIT
|
2024-11-06 13:40:30 -05:00
|
|
|
|
|
|
|
|
# Create recipient arguments for gpg
|
|
|
|
|
recipients=()
|
2024-11-06 13:53:16 -05:00
|
|
|
recipients+=("-r" "0x5F873416BCF59F35")
|
2024-11-06 13:40:30 -05:00
|
|
|
for recipient in "$@"; do
|
|
|
|
|
recipients+=("-r" "$recipient")
|
|
|
|
|
done
|
|
|
|
|
|
|
|
|
|
# Open neovim with the temp file
|
|
|
|
|
${neovim}/bin/nvim \
|
|
|
|
|
-c "set noswapfile" \
|
|
|
|
|
-c "set filetype=" \
|
|
|
|
|
"$temp_file"
|
|
|
|
|
|
|
|
|
|
# Check if the temp file has content after nvim closes
|
|
|
|
|
if [[ -s "$temp_file" ]]; then
|
|
|
|
|
# Encrypt the content with gpg and copy to clipboard
|
|
|
|
|
if [[ -n "$WAYLAND_DISPLAY" ]]; then
|
|
|
|
|
${gnupg}/bin/gpg --encrypt \
|
|
|
|
|
--armor \
|
|
|
|
|
--trust-model always \
|
|
|
|
|
"''${recipients[@]}" \
|
2024-11-06 13:53:16 -05:00
|
|
|
"$temp_file"
|
|
|
|
|
|
|
|
|
|
cat "$temp_file".asc | ${wl-clipboard}/bin/wl-copy --type text/plain
|
2024-11-06 13:40:30 -05:00
|
|
|
echo "Encrypted content copied to Wayland clipboard"
|
|
|
|
|
elif [[ -n "$DISPLAY" ]]; then
|
|
|
|
|
${gnupg}/bin/gpg --encrypt \
|
|
|
|
|
--armor \
|
|
|
|
|
--trust-model always \
|
|
|
|
|
"''${recipients[@]}" \
|
2024-11-06 13:53:16 -05:00
|
|
|
"$temp_file"
|
|
|
|
|
cat "$temp_file.asc" | ${xclip}/bin/xclip -selection clipboard
|
2024-11-06 13:40:30 -05:00
|
|
|
echo "Encrypted content copied to X11 clipboard"
|
|
|
|
|
else
|
|
|
|
|
echo "No display detected, cannot copy to clipboard"
|
|
|
|
|
exit 1
|
|
|
|
|
fi
|
|
|
|
|
else
|
|
|
|
|
echo "No content was saved, exiting."
|
|
|
|
|
fi
|
|
|
|
|
''
|