Skip to content

Instantly share code, notes, and snippets.

@Gen2ly
Created June 7, 2012 10:59
Show Gist options
  • Star 5 You must be signed in to star a gist
  • Fork 2 You must be signed in to fork a gist
  • Save Gen2ly/2888207 to your computer and use it in GitHub Desktop.
Save Gen2ly/2888207 to your computer and use it in GitHub Desktop.
Paste contents of Xorg clipboard to a file from the command line
#!/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