I constantly find myself needing to open a lot of similar tabs to research something at work. For example, maybe I want to review account notes on a few dozen accounts, or I want to audit 30-40 support tickets.
Most web apps usually just pass unique identifiers in the URL itself. For example, if you use Zendesk, a ticket URL might be https://subdomain.zendesk.com/tickets/123456 where 123456 is the Ticket ID number. You might have an internal CRM tool that has a URL like https://internal.company.com/accounts/95438.
It doesn’t take a genius to figure out that by just changing the 95438 in the URL to a different number, you pull up a different account. So instead of going through the trouble of searching in the web app, most people just change the URL to the account they are looking for, or create a custom search in their browser.
When I have more than 4 or 5 of the same type of item I want to review (Tickets, Accounts, whatever), it becomes tedious to copy each item, open a new tab manually, paste the variable, and wait for the page to load.
For cases like this, I wrote a simple bash utility that I call tabit. Tabit has one job: Read input from a file and open a bunch of tabs with the specific variables. Here is a quick example using Youtube (since I obviously won’t share the links to Rackspace’s internal tools).
Say you have a list of the 10 most popular Youtube Video IDs.
1 2 3 4 5 6 7 8 9 10 |
9bZkp7q19f0 RgKAFK5djSk ORhEE9VVg OPf0YbXqDm0 YQHsXMglC9A nfWlot6h_JM NUsoVlDFqZg 0KSOMA3QBU0 kffacxfA7G4 7PCkvCPvDXk |
We know that Youtube’s URL format is https://www.youtube.com/watch?v=<Unique ID>. Instead of manually copying/pasting that 10 times, here is how you would do it with Tabit.
First, grab the source from github: https://github.com/joshprewitt/tabit or copy the script below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 |
#!/bin/bash #Initialize variables to default values. TABFILE="$HOME/.tabit" NEWWINDOW=1 #Set fonts for Help. NORM=$(tput sgr0) BOLD=$(tput bold) #Help function function HELP { echo -e \\n"${BOLD}Help documentation for tabit${NORM}"\\n echo -e "${BOLD}Basic usage: ${NORM}tabit [options] <start of URL with trailing slash> [Remainder of URL with leading slash]"\\n echo "${BOLD}Options:${NORM}" echo "${BOLD}-f${NORM} <path to file>. -- File to read variables from. Default is ~/.tabit" echo "${BOLD}-c${NORM} -- Use Current Window." exit 1 } #Check the number of arguments. If none are passed, print help and exit. NUMARGS=$# if [ $NUMARGS -eq 0 ]; then HELP fi ### Start getopts code ### #Parse command line flags #If an option should be followed by an argument, it should be followed by a ":". #Notice there is no ":" after "h". The leading ":" suppresses error messages from #getopts. This is required to get my unrecognized option code to work. while getopts :f:ch FLAG; do case $FLAG in f) #set option for custom file TABFILE=$OPTARG ;; c) #set option for current window NEWWINDOW=0 ;; h) #show help HELP ;; \?) #unrecognized option - show help echo -e \\n"Option $OPTARG not allowed." HELP ;; esac done shift $((OPTIND-1)) #This tells getopts to move on to the next argument. #Call Chrome by itself. This will create a new window instead of hijacking the existing one. if [ $NEWWINDOW -eq 1 ]; then /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome fi ### Actually Open The Tabs ### while read line; do open -a /Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome $1$line$2; done < $TABFILE |
Place it somewhere in your default path. If you don’t know what that means, just put it at /usr/local/bin/tabit
Make it executable:
1 |
chmod +x /usr/local/bin/tabit |
By default, Tabit looks for a file in your user’s home directory called ‘.tabit’. Paste the list of Youtube IDs into that file. If you are on a Mac and just copied the list above, the following will do the trick:
1 |
pbpaste > ~/.tabit |
All that is left to do now is run the script. Using the defaults, the syntax is really simple: Just run
1 |
tabit https://www.youtube.com/watch?v= |
I added a few options like the ability to specify a file instead of the default ~/.tabit and also the option to have the tabs open in your current Chrome window. Lastly, if you happen to have a URL where the variable is NOT the last part of the URL, you can add on a suffix. You get the following help documentation if you run tabit with no arguments:
Help documentation for tabit
Basic usage: tabit [options] <start of URL with trailing slash> [Remainder of URL with leading slash]
Options:
-f <path to file>. — File to read variables from. Default is ~/.tabit
-c — Use Current Window.
That’s it! After you get used to using this, you will find that it is much easier to just paste the variables into ~/.tabit and run the script instead of manually opening a bunch of tabs.
Keyboard Shortcuts
When working with dozens (to hundreds) of tabs, don’t forget these shortcuts
Shortcut Keys | Action |
---|---|
Cmd+Shift+{ | Go to Left Tab |
Cmd+Shift+} | Go to Right Tab |
Cmd+w | Close Tab |
Cmd+Shift+T | Re-Open Most Recently Closed Tab |
Click a tab + Shift + Click a different tab | Select Range of Tabs (Cmd+w will close all selected tabs) |
Gotchas
The script assumes a standard installation of Google Chrome. If you installed it somewhere else, you will need to edit lines 58 and 62 with the correct path to Chrome on your system.
References
Optargs help came from http://tuxtweaks.com/2014/05/bash-getopts/
0 Comments.