Created
August 29, 2015 14:26
-
-
Save thewhitetulip/e71b5b96159d32cc9413 to your computer and use it in GitHub Desktop.
Trim the username on the bash terminal
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 promptThe terminal looks way more cleaner this way
Link: http://askubuntu.com/questions/17723/trim-the-terminal-command-prompt-working-directory/17738#17738