Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- '''
- Still not really that functional
- Dependencies:
- - http://pypi.python.org/pypi/GitPython
- - http://pypi.python.org/pypi/termcolor
- Installing termcolor:
- sudo apt-get install python-stdeb
- wget http://pypi.python.org/packages/source/t/termcolor/termcolor-1.1.0.tar.gz#md5=043e89644f8909d462fbbfa511c768df
- tar xf termcolor-1.1.0.tar.gz
- cd termcolor-1.1.0
- python setup.py --command-packages=stdeb.command bdist_deb
- sudo dpkg -i deb_dist/python-termcolor_1.1.0-1_all.deb
- '''
- __author__ = 'Kurt Schwehr'
- import datetime
- import os
- import re
- import subprocess
- import sys
- import git
- import termcolor
- def get_width():
- proc = subprocess.Popen(['tput', 'cols'] , stdout=subprocess.PIPE)
- width = proc.communicate()[0].strip()
- return int(width)
- try:
- repo = git.Repo('.')
- branch = '[%s]' % repo.active_branch
- except InvalidGitRepositoryError:
- branch = '' #None
- homedir = os.path.expanduser('~')
- path = re.sub('^'+homedir, '~', os.getcwd())
- # FIX: trim long path from left
- now = datetime.datetime.now()
- when = now.strftime('%a %H:%M:%S')
- who = '(%s@%s)' % (os.getlogin(), os.uname()[1].split('.')[0])
- #who = '(%s@%s)' % (os.getlogin(), socket.gethostname()[1].split('.')[0])
- width = get_width()
- print width
- # FIX: Nicely balance where things go and use the width
- prompt = ' ({path}) {when} {branch} {who} '.format(**locals())
- prompt += ' ' * (width - len(prompt))
- prompt_clr = termcolor.colored(prompt, 'white', 'on_green', attrs=['bold'])
- print prompt_clr
- print '# ',
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement