Skip to content

Instantly share code, notes, and snippets.

@gadamc
Last active December 30, 2015 20:59
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gadamc/7884266 to your computer and use it in GitHub Desktop.
Save gadamc/7884266 to your computer and use it in GitHub Desktop.
set up a curl alias (acurl) to include credentials so that you don't have to type them out
import base64
import os
import sys
user = raw_input('username:')
password = raw_input('password:')
b64encoded = base64.urlsafe_b64encode('{0}:{1}'.format(user,password))
shell = os.path.basename(os.environ.get('SHELL'))
if shell == 'bash':
shellrc = '{0}/.{1}_profile'.format(os.environ.get('HOME'), shell)
else:
shellrc = '{0}/.{1}rc'.format(os.environ.get('HOME'), shell)
equalizer = ' '
if shell in ('bash', 'zsh'):
equalizer = '='
elif shell in ('tcsh', 'csh'):
equalizer = ' '
else:
sys.exit('unsupported shell (bash, zsh, tcsh, csh)')
aliasline = 'alias acurl{0}"curl -s --proto \'=https\' -g -H \'Authorization: Basic {1}\'"'.format(equalizer, b64encoded)
print 'Adding the following line'
print aliasline
print 'to {0}'.format(shellrc)
with open(shellrc, 'a') as rcfile:
rcfile.write('\n### Added by acurl.py\n' )
rcfile.write(aliasline + '\n')
@garbados
Copy link

Clever :D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment