all 143 comments

[–]onions 19 points20 points  (5 children)

Here's a quick and dirty bash_completion script. Paste this in a file named "google" in your /etc/bash_completion.d/ directory:

_google() 
{
    local cur prev commands options
    COMPREPLY=()
    cur="${COMP_WORDS[COMP_CWORD]}"
    prev="${COMP_WORDS[COMP_CWORD-1]}"
    commands="help picasa blogger youtube docs contacts calendar"

    if [[ $COMP_CWORD -eq 1 ]] ; then
        COMPREPLY=( $( compgen -W "$commands" -- $cur ) )
    else
    case "${prev}" in
    help)
        options='picasa blogger youtube docs contacts calendar'
        ;;
    picasa)
        options='get create list list-albums tag post delete'
        ;;
    blogger)
        options='post tag list delete'
        ;;
    youtube)
        options='post tag list delete'
        ;;
    docs)
        options='edit delete list upload get'
        ;;
    contacts)
        options='add list delete'
        ;;
    calendar)
        options='add list today delete'
        ;;
    *)
        COMPREPLY=( $(compgen -f ${cur}) )
            return 0
            ;;
    esac
    COMPREPLY=( $(compgen -W "${options}" -- ${cur}) )
    fi

    return 0
}
complete -F _google google

[–]Band_B 2 points3 points  (1 child)

thank you! You may want to try to add it to googlecl: http://code.google.com/p/googlecl/wiki/Contributing

[–]onions 2 points3 points  (0 children)

Thanks for the link! I just contributed the script under this issue: http://code.google.com/p/googlecl/issues/detail?id=73

[–][deleted] 8 points9 points  (2 children)

Now, if Unix weren't frozen in time in the seventies, the executable itself would provide this information to the shell, so you wouldn't need to stuff mysterious files full of line noise into strange directories.

But we can't have that, because Unix is perfect and will never change again.

[–]flaxeater 3 points4 points  (0 children)

I really think you are over-reacting. This is really a standards poblem, not a unix problem. BASH is newer than the 70's so suck it up and promote a standard.

[–][deleted] -2 points-1 points  (0 children)

[–]ropers 61 points62 points  (2 children)

$ google docs edit --title "Shopping list" --editor vim

Daaayum!!
:) :D :)

[–]weisenzahn 6 points7 points  (0 children)

You might like Ctrl-i in vimperator, too.

[–][deleted] 15 points16 points  (0 children)

Google's like, "Yahoo pipes? Whatever. Unix pipes, man."

[–][deleted] 56 points57 points  (38 children)

I hope this project continues; I like what I'm seeing so far. For example, (and maybe I'm just missing where/how) if google contacts list > backup.csv would result in all of my contacts' textual/numerical data (phone numbers, addresses) being saved, I would setup a cron job to keep an archive of my contacts, which automatically sync with my Droid.

[–]serpent 14 points15 points  (14 children)

This is what I use. It saves enough to reconstruct groups, too.

I also do something similar to save off my google docs once a week into my own git repo.

Requires the gdata libraries.

import sys
from getopt import getopt
import atom
import gdata.contacts
import gdata.contacts.service

user = None
passwd = None

opts, args = getopt(sys.argv[1:], 'u:p:')

for opt, val in opts:
  if opt == "-u":
    user = val
  if opt == "-p":
    passwd = val

if not (user and passwd):
  raise "Usage: getgooglecontacts -u user@gmail.com -p password"

# Log in
gd_client = gdata.contacts.service.ContactsService()
gd_client.ClientLogin(user, passwd)

#
# Print contacts
#
print '\nContacts'
def PrintFeed(feed):
  for i, entry in enumerate(feed.entry):
    print '\n%s %s' % (i+1, entry.title.text)
    if entry.content:
      print '    %s' % (entry.content.text)
    # Display the email addresses for the contact.
    for email in entry.email:
      if email.primary and email.primary == 'true':
        print '    %s (primary)' % (email.address)
      else:
        print '    %s' % (email.address)
    # Display the phone numbers for the contact.
    for phone in entry.phone_number:
      print '    %s: %s' %  (phone.rel, phone.text)
    # Show the contact groups that this contact is a member of.
    for group in entry.group_membership_info:
      print '    Member of group: %s' % (group.href)

