A dynamic working directory string shortener for BASH terminals.
A Python and C file are provided that enable you to customise your terminal so that the working directory string will be shortened such that the string will not occupy more than ~40% of the terminal width by reducing the number of characters in any parent directory strings. The C version is faster than the Python version.
- Place the script in the home directory
- Give the script the relevant permissions to execute on your system.
chmod 755 dirShort.pyfor example. - Add the following to your ~/.bashrc file (change the colors if you wish):
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]$(python3 $HOME/dirShort.py "$(dirs)")\[\033[00m\]\$ '
- Compile the file using
gcc -O3 -Wall -std=c99 dirShort.c -o dirShort - Place the executable in the home directory. (
dirShortis you used the above command) - Give the executable the relevant permissions to execute on your system.
chmod 775 dirShortfor example. - Add the following to your ~/.bashrc file (change the colors if you wish):
PS1='\[\033[01;32m\]\u@\h\[\033[00m\]:\[\033[01;34m\]$($HOME/dirShort "$(dirs)")\[\033[00m\]\$ '
From:
user@pc:~/myFiles/documents/codeExamples
To (gradually reducing terminal width):
user@pc:~/myFiles/documen/codeExamples
user@pc:~/myFil/docum/codeExamples
user@pc:~/myF/doc/codeExamples
user@pc:~/m/d/codeExamples
- You may wish to tweek the limits in the file to suit your own terminal needs