New awesome exemple (URL copied to clipboard) #349

Closed
opened 2026-01-19 18:29:59 +00:00 by michael · 1 comment
Owner

Originally created by @heuzef on GitHub.

Thanks for this amazing tools ! New awesome example with alias (.bashrc) :

transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile | parcellite -c | sleep 1; rm -f $tmpfile; echo "URL copied to clipboard"; echo; }

URL will be copied to clipboard via parcellite :)

> transfer texture.jpg ######################################################################## 100,0% URL copied to clipboard

Originally created by @heuzef on GitHub. Thanks for this amazing tools ! New awesome example with alias (.bashrc) : `transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile | parcellite -c | sleep 1; rm -f $tmpfile; echo "URL copied to clipboard"; echo; }` URL will be copied to clipboard via [parcellite](parcellite.sourceforge.net) :) `> transfer texture.jpg ######################################################################## 100,0% URL copied to clipboard `
Author
Owner

@gingerbeardman commented on GitHub:

you should use pbcopy instead as it is a built-in macOS command.

see https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/pbcopy.1.html or https://ss64.com/osx/pbcopy.html

Here's my version of transfer

transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile | pbcopy; pbpaste; echo; rm -f $tmpfile; }

it copies the URL to the clipboard/pasteboard and prints out the URL followed by a carriage return.

@gingerbeardman commented on GitHub: you should use `pbcopy` instead as it is a built-in macOS command. see https://developer.apple.com/legacy/library/documentation/Darwin/Reference/ManPages/man1/pbcopy.1.html or https://ss64.com/osx/pbcopy.html Here's my version of transfer ` transfer() { if [ $# -eq 0 ]; then echo -e "No arguments specified. Usage:\necho transfer /tmp/test.md\ncat /tmp/test.md | transfer test.md"; return 1; fi tmpfile=$( mktemp -t transferXXX ); if tty -s; then basefile=$(basename "$1" | sed -e 's/[^a-zA-Z0-9._-]/-/g'); curl --progress-bar --upload-file "$1" "https://transfer.sh/$basefile" >> $tmpfile; else curl --progress-bar --upload-file "-" "https://transfer.sh/$1" >> $tmpfile ; fi; cat $tmpfile | pbcopy; pbpaste; echo; rm -f $tmpfile; } ` it copies the URL to the clipboard/pasteboard and prints out the URL followed by a carriage return.
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: dutchcoders/transfer.sh#349