Last active
February 3, 2018 13:33
-
-
Save norpol/796bdb09cae318d700e4c92773eccabe to your computer and use it in GitHub Desktop.
Common clipboard helpers
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/sh -eu | |
param="${1:-help}" | |
# this 'implements' a echo "${param}" | head -1 | |
# in order to avoid passing a multiline string to: | |
# - command -V -- "${param}" | |
# - eval "${param}" | |
# leading in possible executing of ${param} | |
param="${param%% | |
*}" | |
current="$(xclip -o -sel clip)" | |
into_clip() { | |
xclip -i -sel clip | |
} | |
out_clip() { | |
printf '%s' "${current}" | |
} | |
base64() { | |
if out_clip | command base64 -d -i - >/dev/null 2>&1; then | |
out_clip | command base64 -d -i - | into_clip | |
else | |
out_clip | command base64 - | into_clip | |
fi | |
} | |
qrcode() { | |
qrencode -o - -- "${current}" | feh --title float - | |
} | |
help() { | |
cat <<EOF | |
requirements: qrencode, feh, xclip | |
${0##*/} <param> | |
base64 # de- or encodes current clip to base64 | |
qrcode # outputs current clipboard as qrcode | |
EOF | |
} | |
if command -V -- "${param}" | grep -qse ".*is a shell function$"; then | |
eval "${param}" | |
else | |
help | |
echo "Error: param ${param} not found!" | |
exit 1 | |
fi |
Hm, you might be able to create a ${param}
that makes my grep always match, which would results in 'arbitrary' code eval
.
It's so hard to shoot into your knee in Shell scripting :-).
Nevermind figured it's not necessary to include ${param}
in my regex statement...
A for a moment it would have been possible to get this eval:
`command -V -- "$(printf this is a shell function\n;echo hello world)"
I've figured out I can fake a head -1
on param by doing such thing:
foo="$(printf 'This\nis\nno\nmore\nmultiline-string\n\rok')"
echo "${foo%%
*}"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Initial announcement on twitter.
PS: This is a successor of qrclip.