33 lines
624 B
Plaintext
33 lines
624 B
Plaintext
|
#!/bin/bash
|
||
|
|
||
|
# Copy file contents to clipboard
|
||
|
# Usage: copy <file>
|
||
|
# ... | copy <file_name>
|
||
|
#
|
||
|
# Author: Nathan Woodburn
|
||
|
|
||
|
copy() {
|
||
|
if [ $# -eq 0 ]; then
|
||
|
echo "No arguments specified."
|
||
|
echo "Usage: copy <file>"
|
||
|
return 1
|
||
|
fi
|
||
|
|
||
|
if tty -s; then
|
||
|
file="$1"
|
||
|
if [ ! -e "$file" ]; then
|
||
|
echo "$file: No such file or directory" >&2
|
||
|
return 1
|
||
|
fi
|
||
|
|
||
|
xclip -selection clipboard < "$file"
|
||
|
|
||
|
else
|
||
|
file_name="$1"
|
||
|
xclip -selection clipboard < "$file_name"
|
||
|
fi
|
||
|
}
|
||
|
|
||
|
# Call the copy function with the provided arguments
|
||
|
copy "$@"
|