Configure KDE Terminal Working Directory

Duncan 1i5t5.duncan at cox.net
Tue Jun 26 10:13:37 BST 2012


Zaki Akhmad posted on Tue, 26 Jun 2012 13:28:52 +0700 as excerpted:

> I want to configure my KDE terminal
> 
> The default appearance of terminal with
> /home/za/Video/youtube/music/mraz working directory is like this:
> za at zara:/home/za/Video/youtube/music/mraz
> 
> If my working directory is too deep, the terminal appearance won't be
> convenience again, so I'd like to only show the last directory
> za at zara:/mraz
> 
> How to do that?

I'm guessing you're talking about the shell prompt.  Assuming that shell 
is bash, you can read all about it in the bash (1) manpage or the bash 
info pages.  What you want to look for is the information on PROMPTING, 
and set the PS1 variable accordingly.  FWIW, I have a quite complicated 
multi-color three-line prompt here (fg=foreground color, bg=background 
color):

The first line is blank (a simple linefeed char)

Second line as a normal user:
fg:yel        red grn      gry      yel      red         cyn
bg:blu        blk blk      blk      blk      blk         blk
username at host tty 24H-time history# #bg-jobs exit-status pwd

That typically leaves enough room for a full path

Third line as normal user (very short, three chars)
fg:yel
bg:blu
$>>


If I'm root, the first bits of both lines become yellow on red instead of 
yellow on blue, the username changes to root of course, and the first 
char of line three changes to a # instead of $, so it's very hard to miss 
that I'm running as root, especially with the blue changing to red!

To do that, I use ANSI-term color-codes and the standard prompt escapes 
as explained in the bash infopages or manpage.  Here's what I have PS1 
set to, as displayed by "echo $PS1" (this is as a normal user, as root, 
the color-codes would be slightly different, I have logic for that in my 
shell startup scripts) :

\n\[\033[00;01;33;44m\]\u@\h\[\033[00m\] \[\033[00;01;31;40m\]\l\[\033[00m
\] \[\033[00;01;32;40m\]\t\[\033[00m\] \[\033[00;01;30;40m\]#\!\[\033[00m
\] \[\033[00;01;33;40m\]j\j\[\033[00m\] \[\033[00;01;31;40m\]s$?\[\033[00m
\] \[\033[00;01;36;40m\]\w\[\033[00m\] \n\[\033[00;01;33;44m\]\$>>\[\033
[00m\]


Meanwhile, excerpts from the manpage to help decode the above:

(Under Shell Variables)

PROMPT_DIRTRIM   If set to a number greater than zero, the value is used 
as the number of trailing directory components to retain when expanding 
the \w and \W prompt string escapes (see PROMPTING below).  Characters 
removed are replaced with an ellipsis.

PS1    The  value  of this parameter is expanded (see PROMPTING below) 
and used as the primary prompt string.  The default value is ``\s-\v\$ ''.


(Under PROMPTING)

When executing interactively, bash displays the primary prompt PS1 when 
it is ready to read a command, and the secondary prompt PS2 when it needs 
more input to complete a command.   Bash allows these prompt strings to 
be customized by inserting a number of backslash-escaped special 
characters that are decoded as follows:

    \h     the hostname up to the first `.'
    \j     the number of jobs currently managed by the shell
    \l     the basename of the shell's terminal device name
    \n     newline
    \t     the current time in 24-hour HH:MM:SS format
    \u     the username of the current user
    \w     the current working directory, with $HOME abbreviated with
           a tilde (uses the value of the PROMPT_DIRTRIM variable)
    \W     the basename of the current working directory,
           with $HOME abbreviated with a tilde
    \!     the history number of this command
    \$     if the effective UID is 0, a #, otherwise a $
    \nnn   the character corresponding to the octal number nnn
    \[     begin  a  sequence  of  non-printing  characters, which could
           be used to embed a terminal control sequence into the prompt
    \]     end a sequence of non-printing characters


(There's a few others.  That's the ones I use, plus \W since it's of 
interest.)

Looks like your distro sets...

PS1="\u@\h:\w"

You could replace that with...

PS1="\u@\h:\W"

Or, to get something between the two, keep the first version and just 
set...

PROMPT_DIRTRIM=2

... or whatever.



FWIW, if you'd like something even fancier than mine (which is still 
pretty basic, really, sticking to the originally available prompt-string 
substitutions plus ANSI-color), consider googling...

bash prompt ps1

As with about anything on the net, there's quite a bit of info out there 
to help, free for the googling! =:^)

-- 
Duncan - List replies preferred.   No HTML msgs.
"Every nonfree program has a lord, a master --
and if you use the program, he is your master."  Richard Stallman

___________________________________________________
This message is from the kde mailing list.
Account management:  https://mail.kde.org/mailman/listinfo/kde.
Archives: http://lists.kde.org/.
More info: http://www.kde.org/faq.html.




More information about the kde mailing list