25 09 | 2011

Increase your productivity with two spaces

Written by Tanguy

Classified in : Homepage, Debian, Command line

Shell prompts are often designed to provide a reminder of useful context information such user name, host and current directory:

PS1="\u@\h:\w\$"
tanguy@muscat:~/public_html$

Such a prompt is sufficient to serve its original purpose, but it can be enhances in at least one useful way. Sometimes you have to copy the path of the current directory: with this prompt, it means selecting it by precisely dragging the mouse over it. Well, by adding spaces around the current directory you can become able to select it with a simple double click:

PS1="\u@\h: \w \$"
tanguy@muscat: ~/public_html $

Indeed, with such a prompt, you can now roughly point to the path, double click, and let your terminal emulator's word detection feature select the whole path for you. This simple modification may save you several tenths of seconds!

10 comments

sunday 25 september 2011 à 19:56 ao2 said : #1

This is useful, but word selection delimiters might need to be tweaked depending on the terminal emulator, for xterm I found these instructions:
http://www.jaymzworld.com/wiki/XTerm_double-click_word_selection

For xrvt there is the "cutchars" resource.

Regards,
Antonio

sunday 25 september 2011 à 21:44 Stuart Prescott said : #2

konsole's default word-splitting characters for double click are:

:@-./_~?&=%+#

which already does what you want without padding the prompt out (although you'll notice it doesn't work for your public_html example)

interesting!

sunday 25 september 2011 à 23:17 Anonymous said : #3

Interesting point, but the few times I've needed the current directory, I find it more convenient to just type pwd | xsel. Also, gnome-terminal has the same word-select behavior as Stuart mentioned for konsole.

More frequently, though, I end up just launching whatever program I want to run directly and passing it '.'; I haven't run into a need for copying the current directory very often.

monday 26 september 2011 à 06:28 Alexander E. Patrakov said : #4

This extra space in the prompt is already the default in Gentoo.

PS1='\[\033[01;32m\]\u@\h\[\033[01;34m\] \w \$\[\033[00m\]'

monday 26 september 2011 à 13:46 jhr said : #5

But then, c&p including the host name isn't possible anymore. Well, at least you would have to erase the spaces again if you c&p to an ssh/scp command.

tuesday 27 september 2011 à 15:02 mirabilos said : #6

Your OS is simply broken ☺

The default mksh prompt looks like this:
root@aranym:~/OUT # _

The default uxterm selection stops at the colon.

Note that, on Kubuntu, you need to write
UXTerm*charClass: 33:33,35:35,37:37,38:38,43:43,44:44,45:45,46:46,47:47,58:58,61:61,62:62,63:63,64:64,95:48,126:126
into ~/.Xresources to fix their brain damage and
restore the default uxterm character classes.

tuesday 27 september 2011 à 18:02 -dsr- said : #7

I'm more likely to need a path including username and host (for ssh/scp, as previously mentioned) and so I use this:
\[\033]0;\u@\h:\w\007\]\[\033[1;37m\]\033[1;40m\]\[\033[1D\]\u@\h:\w\n\[\033[0m\]$
which includes a newline rather than a space.

friday 30 september 2011 à 23:26 Axel said : #8

I prefer _not_ to have a space between hostname and path, because then the prompt is also a proper and easy to copy and paste parameter to scp or rsync. :-)

wednesday 05 october 2011 à 10:26 lorexvii said : #9

`pwd`|xsel ?

wednesday 05 october 2011 à 10:27 lorexvii said : #10

emh... pwd|xsel

Write a comment

What is the second letter of the word fbkz? : 

Archives