Skip to content

Instantly share code, notes, and snippets.

@mildred
Created June 13, 2016 13:37
Show Gist options
  • Save mildred/23f98fa15f8542185c0f31a90d36aabc to your computer and use it in GitHub Desktop.
Save mildred/23f98fa15f8542185c0f31a90d36aabc to your computer and use it in GitHub Desktop.
ccut, ccopy, cpaste command line
chelp() {
echo "chelp - this help" >&2
echo "ccopy FILE... - copy these files to the cclipboard" >&2
echo "ccut FILE... - move these files to a temp dir and put them in the cclipboard" >&2
echo "cpaste [-c] - copy the files in the cclipboard in the current directory" >&2
echo "cmove - moves the files in the cclipboard in the current directory" >&2
echo "clist - list the files in the cclipboard" >&2
echo "cclear - clear the cclipboard and remove temporary files" >&2
}
ccopy() { sed 's:^: :' ~/.cache/cclist >&2; for i in "$@"; do echo "$PWD/$i" >> ~/.cache/cclist; echo "+ $PWD/$i">&2; done }
ccut() { sed 's:^: :' ~/.cache/cclist >&2; mkdir -p "/tmp/ccopy-$USER"; for i in "$@"; do echo "+ /tmp/ccopy-$USER/${i##*/} ($i, moved)">&2; mkdir -p "/tmp/ccopy-$USER/`dirname "$i"`"; mv "$i" "/tmp/ccopy-$USER/$i"; echo "/tmp/ccopy-$USER/$i" >> ~/.cache/cclist; done }
cpaste() { ( exec 5<~/.cache/cclist; while read i <&5; do echo "= ${i##*/} ($i, copy)" >&2; cp -i -a "$i" .; done ); if [ "a$1" = "a-c" ]; then cclear; fi }
cmove() { ( exec 5<~/.cache/cclist 6>~/.cache/cclist.$$; while read i <&5; do echo "~ ${i##*/} ($i, moved)" >&2; if ! mv -i "$i" . || [ -e "$i" ]; then echo "$i">&6; fi; done; mv ~/.cache/cclist.$$ ~/.cache/cclist ); sed 's:^:+ :' ~/.cache/cclist }
clist() { :>>~/.cache/cclist; cat ~/.cache/cclist }
cclear() { sed 's:^:- :' ~/.cache/cclist >&2; if [ -e "/tmp/ccopy-$USER" ]; then echo "rm -rf /tmp/ccopy-$USER" >&2; rm -rf "/tmp/ccopy-$USER"; fi; :>~/.cache/cclist }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment