Add support for *clip.exe* for Bash on Ubuntu on Windows
Kenny Evitt
kenny.evitt at gmail.com
Wed Apr 11 17:18:13 CEST 2018
Here's a new patch (that replaces the previous one) that fixes quoting in
the `write_to_clipboard` function:
---
src/platform/linux.sh | 29 +++++++++++++++++++++++++++++
1 file changed, 29 insertions(+)
create mode 100644 src/platform/linux.sh
diff --git a/src/platform/linux.sh b/src/platform/linux.sh
new file mode 100644
index 0000000..ea899f2
--- /dev/null
+++ b/src/platform/linux.sh
@@ -0,0 +1,29 @@
+# This file is actually for Bash on Ubuntu on Windows!
+
+clip() {
+ local sleep_argv0="password store sleep on display $DISPLAY"
+ pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
+ local before="$(read_from_clipboard | base64)"
+
+ write_to_clipboard "$(echo -n "$1")"
+ (
+ ( exec -a "$sleep_argv0" sleep "$CLIP_TIME" )
+ local now="$(read_from_clipboard | base64)"
+
+ [[ $now != $(echo "$1" | base64) ]] && before="$now"
+ write_to_clipboard "$(echo "$before" | base64 -d)"
+ ) 2>/dev/null & disown
+ echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
+}
+
+read_from_clipboard() {
+ local
text="$(/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
-Command "Add-Type -AssemblyName System.Windows.Forms;
[System.Windows.Forms.Clipboard]::GetText()")"
+ # Remove trailing carriage return:
+ echo "${text:0:-1}"
+}
+
+write_to_clipboard() {
+ # Escape for PowerShell:
+ local text="${1//\'/\'\'}"
+ /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe -Command
"Add-Type -AssemblyName System.Windows.Forms;
[System.Windows.Forms.Clipboard]::SetText('$text')"
+}
--
2.10.0.windows.1
On Thu, Apr 5, 2018 at 10:47 AM, Kenny Evitt <kenny.evitt at gmail.com> wrote:
> I didn't submit a patch because I don't expect it be to merged upstream
> anytime soon. The 'soft fork' is just a convenient place for me to keep the
> changes where I, and anyone else, can access them.
>
> Here's the patch for the changes (excluding my "soft fork" README changes):
>
> ---
> src/platform/linux.sh | 27 +++++++++++++++++++++++++++
> 1 file changed, 27 insertions(+)
> create mode 100644 src/platform/linux.sh
>
> diff --git a/src/platform/linux.sh b/src/platform/linux.sh
> new file mode 100644
> index 0000000..93c568e
> --- /dev/null
> +++ b/src/platform/linux.sh
> @@ -0,0 +1,27 @@
> +# This file is actually for Bash on Ubuntu on Windows!
> +
> +clip() {
> + local sleep_argv0="password store sleep on display $DISPLAY"
> + pkill -f "^$sleep_argv0" 2>/dev/null && sleep 0.5
> + local before="$(read_from_clipboard | base64)"
> +
> + write_to_clipboard "$(echo -n "$1")"
> + (
> + ( exec -a "$sleep_argv0" sleep "$CLIP_TIME" )
> + local now="$(read_from_clipboard | base64)"
> +
> + [[ $now != $(echo "$1" | base64) ]] && before="$now"
> + write_to_clipboard "$(echo "$before" | base64 -d)"
> + ) 2>/dev/null & disown
> + echo "Copied $2 to clipboard. Will clear in $CLIP_TIME seconds."
> +}
> +
> +read_from_clipboard() {
> + local text="$(/mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
> -Command "Add-Type -AssemblyName System.Windows.Forms;
> [System.Windows.Forms.Clipboard]::GetText()")"
> + # Remove trailing carriage return:
> + echo "${text:0:-1}"
> +}
> +
> +write_to_clipboard() {
> + /mnt/c/Windows/System32/WindowsPowerShell/v1.0/powershell.exe
> -Command "Add-Type -AssemblyName System.Windows.Forms;
> [System.Windows.Forms.Clipboard]::SetText(\"$1\")"
> +}
> --
> 2.10.0.windows.1
>
>
> On Wed, Apr 4, 2018 at 11:14 AM, Jason A. Donenfeld <Jason at zx2c4.com>
> wrote:
>
>> Instead of a "soft fork", why not just submit proper patches to the
>> mailing list to be reviewed and merged upstream? git-send-email is
>> your friend.
>>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.zx2c4.com/pipermail/password-store/attachments/20180411/58bc2ead/attachment.html>
More information about the Password-Store
mailing list