Skip to content

Commit e9786ef

Browse files
committed
Create script for pasting from clipboard
1 parent 9dda177 commit e9786ef

File tree

1 file changed

+44
-0
lines changed

1 file changed

+44
-0
lines changed

terminal/paste.sh

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
#!/usr/bin/env bash
2+
# Paste to stdout from the clipboard.
3+
4+
set -uo pipefail
5+
6+
stderr() {
7+
echo "${@}" 1>&2
8+
}
9+
10+
fail() {
11+
stderr "${1}"
12+
stderr ""
13+
stderr "Exiting …"
14+
exit "${2:-1}"
15+
}
16+
17+
wsl_paste() {
18+
powershell.exe -c 'Get-Clipboard'
19+
}
20+
21+
if [[ "$(uname -r)" =~ .*microsoft.* ]]; then
22+
declare -r IS_WSL=true
23+
else
24+
declare -r IS_WSL=false
25+
fi
26+
27+
if [[ "${IS_WSL}" == "true" ]]; then
28+
wsl_paste
29+
else
30+
missing_dependencies=false
31+
declare -r dependencies=(
32+
xclip
33+
)
34+
for dep in "${dependencies[@]}"; do
35+
if ! command -v "${dep}" &> /dev/null; then
36+
stderr "❌ ERROR: Missing dependency ${dep}"
37+
missing_dependencies=true
38+
fi
39+
done
40+
if ${missing_dependencies}; then
41+
fail 'Please install the missing dependencies!'
42+
fi
43+
xclip -o -selection clipboard
44+
fi

0 commit comments

Comments
 (0)