fix: Copy pipe usage
This commit is contained in:
parent
98507e35b7
commit
472cad1edb
24
copy
24
copy
@ -1,32 +1,28 @@
|
|||||||
#!/bin/bash
|
#!/bin/bash
|
||||||
|
|
||||||
# Copy file contents to clipboard
|
# Copy file contents or command output to clipboard
|
||||||
# Usage: copy <file>
|
# Usage: copy <file>
|
||||||
# ... | copy <file_name>
|
# ... | copy
|
||||||
#
|
#
|
||||||
# Author: Nathan Woodburn
|
# Author: Nathan Woodburn
|
||||||
|
|
||||||
copy() {
|
copy() {
|
||||||
if [ $# -eq 0 ]; then
|
|
||||||
echo "No arguments specified."
|
|
||||||
echo "Usage: copy <file>"
|
|
||||||
return 1
|
|
||||||
fi
|
|
||||||
|
|
||||||
if tty -s; then
|
if tty -s; then
|
||||||
file="$1"
|
file="$1"
|
||||||
if [ ! -e "$file" ]; then
|
if [ -n "$file" ] && [ ! -e "$file" ]; then
|
||||||
echo "$file: No such file or directory" >&2
|
echo "$file: No such file or directory" >&2
|
||||||
return 1
|
return 1
|
||||||
fi
|
fi
|
||||||
|
|
||||||
xclip -selection clipboard < "$file"
|
xclip -selection clipboard < "$file"
|
||||||
|
|
||||||
else
|
else
|
||||||
file_name="$1"
|
xclip -selection clipboard
|
||||||
xclip -selection clipboard < "$file_name"
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# Call the copy function with the provided arguments
|
# Call the copy function with the provided arguments or from a pipe
|
||||||
copy "$@"
|
if [ -t 0 ]; then
|
||||||
|
copy "$@"
|
||||||
|
else
|
||||||
|
copy
|
||||||
|
fi
|
||||||
|
Loading…
Reference in New Issue
Block a user