Skip to content

Instantly share code, notes, and snippets.

@Nixtren
Last active January 2, 2017 17:35
Show Gist options
  • Select an option

  • Save Nixtren/46191216c8e6349b94b7f776e26b593f to your computer and use it in GitHub Desktop.

Select an option

Save Nixtren/46191216c8e6349b94b7f776e26b593f to your computer and use it in GitHub Desktop.
Add transfer.sh alias to .bashrc
<?php
/*
This dirty script adds transfer.sh alias to .bashrc
The string is Base64 encoded because I don't know if the original code would cause any conflict with the PHP variables
You might be wondering why I made this in PHP. Well, it's just because I use PHP on a daily basis. Feel free to port it to Bash or whatever!
Quickly coded by Nixtren, released under public domain because there's nothing special here
Run this with a one-liner:
curl -s https://gist.githubusercontent.com/Nixtren/46191216c8e6349b94b7f776e26b593f/raw | php
The decoded Base64 string should be the following:
transfer() { if [ $# -eq 0 ]; then echo "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; rm -f $tmpfile; }
*/
$string = <<<HEREDOC
dHJhbnNmZXIoKSB7IGlmIFsgJCMgLWVxIDAgXTsgdGhlbiBlY2hvICJObyBhcmd1bWVudHMgc3Bl
Y2lmaWVkLiBVc2FnZTpcbmVjaG8gdHJhbnNmZXIgL3RtcC90ZXN0Lm1kXG5jYXQgL3RtcC90ZXN0
Lm1kIHwgdHJhbnNmZXIgdGVzdC5tZCI7IHJldHVybiAxOyBmaQp0bXBmaWxlPSQoIG1rdGVtcCAt
dCB0cmFuc2ZlclhYWCApOyBpZiB0dHkgLXM7IHRoZW4gYmFzZWZpbGU9JChiYXNlbmFtZSAiJDEi
IHwgc2VkIC1lICdzL1teYS16QS1aMC05Ll8tXS8tL2cnKTsgY3VybCAtLXByb2dyZXNzLWJhciAt
LXVwbG9hZC1maWxlICIkMSIgImh0dHBzOi8vdHJhbnNmZXIuc2gvJGJhc2VmaWxlIiA+PiAkdG1w
ZmlsZTsgZWxzZSBjdXJsIC0tcHJvZ3Jlc3MtYmFyIC0tdXBsb2FkLWZpbGUgIi0iICJodHRwczov
L3RyYW5zZmVyLnNoLyQxIiA+PiAkdG1wZmlsZSA7IGZpOyBjYXQgJHRtcGZpbGU7IHJtIC1mICR0
bXBmaWxlOyB9IA==
HEREDOC;
$string = base64_decode($string);
$result = file_put_contents(getenv("HOME") . "/.bashrc", "\n" . $string . "\n", FILE_APPEND);
if($result)
{
$home = getenv("HOME");
exec("source {$home}/.bashrc");
echo "Done!\n";
}
else echo "Failed to write .bashrc\n";
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment