How to shorten current path name
Hello
If i am using a terminal window (shell) and I am on a deep point of a folder tree it becomes difficult to read what i write, as well as the entire content of the window. Is there a way to shorten the name of the current path in a shell / terminal? I know that aliases can be used for commands, does it exist anything similar for paths? |
You can use symbolic links. See the man pages for the ln command.
|
Does the PROMPT_DIRTRIM variable do what you want, for example export PROMPT_DIRTRIM=3
|
yeah symbolic links are one of the more powerful features of Linux that are only half implimented in windows as 'shortcuts', i've even used symbolic links to put modules for a web script on an nfs server (yes i could have mounted the nfs server as the modules directory, but with symlinks I could use the same module set for multiple instances of said script in multiple document roots)
another way would be to simply edit the PS1 value in .bashrc in your home directory Quote:
eg Code:
export PS1='[\u@\h \W]\$ ' as opposed to Code:
export PS1='[\u@\h \w]\$ ' though a symlink has the added bonus of making navigating to the directory quicker |
Quote:
http://en.wikipedia.org/wiki/Symboli..._symbolic_link I've never tried using them. They might suck. I suspect PROMPT_DIRTRIM is the answer to the OP's query. |
I use symbolic links all the time. For instance, I might support a product that installs to a path like so:
/opt/company_name/product_brand/specific_product_name/version_number And symlink it to: /productroot Not only does it make it easier for me to navigate, but later on while I'm transitioning between two different versions, it means I don't have to change any of my automation scripts or configuration files. I simply manipulate the symlink. But to each their own. |
Quote:
Quote:
Quote:
|
I always end my PS1 with \n\$ '. This give me a full line for my command and can keep a full path in the prompt. It takes two lines, but this is better than having command lines split over two lines.
|
Thanks to everybody for your suggestions.
I'll give a try to your different solutions. |
Quote:
Code:
14:39 /media/5 Code:
export PS1="\n$grey \$(date +%R) \w\n $cyan\\$ $no_color" |
All the solutions proposed above are very good and usable for a prompt and
some are also good for general use. For those simply looking for a solution that means less to type (as opposed to shortening the prompt), two other easily used possibilities remain: 1. If your execution path lies in the same volume, use a hard link: Code:
ln /myvolume/my_very_long_path_including_all_intervening_directories_and_myfile /myvolume/myfile 2. Create and export a shell variable: Code:
# export if necessary: a file included in a shell invocation. If placed in an invocation file, the name would be better chosen as a unique name, unlikely to be chosen by other shells. |
I don't like symlinks for this purpose. They don't change the PWD correctly:
Code:
ln -s /var/www /home/user/www This function shortens the path to display only the next 2 higher dirs. Put it in your .bashrc and change the PS1 to include any other things you want. Code:
# generate shortened pwd entry similar to csh's, for the PS1 prompt |
I have also been frustrated by this feature.
Padeen, I was previously frustrated by this issue but resolved it differently.
Quote:
Had you entered Code:
cd /var/www I haven't tested your solution but prefer to keep my code simple. I don't like changing the meaning of $PWD to be different from what bash coders or programmers expect. If I were to use such a redefinition of $PWD, that, too, could break some scripts and if the script were lengthy and not written by me, I could spend a lot of time "fixing" it. By the way, if you insist on using your change to $PWD, you might also consider making an alias for the pwd command. Some "bin" directory commands are actually scripts. On my Mac G5 running the Tiger (10.4.11) OS, many /usr/bin commands are actually recognized as "Bourne" scripts by the "file" command but begin with "#!/bin/sh" which will default to bash (Bourne-Again-SHell) anyway. _ |
Quote:
|
Quote:
If you want to use the actual directory in your scripts instead of the symlink, then just use /var/www instead. |
All times are GMT -5. The time now is 03:14 AM. |