This is for Mac OS X and requires npm.
- Open a terminal
- Type
bitly http://www.somewebsite.com/needs/to/be/shortened/
The shortened link is now in your clipboard. Paste the shortened link wherever you need to!
- Open a terminal
- Type
npm install request(if you don't already have the request module). - Type
cd /usr/local/lib/node - Type
vim bitly.js - Now paste in the following code:
var request = require('request'),
sys = require('sys'),
link = process.ARGV[2],
bitly = 'http://api.bit.ly/v3/shorten';
function urlencode(str) {
return escape(str)
.replace('+', '%2B')
.replace('%20', '+')
.replace('*', '%2A')
.replace('/', '%2F').replace('@', '%40');
}
// prepend http if it does not exist.
if (!/^https?:\/\//i.test(link)) {
link = 'http://' + link;
}
// urlencode the link and add to params.
var params = 'login=YOUR_LOGIN_ID&apiKey=YOUR_API_KEY&longUrl='+urlencode(link)+'%2F&format=json';
request({uri:bitly, body:params, method:'POST'},function(error,response,body){
if(!error && response.statusCode === 200 && body)
{
var json = JSON.parse(body);
console.log(json.data.url);
}
});
NOTE: You will need to supply your own login and apiKey values.
- Type
ESC:wqto save the file and close it. - Back in your terminal type
vim ~/.bash_profile - Paste in the following block of code:
function bitly()
{
bitlyPath='/usr/local/lib/node/bitly.js'
node $bitlyPath $1 | pbcopy
}
- Type
ESC:wqto save the file and close it. - Restart your terminal.
- Type
bitly www.google.com.
The bitly link for "www.google.com" is now in copied into your clipboard.