The team that runs the 18F website recently started writing down the tools and processes that we use to update the blog and the code that runs the site.īecause some of the people we hire have never used these tools before, this guide assumes you have no prior knowledge of them either. We hire people from many different backgrounds and each new employee brings a different level of comfort with the specific tools we use on our various projects. If you’ve never used GitHub before, it can be a little intimidating, so we’d like to share the tutorial our own new employees use when they start with 18F. We do this so that the public can see the code we’re working on, offer feedback, and copy or fork that code for their own projects.
One of the ways we do that is by building all of our products-from our blog and our dashboard to a new website for the Peace Corps’ Let Girls Learn Initiative-using GitHub.
This used to be fine, as the python binary shipped with macOS. While this has worked wonderfully and more reliably than other solutions, it always looked inelegant, and added a dependency on the python binary. But there are edge cases, mostly with Fast User Switching, where these methods don’t return the correct user. There are various other solutions to get the current user which use stat, who, or last commands. However, the semi-official, “sanctioned” method has always involved a rather elaborate python one-liner, originally published by Ben Toms: loggedInUser=$(/usr/bin/python -c 'from SystemConfiguration import SCDynamicStoreCop圜onsoleUser import sys username = (SCDynamicStoreCop圜onsoleUser(None, None, None) or ) username = ] (username + "\n") ') There are many solutions to get the current logged in user in macOS to use in a shell script.
…or, how to deal with deprecated bash and python…