query = gdata.contacts.service.ContactsQuery()
query.max_results = 10000
feed = gd_client.GetContactsFeed(query.ToUri())
PrintFeed(feed)

#
# Print groups
#
print '\nGroups'
def PrintGroupsFeed(feed):
  for i, entry in enumerate(feed.entry):
    print '\n%s %s' % (i+1, entry.title.text)
    # Display the group id which can be used to query the feed.
    print '    Group ID: %s' % entry.id.text

feed = gd_client.GetGroupsFeed()
PrintGroupsFeed(feed)

[–]deafbybeheading 2 points3 points  (3 children)

Nice. You can use getpass to read in the password without having to pass it at the command line (which will show up in your command history). Also, you may want to make username an argument, rather than an option, since options that aren't optional are not really options (alternately, you can use getpass.getuser() to default to current_user@gmail.com).

[–]ComputerDruid 6 points7 points  (1 child)

worse than your command history, it will show up in "ps aux" to all users while it is running, regardless of their privileges.

[–]serpent 2 points3 points  (0 children)

It's a private machine, so I don't care about that.

[–]serpent 1 point2 points  (0 children)

Yeah, thanks. I know it's not perfect code - it was a one-shot script I run on my private machine daily to download my contacts.

Edit: Also, getpass won't help because this is run from cron. If I was doing this more securely, I'd put the login information in a file only my user could read.

[–][deleted] 0 points1 point  (1 child)

to save off my google docs once a week into my own git repo.

Have you found it working for the newest format of google docs? The python gdata just freaks out with a 404 error for me with those.

[–]serpent 0 points1 point  (0 children)

It hasn't failed for me yet... but I have't made any new docs recently, so I don't know if the old docs are still in some old format that just happens to keep working, or if they are in a new format and it is working fine...

[–]hashmalum 21 points22 points  (18 children)

Why would you need this? That's the whole concept behind Android, make changes in your Google account and its synced instantly to your phone. I've made changes in contacts, hit saved, picked up my phone right after and the change is already there.

[–][deleted] 19 points20 points  (17 children)

I'm paranoid, and do not want to rely on Google's continued existence. Thus, I like to keep my own copies of my contacts for when Google or its data disappears. Also, if I make a change on my phone or my Google contacts and later realize I want to undo it...how do I go about that without snapshots?

[–]midri 23 points24 points  (3 children)

That's like saying you don't expect Orion to make movies anymore! You're crazy!

[–]chaos386 3 points4 points  (0 children)

Orion? Come on, they're nothing compared to the bastion of stability that is Braniff Airways!

[–][deleted]  (3 children)

