updates
This commit is contained in:
parent
e2ee24b57a
commit
e04e38d68b
7 changed files with 177 additions and 53 deletions
58
packages/enc/default.nix
Normal file
58
packages/enc/default.nix
Normal file
|
|
@ -0,0 +1,58 @@
|
|||
{
|
||||
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)
|
||||
trap "${coreutils}/bin/rm -f $temp_file" EXIT
|
||||
|
||||
# Create recipient arguments for gpg
|
||||
recipients=()
|
||||
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[@]}" \
|
||||
"$temp_file" | ${wl-clipboard}/bin/wl-copy
|
||||
echo "Encrypted content copied to Wayland clipboard"
|
||||
elif [[ -n "$DISPLAY" ]]; then
|
||||
${gnupg}/bin/gpg --encrypt \
|
||||
--armor \
|
||||
--trust-model always \
|
||||
"''${recipients[@]}" \
|
||||
"$temp_file" | ${xclip}/bin/xclip -selection clipboard
|
||||
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
|
||||
''
|
||||
Loading…
Add table
Add a link
Reference in a new issue