The trouble with bash colored prompts munging your control-r bash history searches

Basically, you just want to be very careful properly escaping and ending color sequences in your bash prompt.  If you mess them up, when you try to use spiffy bash tricks that alter the text on your current input line, such as control-r to search through your bash history and then left of right arrow to edit that line, you'll get a partially overwritten line that is impossible to read or edit properly.

Filed under  //   bash   tech  

Comments [0]

My Favorite bash Tips and Tricks

which produces the same result. However, brace expansion becomes quite useful when the brace-enclosed list occurs immediately before, after or inside another string:

$ echo {one,two,red,blue}fish
onefish twofish redfish bluefish

$ echo fish{one,two,red,blue}
fishone fishtwo fishred fishblue

$ echo fi{one,two,red,blue}sh
fionesh fitwosh firedsh fibluesh

Notice that there are no spaces inside the brackets or between the brackets and the adjoining strings. If you include spaces, it breaks things:

$ echo {one, two, red, blue }fish
{one, two, red, blue }fish

$ echo "{one,two,red,blue} fish"
{one,two,red,blue} fish

However, you can use spaces if they're enclosed in quotes outside the braces or within an item in the comma-separated list:

$ echo {"one ","two ","red ","blue "}fish
one fish two fish red fish blue fish

$ echo {one,two,red,blue}" fish"
one fish two fish red fish blue fish

You also can nest braces, but you must use some caution here too:

$ echo {{1,2,3},1,2,3}
1 2 3 1 2 3

$ echo {{1,2,3}1,2,3}
11 21 31 2 3

Now, after all these examples, you might be thinking to yourself, “Gee, those are great parlor tricks, but why should I care about brace expansion?”

Brace expansion becomes useful when you need to make a backup of a file. This is why it's my favorite shell trick. I use it almost every day when I need to make a backup of a config file before changing it. For example, if I'm making a change to my Apache configuration, I can do the following and save some typing:

$ cp /etc/httpd/conf/httpd.conf{,.bak}

Notice that there is no character between the opening brace and the first comma. It's perfectly acceptable to do this and is useful when adding characters to an existing filename or when one argument is a substring of the other. Then, if I need to see what changes I made later in the day, I use the diff command and reverse the order of the strings inside the braces:

$ diff /etc/httpd/conf/httpd.conf{.bak,}
1050a1051
> # I added this comment earlier

Brace expansion is pretty cool when used as pseudo-globbing.

Filed under  //   bash   tech   unix  

Comments [2]

bash command completion for rake

http://oldblog.timocracy.com/2007/10/09/bash-command-completion-for-rake

An imported post from my old blog. Hopefully the title is self-explantory.

Filed under  //   bash   rake   ruby   tech  

Comments [0]

Alpha of subversion URL tab completion

http://oldblog.timocracy.com/2007/03/23/alpha-of-subversion-url-tab-completion

An imported post from my old blog. Hopefully the title is self-explantory.

Filed under  //   bash   scm   svn   tech  

Comments [0]

Filed under  //   bash   tech  

Comments [0]

Superior bash tab completion in OS X

http://oldblog.timocracy.com/2007/03/22/superior-bash-tab-completion-in-os-x

An imported post from my old blog. Hopefully the title is self-explantory.

Filed under  //   apple   bash   osx   tech  

Comments [0]