-
Notifications
You must be signed in to change notification settings - Fork 1
/
copy
30 lines (26 loc) · 767 Bytes
/
copy
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
#!/bin/bash
# Description: This script copies the input passed through a pipe to the clipboard using xclip.
# Dependency: xclip
# Check whether xclip is installed
if ! command -v xclip >/dev/null 2>&1; then
echo "Error: 'xclip' is not installed. Please install it."
exit 1
fi
# Print help message
if [[ "$1" == "-h" || "$1" == "--help" ]]; then
echo "It copies the input passed through a pipe to the clipboard using xclip."
echo "Usage: "
echo " [command] | copy"
echo "Example: "
echo " cat log.txt | copy"
echo " ls | copy"
exit 0
fi
# Check if input is passed through pipe
if ! [[ -t 0 ]]; then
# Copy input to clipboard
xclip -sel clip
echo "Copied!"
else
echo "No value passed through pipe"
fi