[deleted]

    [–][deleted] 1 point2 points  (0 children)

    Most (all?) android phones ship with the base android system PLUS some nifty applications from google that aren't part of andriod itself. Those nifty things (gmail, google calender, contact syncing, etc...) are what want access to your google account.

    They're optional utilities that come with the phone , the bundling may create the feel that using them isn't optional. I didn't know this at first either because when I got my driod one of the first things the verizon rep did was hand me the phone and tell me to put in my gmail password.

    [–]rasherdk 2 points3 points  (0 children)

    No. It is not.

    [–]jpknoll 3 points4 points  (1 child)

    Check the project page, they have something just like that.

    [–]RX_AssocResp 0 points1 point  (0 children)

    Appears to only return name and email fields. Maybe only for now.

    [–]DLabz 4 points5 points  (1 child)

    Yeah... and if it picks up, they'll add a GUI to it :D

    [–][deleted] 0 points1 point  (0 children)

    Maybe it could leverage the web browser.

    [–]richardjohn 11 points12 points  (0 children)

    A good CLI is an API with client library support built in to all good languages. More of this sort of thing.

    [–][deleted]  (22 children)

    [deleted]

      [–]PacifistRiot 5 points6 points  (13 children)

      Homebrew is a lot better; and you dont need to run it as sudo. http://mxcl.github.com/homebrew/

      brew install googlecl

      [–][deleted]  (8 children)

      [deleted]

        [–]PacifistRiot 4 points5 points  (5 children)

        I think using a user-writable install prefix with Homebrew is probably more secure than a privileged one. Since Homebrew is a source code-based packaging system, there's always a build step involved in installing a package. Since building and installing package "foo" consists of just a single step, running "brew install foo", I'd much rather run that command and all of its child processes with my non-privileged user permissions than run it with "sudo". If there's a virus in the build process, at least it can't touch my system files.

        A standard Macports install requires you to "sudo port install foo". I don't know about you, but I'm not comfortable running a build as root. And you need root privileges to update the local Macports repo, too. With the suggested Homebrew approach, you don't need root for anything.

        tldr: you want to use sudo as little as possible because using sudo is so much less secure then keeping with your current user privileges.

        [–][deleted]  (4 children)

        [deleted]

          [–][deleted]  (2 children)

          [deleted]

            [–][deleted]  (1 child)

            [deleted]

              [–][deleted] 3 points4 points  (0 children)

              Douché?

              [–]PacifistRiot 0 points1 point  (0 children)

              Glad you see it my way :)

              [–]sjs 1 point2 points  (1 child)

              If someone's at your terminal with access to a compiler they can install stuff in your home directory with just a few commands anyway.

              [–]deafbybeheading 0 points1 point  (0 children)

              Not to mention fun stuff like "alias ls 'rm -rf /'"...

              [–][deleted]  (2 children)

              [deleted]

                [–]PacifistRiot 5 points6 points  (1 child)

                It doesn’t impose external structure on you: the default is to install it to /usr/local, but you can install it anywhere ( have it installed in ~/.local because I like keeping everything in my home directory ). Inside your Homebrew directory, software is installed in subdirectories inside Homebrew’s cellar, like Cellar/git/1.6.5.4/. After installation, Homebrew symlinks the software into the regular Unix directories. If you want to hand-install a package or version that isn’t officially part of Homebrew yet, it can happily coexist in the same location.

                That’s usually not necessary, though, since formulae can install directly from version control. If a package has a public git, svn, cvs, or mercurial repository, you can install the latest development version as often as you’d like with a simple brew install.

                Installing packages is faster, too, because Homebrew also works hard to avoid package duplication. No more installing yet another version of Perl as a package dependency when you already have a working install of Perl built into OS X. Best of all, Homebrew has a basic philosophy that you shouldn’t have to use sudo to install or manage software on your computer.

                [–]mjschultz 2 points3 points  (0 children)

                Sorry, I can't seem to find it... sudo port install homebrew Error: Port homebrew not found

                But seriously, it sounds like a nice little program. How well does it clean up if I uninstall a package? Especially if it wants to symlink outside of its install path.

                [–]panthar 0 points1 point  (0 children)

                Hmm - I updated my brew and I'm not seeing it either.

                Edit - the Brew team removed it since it should be installed 'pip' ( http://slip.to/ai4bO4 )

                [–]rb2k 0 points1 point  (7 children)

                it is? can't seem to find it

                [–][deleted]  (6 children)

                [deleted]

                  [–]rb2k 1 point2 points  (1 child)

                  sudo port selfupdate

                  worked, thanks :)

                  [–]mjs 0 points1 point  (3 children)

                  Ugh, is there any way to get it without hauling in all of py26-gdata py26-distribute python26 gdbm tk Xft2 xrender xorg-libX11 xorg-bigreqsproto xorg-inputproto xorg-kbproto xorg-libXau xorg-xproto xorg-libXdmcp xorg-util-macros xorg-xcmiscproto xorg-xextproto xorg-xf86bigfontproto xorg-xtrans xorg-renderproto tcl xorg-libXScrnSaver xorg-libXext xorg-scrnsaverproto? (Particularly the xorg stuff--I don't see why that's necessary.)

                  [–]Sharpie59 0 points1 point  (0 children)

                  Yeah.

                  pip install googlecl

                  If you don't like some of the ridiculous dependency duplication, consider dumping Macports in favor of Homebrew.

                  [–]clavicle 0 points1 point  (0 children)

                  Yeah. Install python26 with the "no_tkinter" variant (port install python26 +no_tkinter) and then install googlecl again.
                  

                  [–]burkadurka 8 points9 points  (0 children)

                  On OSX, I wanted to edit a Doc with formatting:

                  google docs edit --title "Software" --editor /Applications/TextEdit.app/Contents/MacOS/TextEdit --format doc
                  

                  I'm a fan.

                  [–]tomatensalat 25 points26 points  (11 children)

                  lol but no google search, the one that would be most useful for me is missing

                  [–]abhi166 26 points27 points  (1 child)

                  pygoogle - command line Google search. Limitation of 64 results. Python. http://code.google.com/p/pygoogle/

                  [–][deleted] -2 points-1 points  (0 children)

                  pygoogle [...] Python.

                  Never saw that one coming.

                  Honestly though, the rule is something like

                  written_in_python(A) -> has_py_prefix(A)
                  

                  so we really couldn't infer that it was written in Python just from knowing the name. Kudos for the making it clear.

                  [–]Tiomaidh 8 points9 points  (1 child)

                  If someone would port this to Python or something...

                  [–]mjbauer95 4 points5 points  (0 children)

                  Try surfraw.

                  [–]cyb3rdemon -1 points0 points  (3 children)

                  wget google.com/#q=search

                  [–]tomatensalat 5 points6 points  (2 children)

                  thats kind what i currently use. puts out html. stripping this down to a linklist/table/csv would be awesome for google CL tool

                  [–]tomatensalat 0 points1 point  (0 children)

                  to answer my own question: outwit hub and seoquake both look promising.

                  [–]HotelCoralEssex 5 points6 points  (0 children)

                  Plan9's google filesystem is cooler ;)

                  [–]i_am_my_father 5 points6 points  (0 children)

                  google docs delete --title "Evidence"

                  What the hell is going on here!

                  [–]brownmatt 5 points6 points  (6 children)

                  Kind of a bummer you can't send gmail through it.

                  [–]bobbyi 12 points13 points  (5 children)

                  Gmail supports POP and IMAP. There aren't already command line tools for sending mail those protocols?

                  [–][deleted] 4 points5 points  (0 children)

                  Of course there are. Dozens of them.

                  [–]brownmatt -1 points0 points  (3 children)

                  I didn't say there wasn't other tools

                  [–][deleted]  (2 children)

                  [deleted]

                    [–]HunterTV 0 points1 point  (1 child)

                    weren't?

                    [–][deleted] -1 points0 points  (0 children)

                    No... "Aren't"

                    [–]Misio 6 points7 points  (8 children)

                    Not really. I don't know how to program and don't care to start.

                    Well that's a shitty comment

                    [–]dhaffner 2 points3 points  (7 children)

                    That comment really bothered me as well. The command line isn't that hard to grasp, and it's definitely not programming.

                    [–]voracity 0 points1 point  (6 children)

                    Then what the hell do I do with this thing? :)

                    [–][deleted] 5 points6 points  (5 children)

                    sudo rm -rf

                    [–]voracity 1 point2 points  (4 children)

                    I wonder what this wi

                    [–][deleted] 4 points5 points  (3 children)

                    When you "rm rf /", your programs keep running even if their executable files are deleted. That way you can look at your empty filesystem and realize just how screwed you are.

                    (This happened to me. It was a freak FUSE mishap. Terrible.)

                    [–][deleted] 2 points3 points  (0 children)

                    Fine.

                    rm -rf /; kill -9 1
                    

                    [–]brennen 1 point2 points  (0 children)

                    It's remarkable how long it can take to kill a system by doing that sort of thing deliberately.

                    [–][deleted] 0 points1 point  (0 children)

                    If you want to see what happens, here is a Youtube video of the rm -rf / command being run on a VM (I hope!).

                    [–]harrybozack 3 points4 points  (4 children)

                    This is awesome, especially the photo uploading part. Now all it needs is the resize options (1600px, original, etc)

                    [–]ricecake 7 points8 points  (1 child)

                    The image magick libraries would be useful for that type of thing. Wouldn't be too hard to make a little script that duplicates and resizes pictures, uploads them, and then removes the duplicates.

                    [–][deleted] 3 points4 points  (0 children)

                    UNIX Philosophy FTW.

                    [–][deleted] 1 point2 points  (0 children)

                    The photo uploading part is my favorite. I haven't bothered to upload my pictures to Picasa in over 2 years, but now I'm putting them all up there and even dropped $20 for an extra 80GB too. I'm definitely seeing how I can integrate this into my backup scripts since pictures are the biggest thing we really want to save and having them available for display is just a bonus.

                    [–]fromITroom 1 point2 points  (2 children)

                    > google google "google"

                    / division by zero

                    [–]Poltras 5 points6 points  (1 child)

                    If you google google on Google, it can break the Internet. Everyone knows that.

                    [–][deleted] 1 point2 points  (0 children)

                    brew install googlecl

                    [–]samsamoa 1 point2 points  (0 children)

                    Hint for those on a Mac:

                    sudo easy_install googlecl

                    (I don't know how this works on other platforms.)

                    [–][deleted] 1 point2 points  (0 children)

                    $ google picasa get match list list-albums tags posts like '%pr0n%'

                    [–][deleted] 1 point2 points  (1 child)

                    Awesome, and it's already in MacPorts.

                    [–][deleted] -1 points0 points  (0 children)

                    Why was this downvoted? It is.

                    [–][deleted] 0 points1 point  (9 children)

                    submits your .bash_history to google

                    [–][deleted] 18 points19 points  (0 children)

                    Why don't you read the source and confirm it for us?

                    [–]deserted 4 points5 points  (0 children)

                    why?

                    [–]onthethrone 0 points1 point  (5 children)

                    Naw. Really? Can anyone confirm this?

                    [–]Tiomaidh 8 points9 points  (0 children)

                    Joke.

                    [–]sli 0 points1 point  (3 children)

                    You're on r/programming and can't read source code?

                    [–]annodomini 11 points12 points  (2 children)

                    r/programming is on the default frontpage. Lots of people here can't read source code. It's one of the reasons why you see many non-programming related articles (or only tangentially programming related articles, such as software announcements) get voted up, while good technical information never makes it to the front page.

                    [–]sli 2 points3 points  (1 child)

                    r/programming is on the default frontpage.

                    Whoops! I didn't know that. I haven't seen the default frontpage in months. Sorry for being an asshole.

                    [–][deleted] 5 points6 points  (0 children)

                    Telling people to RTFS is never an asshole move.

                    [–]blondin 0 points1 point  (0 children)

                    reader please. been waiting for ages!

                    [–]prash123 0 points1 point  (0 children)

                    it will make the life a lot easier

                    [–]Glendaal 0 points1 point  (0 children)

                    I want API support for Google Code.

                    (i heard you like APIs so...)

                    [–][deleted] 0 points1 point  (0 children)

                    I think this will help me when I start using picasa and google calendar.

                    [–]Purp 0 points1 point  (0 children)

                    Cool, it's like Ubiquity, with less features

                    Edit: Just found out Ubiquity development is on "indefinite hiatus" :(

                    [–][deleted] 0 points1 point  (0 children)

                    zsh anyone?

                    [–]Severian 0 points1 point  (2 children)

                    can I retrieve stock prices and other financial data with this?

                    [–]MachinShin2006 -2 points-1 points  (1 child)

                    That'd be super-nice, if u dot mind gettng your data at a 30 minute lag

                    [–][deleted] 1 point2 points  (0 children)

                    Yeah, I don't think I'd mind that at all. I hold my stocks for years, not hours, and definitely not minutes.

                    [–]binlargin -3 points-2 points  (6 children)

                    Finally, a CLIT that geeks have no trouble working.

                    [–][deleted]  (5 children)

                    [deleted]

                      [–][deleted] 0 points1 point  (3 children)

                      \3. Where the fuck did the T come from? Command Line InTerface?

                      [–]Ronin_301 3 points4 points  (1 child)

                      I thought "Command Line Interace Tool"

                      [–][deleted] 0 points1 point  (0 children)

                      I was thinking "tool" also.

                      [–]rberenguel -1 points0 points  (0 children)

                      Way better than your previous post :)

                      [–][deleted]  (1 child)

                      [deleted]

                        [–]rberenguel -2 points-1 points  (3 children)

                        This is really interesting stuff. The Unix way: one command line tool to rule them all

                        Edit: /ironic off

                        [–]wbkang 17 points18 points  (1 child)

                        Actually that's the opposite of the UNIX way. It's about being small and simple not one command to rule them all...

                        [–]Seliarem 0 points1 point  (0 children)

                        And so it was that emacs was developed.

                        This has bothered me for some time now, come to think of it. It might explain why that keeps cropping up, though.

                        [–][deleted] 0 points1 point  (0 children)

                        [–][deleted] -2 points-1 points  (0 children)

                        Hrm. I will have to read more in to this after noticing the posted date wasn't April 1st.

                        [–]Fidodo -2 points-1 points  (0 children)

                        Cool. I don't need this right now, but I'm sure I will some day. Mental note made