metalx1000

Create tinyURL link for clipboard and shell

Aug 13th, 2018
1,085
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Bash 2.09 KB | None | 0 0
  1. #!/bin/bash
  2.  
  3. #Created by Kris Occhipinti
  4. #Aug 13th 2018
  5. #http://filmsbykris.com
  6.  
  7. #Licensed under the GPLv3
  8. #This is free software: you can redistribute it and/or modify
  9. #it under the terms of the GNU General Public License as published by
  10. #the Free Software Foundation, either version 3 of the License, or
  11. #(at your option) any later version.
  12. #
  13. #This code is distributed in the hope that it will be useful,
  14. #but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. #MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  16. #GNU General Public License for more details.
  17. #
  18. #You should have received a copy of the GNU General Public License
  19. #Along with this program.  If not, see <http://www.gnu.org/licenses/>.
  20. #
  21. #Description:
  22. #grabs text/url from last highlighted mouse selection
  23. #and gets a tinyurl link and puts it into clipboard
  24.  
  25. function main(){
  26.   #check for needed files/program
  27.   check_depend
  28.  
  29.   #get last mouse selection
  30.   URL="$(xclip -o)"
  31.  
  32.   echo "Starting URL $URL"
  33.  
  34.   #get tinyurl
  35.   tinyURL="$(curl -s "http://tinyurl.com/create.php?url=$URL"|grep "The following URL" -A3|tail -1|awk -F\> '{print $3}'|sed 's,</b,,')"
  36.  
  37.   #check if a url is returned
  38.   if [ "$tinyURL" = "" ];then echo "Error getting URL";exit 1;fi
  39.  
  40.   #put the tiny url in the clipboards for pasting
  41.   echo "$tinyURL"|xclip
  42.   echo "$tinyURL"|xclip -selection clipboard
  43.  
  44.   #output short link to shell
  45.   echo "URL in Clipboard: $tinyURL"
  46.  
  47.   #give qrcode output to shell for scanning
  48.   echo "$tinyURL"|qrencode -t UTF8
  49.  
  50.   #Display notification - Time out after 5 seconds
  51.   notify-send -t 5000 "URL Shortened in Clipboard" "$tinyURL"
  52. }
  53.  
  54. function check_depend(){
  55.   #list for dependencies
  56.   deps=( "/usr/bin/qrencode" "/usr/bin/xclip")
  57.   packages=( qrencode xclip );
  58.  
  59.   #check for needed dependencies
  60.   for i in "${deps[@]}"
  61.   do
  62.     if [ ! -f "$i" ];
  63.     then
  64.       echo "Attempting to install dependencies..."
  65.       echo "Needed dependencies: ${packages[@]}"
  66.       sudo apt-get install ${packages[@]} && break || (echo "Install of dependencies failed";exit 1)
  67.     fi
  68.   done
  69. }
  70.  
  71. main
Add Comment
Please, Sign In to add comment