Blog is moving

My blog is moving to http://victormendonca.com/blog/. If you are looking for a specific or older post you are in the right place Otherwise check out my new page for more up to date content.

Saturday, April 4, 2009

How to use script highlight on 'less' (vim)


The title might be a bit misleading. As far as I know 'less' does not support script highlight (please correct me if I'm wrong). However I did find out that vim has a built-in script that allows you to use it as less.

So here's a very simple solution, add an alias to your ~/.bashrc pointing the vim script:

alias lessv='/usr/share/vim/vim71/macros/less.sh'

You can see from the screenshot bellow that the file is open as read-only and not modifications are allowed. Some of 'less' commands (like “q” to quit) are also replicated.



Friday, April 3, 2009

How to display variables without case sensitivity


This is the second of many shell (bash) tips that I'll be posting here. This little script will allow you to display the value of variables without having case sensitiveness or having to enter the “$” before the variable name.

Here's what displaying a variable without the script looks like:

$ echo $PATH
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

And here after the script:

$ var path
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

$ var PATH
/home/victor/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games

You can see that both ways will work (as long as the variable does not have the same name in lower and capital case).

And here's the script, which can also be added to ~/.bashrc

var ()
{
_var="$1";
if [ -n "${!_var}" ]; then
echo ${!_var};
else
_var=$(echo "$_var" | tr 'a-z' 'A-Z');
echo ${!_var};
fi
}