URL shortening is nothing new, it was originally made popular due to the 140 character limit of Twitter and the 160 character limit of SMS messages. 

https://trimlink.site

https://trimlink.site has been a project of mine for sometime, it is a simple URL Shortener designed to be integrated into larger projects or just to be used to shorten long URL’s. I posted the project on reddit and reddit user spydas created a ZSH plugin for this.

I have modified this slightly to allow it to work on systems without xclip installed as not everyone runs X, I’m actually running OS X so xclip is out of the question.

To use TrimLink at the BASH prompt simply add the following to your .bashrc or .zshrc file in your home directory.

shorten() {
        if echo $1 | grep http > /dev/null
        then
        if  xclip &> /dev/null
        then
                curl -Gs "https://trimlink.site/shorten.php" -d "url=$1" | sed 's/<[^>]*>/\n/g' | sed 's/\s*//g' | xclip -selection clipboard
                echo 'Shortened URL copied to clipboard'
        else
                echo "  Install xclip to add clipboard support"
                curl -Gs "https://trimlink.site/shorten.php" -d "url=$1" | sed 's/<[^>]*>/\n/g' | sed 's/\s*//g' | sed 's/n//'
        fi
        else
            echo "Usage: shorten <url>"
                exit
        fi
}

Shortening a URL is now simple, just type shorten https://example.com

➜  ~ shorten https://example.com
	Install xclip to add clipboard support
http://t5.i/ccd99n

A warning will be shown if xclip is not installed, if you do not want to see this use the version below:

shorten() {
        if echo $1 | grep http > /dev/null
        then
        if  xclip &> /dev/null
        then
                curl -Gs "https://trimlink.site/shorten.php" -d "url=$1" | sed 's/<[^>]*>/\n/g' | sed 's/\s*//g' | xclip -selection clipboard
                echo 'Shortened URL copied to clipboard'
        else
                curl -Gs "https://trimlink.site/shorten.php" -d "url=$1" | sed 's/<[^>]*>/\n/g' | sed 's/\s*//g' | sed 's/n//'
        fi
        else
            echo "Usage: shorten <url>"
                exit
        fi
}

I hope this is found useful, if you have any issues or questions please leave a comment below.

Join the conversation

  1. Avatar
  2. Avatar
  3. Avatar
  4. James

5 Comments

    1. Nice! Here’s a fully working version for OS X users.

      shorten() {
      if echo $1 | grep http > /dev/null
      then
      if echo | pbcopy &> /dev/null
      then
      curl -Gs "https://trimlink.site/shorten.php" -d "url=$1" | sed 's/< [^>]*>/\n/g' | sed 's/\s*//g' | sed 's/n//' | pbcopy
      echo 'Shortened URL copied to clipboard'
      else
      echo " Install pbcopy to add clipboard support"
      curl -Gs "https://trimlink.site/shorten.php" -d "url=$1" | sed 's/< [^>]*>/\n/g' | sed 's/\s*//g' | sed 's/n//'
      fi
      else
      echo "Usage: shorten "
      exit
      fi
      }

  1. I allowed myself just to add xsel -ob so it will be printed out on the terminal and should be immediately clickable in terminal .

Leave a comment

Your e-mail address will not be published. Required fields are marked *

%d bloggers like this: