Skip to content

Instantly share code, notes, and snippets.

@thewhitetulip
Created August 29, 2015 14:26
Show Gist options
  • Save thewhitetulip/e71b5b96159d32cc9413 to your computer and use it in GitHub Desktop.
Save thewhitetulip/e71b5b96159d32cc9413 to your computer and use it in GitHub Desktop.
Trim the username on the bash terminal
import os
from commands import getoutput
from socket import gethostname
hostname = gethostname()
username = os.environ['USER']
pwd = os.getcwd()
homedir = os.path.expanduser('~')
pwd = pwd.replace(homedir, '~', 1)
if len(pwd) > 30:
pwd = pwd[:10]+'...'+pwd[-20:] # first 10 chars+last 20 chars
#print '%s$ ' % (pwd)
print '%s$ ' %(pwd)
@thewhitetulip
Copy link
Author

add this to your .bashrc
export PROMPT_COMMAND='PS1="$(python ~/.short_pwd.py)"'

The default bash prompt makes it terrible to use the terminal once the dir length crosses 30, so this script shortens the length to 30 characters

~/Download...pse.github.io-master$
for Downloads/goclipse.github.io-master/

~$ is the default prompt

The terminal looks way more cleaner this way

Link: http://askubuntu.com/questions/17723/trim-the-terminal-command-prompt-working-directory/17738#17738

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