Created
May 13, 2024 02:31
-
-
Save Davenchy/e62501f65706f2909f7d527ebcd569f5 to your computer and use it in GitHub Desktop.
Copy/Paste bash scripts using xclip
This file contains hidden or 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
#!/usr/bin/bash | |
# Simple bash script to copy files into clipboard using xclip | |
# Check if xclip is installed | |
if ! command -v xclip &> /dev/null; then | |
echo "Error: xclip is not installed. Please install xclip before running this script." | |
exit 1 | |
fi | |
if [[ -z "$1" ]]; then | |
# validate if file was passed | |
echo "Usage: xcopy <file> [<mime>]" | |
exit 1 | |
fi | |
if [[ -z "$2" ]]; then | |
# if no mimetype passed, determine it using file command | |
mime=$(file -ib "$1" | cut -d';' -f1) | |
# print used mimetype | |
echo "Detected MimeType: $mime" | |
else | |
# use passed mimetype | |
mime=$2 | |
fi | |
# copy file using mimetype | |
xclip -sel clip -target "$mime" -i < "$1" |
This file contains hidden or 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
#!/usr/bin/bash | |
# Simple bash script to paste files from clipboard using xclip | |
# Check if xclip is installed | |
if ! command -v xclip &> /dev/null; then | |
echo "Error: xclip is not installed. Please install xclip before running this script." | |
exit 1 | |
fi | |
if [[ "$#" -lt 2 ]]; then | |
# validate if file was passed | |
echo "Usage: xpaste <out-file> <mime>" | |
exit 1 | |
fi | |
# paste file from clipboad using xclip | |
xclip -sel clip -target "$2" -o > "$1" |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment