summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authordweller <dweller@cabin.digital>2024-03-18 05:08:39 +0200
committerdweller <dweller@cabin.digital>2024-03-18 05:08:39 +0200
commit48d6a9cdb9e9b0d72104ad2eb5214376ed621c19 (patch)
treee128e9b93745cbb66a3d9e85569d40005ab5f854
parentae4693676e49907442d53d320a7c758557c9770a (diff)
shellcheck and fix handling of URI encoded file pathsHEADmaster
Diffstat (limited to '')
-rw-r--r--README2
-rwxr-xr-xxcopy7
-rwxr-xr-xxpaste12
3 files changed, 9 insertions, 12 deletions
diff --git a/README b/README
index a62c2b9..e6e278b 100644
--- a/README
+++ b/README
@@ -4,7 +4,7 @@ xfileclip
Copy and paste files to and from your shell and X programs!
-Dependencies: POSIX shell (like dash) and xclip
+Dependencies: POSIX shell (like dash), xclip and GNU awk
Install: just copy and paste `xcopy` and `xpaste` scripts
somewhere on your $PATH.
diff --git a/xcopy b/xcopy
index 1795526..1511d51 100755
--- a/xcopy
+++ b/xcopy
@@ -1,18 +1,15 @@
-#!/bin/sh
+#!/bin/sh -e
#
# Copyright (C) 2023 dwlr <dweller@cabin.digital>
#
# BSD 3-Clause License (BSD-3-Clause)
# See LICENSE for details
-set -e
-
{
echo "" # TODO: why does it need a \n before the list?
-
for i in "$@"; do
- echo "file://$(realpath ${i})"
+ echo "file://$(realpath "$i")"
done
} | xclip -sel clipboard -i -r -t text/uri-list
diff --git a/xpaste b/xpaste
index 444206f..77aa842 100755
--- a/xpaste
+++ b/xpaste
@@ -1,17 +1,17 @@
-#!/bin/sh
+#!/bin/sh -e
#
# Copyright (C) 2023 dwlr <dweller@cabin.digital>
#
# BSD 3-Clause License (BSD-3-Clause)
# See LICENSE for details
-set -e
-
-echo "$(xclip -sel clipboard -o -r -t text/uri-list | cut -d':' -f2- | tr -d '\r')" \
+# NOTE: awk part does URI decoding
+xclip -sel clipboard -o -r -t text/uri-list | cut -d':' -f2- | tr -d '\r' \
+| awk -niord '{printf RT?$0chr("0x"substr(RT,2)):$0}' RS=%.. \
| while IFS= read -r path
do
- if [ -e "${path}" ]; then
- cp -v -r "${path}" "$(basename ${path})"
+ if [ -e "$path" ]; then
+ cp -v -r "$path" "$(basename "$path")"
fi
done