leo charre


vim unix perl development tips

All my work worth using twice is stored as distros inside our version control repository.
We use cvs. It works really well.

Some of the stuff is stored as reference in case something blows up and we need to know what was there. Such as with crontab files, sometimes they have important details- and if we had to recreate from scratch, we could forget one of those important details.
Config files are good too, httpd conf files.. The occasional log file, although rare.

Some projects can get big. So you separate them into smaller projects/module distros with test suite, documentation- and make the hell sure they work really well by themselves, stand alone.

And then some suff- some of it.. Is really better off with a ton of code. It’s rare that you really have an advantage with this- but it can happen.

In that case, maintenance is real work. But I have learned a few things over the years that have sped up and improved my ability to keep up mountains of code and hundreds of distros.
I will list some of these things here. This article will be in constant update and revision.


Look through a ton of code in your distro and open to the exact place where you find "it" via the command line.

I need to find where Cwd::Ext is in my code to change it.

1) [root@wingnut DMS2]# find ./ | xargs grep -s 'Cwd::Ext'
./lib/DMS/User.pm:use Cwd::Ext;
./lib/DMS/User.pm:   require Cwd::Ext; # read in everything
./lib/DMS/User.pm:   my $d = Cwd::Ext::abs_path_nd($abs) or warn("cant get abs path to [$abs]") and return [];
2) [root@wingnut DMS2]# vim ./lib/DMS/User.pm +/Cwd::Ext

Command 1) searched the current directory for all files, all directories.. everything.. and looks inside for the text 'Cwd::Ext'. The -s is error suppression for grep. For example when you run grep on files with spaces this way- you'll get errors. I don't care about that - I just want to look inside files that I know have no funny chars in the filename. This command is actually two commands. The output of find (find ./) is piped (|) to xargs and grep.
If you didn't use xargs, the output you would be filtering 'Cwd::Ext' from would be the file listing from find. When you pass a file argument instead of a text stream to grep, it looks inside the file. Using xargs will pass every list element as an argument to the next command. On unix, non escaped whitespace is a delimiter, spaces, return character, etc.

Command 2) Is much more interesting. It means to open the file in vim- and the + flag means to run the following command. Just as you would in command: mode inside vim environment. What we are saying in this command, is to open the file and search for string. When the file opens, this will result in the current position to be the first line where the text 'Cwd::Ext' appears.
Very fucking cool. Very fucking convenient.


Setting colors of directory listings in bash terminal

Did you realize you can change the colors of the directory listings? This is more useful than you think- especially when you don't ever 'browse your computer'- because you only use the command line.

You do this by setting the shell environment variable LS_COLOR.

You can see what it's set to now, by using this command:

$ set | grep LS_COLORS

And it's possible there's nothing in there.

My personal LS_COLOR environment variable, I have refined mine to be:

LS_COLORS='no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;35:*.cmd=00;32:*.exe=00;32:*.sh=00;32:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.t=93:*.pm=00;36:*.pod=00;96:*.conf=00;33:*.off=00;9:*.jpg=00;94:*.png=00;94:*.xcf=00;94:*.JPG=00;94:*.gif=00;94:*.pdf=00;91'

This helps me detect some things that are important to me, such as tests.t to stand out from other junk in t/, a different color for pod and pm files.. etc. very cool.

The line is inserted in to you ~/.bashrc as:

export LS_COLORS='no=00:fi=00:di=00;34:ln=00;36:pi=40;33:so=00;35:bd=40;33;01:cd=40;33;01:or=01;05;37;41:mi=01;05;37;41:ex=00;35:*.cmd=00;32:*.exe=00;32:*.sh=00;32:*.gz=00;31:*.bz2=00;31:*.bz=00;31:*.tz=00;31:*.rpm=00;31:*.cpio=00;31:*.t=93:*.pm=00;36:*.pod=00;96:*.conf=00;33:*.off=00;9:*.jpg=00;94:*.png=00;94:*.xcf=00;94:*.JPG=00;94:*.gif=00;94:*.pdf=00;91'

The string is really a list, the delimiter is the colon, and semicolon allows you to set multiple codes for each item. The items are patterns just as you would use on the cli, but there are some special identifiers, such as 'ex' (marked executable) and 'ln' (for link)..

I've written a much more involved example and tutorial on setting LS_COLORS colors of directory listings in bash terminal. It also contains the codes for the colors, etc.


useful vim commands,vim cheatsheet

copy lines, multiple commands
For the longest time I wanted to know how to copy lines 145 through 148 to line 180..
:145,148y | 180pu
What we need to be able to do is issue more than one command in : mode. The delimiter is not ':' , or ';' but the pipe! Sheesh..
Test your perl before saving..
:!perl -c %
Insert shell output..
I have dev scripts that do things like examine code an create pod for it to stdout. What's cool is I can paste the pod for the file I am editing at the moment with:
!!pmpod %s

Leave a Reply


Linux User