Category
shell
-
07.08.11Script for making an ordered list of filesYou've got a bunch of files you want to reorder (that is rename so that they appear in a specific order) but do not want to really rename them (their original names are relevant). You may want to create a set of links to each of them with the appropriate '001', '002' term before. Here is a script for doing exactly this. Use as follows (if named 'mapnames.sh'): $ mapnames.sh digits file1 [file2 file3 ...] will use digits digits for the leading numeral (adding '0' before) and will link the files in the given order. Here is the code: #!/bin/sh length=$1 shift count=1 for name in $@ do ...
-
04.08.11Screenshots from the command line (FreeBSD)vidcontrol is a nice utility that among other things allows one to capture the state of a video buffer and dump it to a file. The format of this file is specified in the man page as it is not a regular image file. For this reason one needs a specific tool to convert it to something one can play with. These commands are scr2txt (/usr/ports/textproc/scr2txt) and scr2png (/usr/ports/graphics/scr2png). They can then be combined using one single line: $ vidcontrol -p < /dev/ttyv0 | scr2txt > /tmp/screenshot.txt The -p flag instructs vidcontrol to get the current content of the corresponding video buffer. ...
-
02.22.11Learning to write (GNU) makefilesI am a Mathematician and usually write more LaTeX than C but programming has been an active hobby since I owned my first Spectrum back in the eighties. What I am commenting in this post has been plaguing me for years and I have just learnt it (from laziness, no more): using pattern rules in makefiles. Caveat: I do not know whether this works for non-GNU Makes or not. I had already read a lot of pro makefiles, which contained endless funny codes like $@, $%, $< etc. Today I have learnt the meaning of some of these. I am supervising a ...
-
02.18.11Moving between encodings with emacsI live in Spain. I work at Academia. This is a problem. My School's computers are plagued with Windows (XP!), my pupils most certainly use Windows (I bet it is 7) and I use (obviously) an MBPro with Snow Leopard. Even more, my School's servers are Linux. This gives rise to latin-1, UTF-8 collisions. While writing some text-only documents for use with MATLAB (another problem, by the way) I realized I was going to need to convert them from my Mac's UTF-8 to Windows latin-1 every time I edited them. Time for a makefile. I am not commenting this though, only the ...
-
02.15.11find command in PowershellIn my actual job I have a laptop with Windows 7 installed on it. The last time I used Windows on a daily basis was four years ago and it was Windows XP. The terminal (cmd.exe) was... well, that was not a real terminal neither a real shell. The first days using Windows 7 I had a problem (which I will explain it later) and while I was installing cygwin to run some commands I found Powershell. I have to admit that Windows now has a real shell and it seems pretty powerful. It can be installed in Windows XP and ...
-
02.04.11Easy svn blame vim mappingThe other day, this colleague of mine asked me how he could use svn blame on the same file he was editing without leaving his vim session. This is a mapping I wrote for that purpose. :map <F3> :sp %.tmp_svnblame \| :r! svn blame $(basename % .tmp_svnblame)<CR> Enjoy!
-
12.21.10Limiting resources with limits (1)limits is a FreeBSD's base system utility for displaying and setting system resources limits. To some extent it is equivalent to the limit and ulimit commands. It can set limits for filesize, coredumpsize, maxproc, memoryuse and other parameters. Convenience modifiers like k, m or g for kilobytes, megabytes and gigabytes or s, m, h for seconds, minutes and hours can be used in all cases. limits can be used to achieve three different goals: Set resource limits. For example: $ limits -t 1s ls -R / launches the ls -R command with a cputime limit of 1 second. In general, this is the ...
-
10.23.10Vim. MacrosYou have probably seen something like this in other editors. Macros (or "complex repetitions" as Vim's help puts it) is a way to repeat complex commands sequences. In order to get the most out of this feature, you need to master movement and insertion commands. The work cycle is the following: start recording, execute commands, stop recording. Then, you are ready to execute the whole sequence of commands you have recorded. Let us see this in more detail. To start recording, we use the "q" command followed by a register name in which the sequence of commands will be stored. qa At that ...
-
09.04.10Vim. Key mappingMaps are a way to create an association between a set of key strokes and a set of actions. They are really powerful. However, in this post, I will not explain them in the deepest detail. If you need further information, you will need a good Vim manual. As it happens with abbreviations, maps can be used regardless of the mode you are in Vim or they can be restricted to a certain operation mode. They work the same way in every mode. Type :help :map to know which map commands work in which mode. First off, :map ... ... <Esc>OM <CR> <Esc>Ol ...
-
07.30.10Vim. Saving keystrokes: abbreviationsWelcome to a new issue of this short Vim tutorial! As we saw in previous posts, Vim is the perfect tool if you want to save time in your daily work. It helps you in the write-compile-debug cycle, it indents and autoindents code, it is extremely powerful for searching, replacing and many other frequent tasks. In this post I will introduce an interesting feature meant to make you type less: abbreviations. Abbreviations are, as their name indicates, a way to create an association between a short set of characters and a piece of text (or a command). Abbreviations can be used in insert, replace ...