-
-
Save oshliaer/52ab554008874347758e2d595a313019 to your computer and use it in GitHub Desktop.
Paste contents of Xorg clipboard to a file from the command line
This file contains 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
#!/bin/bash | |
# Paste contents of Xorg clipboard to a file from the command line | |
filename=$@ | |
pasteinfo="clipboard contents" | |
# Display usage if no parameters given | |
if [[ -z "$@" ]]; then | |
echo " ${0##*/} <filename> - paste contents of context-menu clipboard to file" | |
exit | |
fi | |
# If filename matches a directory name exit | |
if [ -d "$filename" ]; then | |
echo " Directory already has the name ""$filename""" && exit | |
fi | |
# Check if file exists, prompt to append or override, else create new | |
if [[ -f "$filename" ]]; then | |
echo " File \""${filename##*/}"\" already exists - (e)xit, (a)ppend, (o)verwrite: " | |
read edit | |
case "$edit" in | |
[aA] ) xclip -out -selection clipboard >> "$filename" | |
echo " File \""$filename"\" appended with clipboard contents" | |
;; | |
[oO] ) xclip -out -selection clipboard > "$filename" | |
echo " File \""$filename"\" overwrote with clipboard contents" | |
;; | |
* ) exit | |
esac; | |
else | |
xclip -out -selection clipboard >> "$filename" | |
echo " File \""$filename"\" created with clipboard contents" | |
fi |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment