Posts Tagged ‘linux’

It has been a while since I played with Archlinux. Meanwhile AUR has transitioned and now uses version controlled PKGBUILDs. So here is how to go about it.

Let us take the example of the package cower.

If you visit that page you will find a “Download snapshot” link under the Package Actions box to the right of the page near the top of the page. Just click on it and you will download a compressed tarball; cower.tar.gz in this case. Uncompress that to find the actual PKGBUILD in it. I also noticed a hidden file called .SRCINFO in the same folder. Now you can simply issue the command “makepkg -irs” in the same directory and you are all set.

The other way is to git clone the repo. The repo link is right at the top of the page under Git Clone URL. If you clone the repo you will find the PKGBUILD and .SRCINFO and .git directory in there. Again use “makepkg -irs” to install the package.

Read Full Post »

i like to sort my vifm buffers by modification time but don’t like the fact that all the directories are grouped first and then the files next. i wanted to sort the buffer so that there is no distinction between directories and files when sorting by modification time. here is how you can achieve it.

issue the colon(:) to access the vifm command prompt

then issue the following command

set sort=mtime,dir

mtime is for modification time and dir for directories.

i have mapped that to the leader key+s combo in vifmrc file thusly

nmap ,s :set sort=mtime,dir<cr>

Read Full Post »

on archlinux with openbox window manager and no desktop environment

Linux  3.11.1-1-ARCH #1 SMP PREEMPT Sat Sep 14 20:31:35 CEST 2013 i686 GNU/Linux

vifm 0.7.5-1

ncurses 5.9-5

gtk2 2.24.20-1

xterm 297-1

rxvt-unicode 9.18-7

tmux 1.8-1

vifm crashes on launch from the terminal with the following message:

vifm: color_manager.c:47: colmgr_init: Assertion `(color_pair_map != ((void *)0) || avail_pairs == 0) && “Not enough memory.”‘ failed. Aborted (core dumped)

turns out that the crash is being caused by the TERM environment variable being set to xterm-256color or screen-256color in xterm or xterm/tmux combo. in rxvt-unicode the TERM was set to rxvt-unicode-256color. setting TERM to xterm or screen is not causing any crash.

i have been bugged by this for some time now but only found out the reason today.

Read Full Post »

can’t select text with mouse.

problem at hand: how do i use the mouse to copy/paste text in xterm running tmux on PC? normally you should not have problems selecting text and pasting it with your mouse. everybody knows about left clicking and then dragging to select and copy the text. in order to paste you need to middle click your mouse. however there are certain options which if set will prevent this functionality. if you have set the following options

  • mouse-select-pane
  • mouse-select-window

you will notice that you are not able to select text at all.

the solution is to use the shift key.

hold down the shift key and then left click and drag across the target text. if you want to now paste the selected text back in to xterm, you must also hold down the shift key and then middle click in order to paste the text. this is not mentioned in the tmux man pages so i do not think this is a tmux feature. guess this has something to do with xterm, but i m not sure.

xterm version 278-1

tmux version 1.6-2

archlinux PC

guly in the comments informs me that iterm users on macosx need to use the option key. bruceedge pointed out that if the target text area resides in a pane of a split window then trying to copy with this method will also copy stuff from adjacent panes. to counter this problem one hack is to use the zoom pane functionality. say you want select text from a pane that resides in a split window with other panes. with keyboard focus on the target pane, you simply hit prefix + z to maximize this pane to the entire window. copy what ever it is you want to copy and then hit prefix + z again to toggle back to the previous state.

Read Full Post »

bash has a great feature called dynamic-complete-history that will allow you to complete text at point with contents from your bash history list.

examine the following workflow :

$ touch file1.txt file-with-a-long-name.txt file3.txt
$ some commands
$ some more commands
$ change directory
$ touch file…

at this point you want to type touch file-with-a-long-name.txt to create another file with the same name in the new directory. would it not be great if i could hit a few characters and then magically complete the name just like hitting TAB in bash completes filenames. yes you can using the bash feature dynamic-complete-history.

just write

$ touch file

and then hit C-M-i (Ctrl+Alt+i) and bash will try to complete the the file name by scanning through the history list. if there are multiple matches then it will display all matching items. enter some more characters until u get a unique match and then hit C-M-i.

the gist of the matter is that if you have already typed some thing and it is in the history list then you can insert it at point with ease. this saves typing which is a good thing.

at first i wrongly assumed that this feature was provided by the gnu readline library but on examining the man page of readline i could not find the corresponding documentation. it turns out that this is a feature provided by bash. on reading the man page of bash i found that it is bound to the key M-TAB but on gnome3 M-TAB is the task switcher i.e. it cycles between open applications. fortunately the magic key chord “\M-\C-i” (Alt+Ctrl+i) is also bound to dynamic-complete-history. this i found out by examining the output of bind -p. i have no idea where this binding is defined

to learn more about bind try

$ help bind

yes that is a help not man

bash version i tested this on is GNU bash, version 4.2.24(2)-release (i686-pc-linux-gnu)

the M in the key chord is the Meta key which is the Alt key on my keyboard.

point basically means where your cursor is at.

bash history list is not the same as ~/.bash_history

Read Full Post »

there have been some situations where i needed a custom grid on a 2-dimensional plot in gnuplot instead of a regularly placed grid. in order for me to set up a customized grid i have to first set up a customised xtics and/or ytics. gnuplot does provide a way of providing user preferred tics by manually typing them in at the gnuplot command prompt:

gnuplot> set xtics (1,2,3,4)

however that might get too tiresome for your digits. naturally one would want to employ the powerful text processors and stream editors that GNU/Linux provides. this is how i went about it:

assume that the data file(data.out, say) is as follows:

# some comments and blank lines

#      #x1	#x2 	  #x3

1      1.1	3.9	  4.5
2      2.7	6.1	  5.6
3      3.9	2.3	  3.4
4      3.5	4.3	  34.0
5      12.1	3.4	  15.9

i want to set the xtics to the values in column 2 and ytics to the values in column 3 say. first i conjure up the following shell script (ttf.sh, say):

#!/usr/bin/env bash

# set tic levels from file at the gnuplot prompt
# examples:
# gnuplot> `./tff.sh data.dat 1 xtics`
# gnuplot> `./tff.sh data.dat 2 ytics`

# dataFile from which tic levels will be read

# which column to use

# xtics OR ytics 

sed -e '/^#/d' $dataFile | \
    sed -e '/^$/d' | \
    cut -f $column | \
    tr '\n' ',' | \
    sed -e "s/^/set $whichTics (/" | \
    sed -e 's/,$/)\n/'

and then in gnuplot carry out the following sequence of commands:

gnuplot> `./tff.sh data.out 2 xtics`
gnuplot> `./tff.sh data.out 3 ytics`
gnuplot> plot 'data.out' u 1:2 w p pt 13 ps 2

to produce the following plot:

it should be noted that some of the grid lines are hidden due to alignment with borders.

the shell script needs 3 inputs

  1. datafile name
  2. which column to pull from the datafile
  3. which tics to set the values to

then the whole command is sandwiched between couple of backtics which bring in the command substitution magic. one could very well do the following in bash:

$ ./tff.sh data.out 2 xtics > tmp

and then in gnuplot

gnuplot> load 'tmp'

but i prefer the backtics.

now the explanation of the wonderful sed magic. first we do a little bit of file cleaning/processing like removing comments and blank lines. these operations may not necessarily apply to your case or might need additional operations which is not that difficult a job. anyways on to the explanations now…

sed -e '/^#/d' $dataFile

simply deletes all lines starting with the # symbol. of course if the comment character is different one should change the code appropriately. ^ stands for the beginning of all lines and ^# means all lines starting with a # symbol. the `d’ command instructs sed to delete those lines. we then pipe (|) the output of this command to the next command

sed -e '/^$/d' 

which simply deletes all blank lines. since ^ represents the beginning of all lines and $ represents the end of all lines, ^$ then represents those lines with nothing in between ^ and $ i.e. blank lines. as always the `d’ command instructs sed to delete this line.

cut -f $column

next we cut out the required column from the datafile using the cut command. we assume here that the field separater is a TAB character. if some other field separater is being used that can be specified with the -d switch. do a `man cut` to find out more. now comes the all important part of the entire exercise, what we want is to transform the vertical stack of values:


to a horizontal comma separated list of values:


notice the comma after 3.
we achieve this by using the tr command which we instruct to transform all the newline characters (`\n’) to the comma character (`,’). we do pick up an unwanted comma at the very end of the list which we get rid of and transformed to a right bracket ) like so:

sed -e 's/,$/)\n/'

this time we are using the subsitute command `s’ and asking sed to replace the last comma by a ). as you already know $ represents the end of the line so (,$) represents the last comma we substitute those with a right bracket ) and a newline character `\n’.
of course we had to prepend the “set xtics (” to the beginning of the list and that bit is done by the following:

sed -e "s/^/set $whichTics (/"

notice the double quotes instead of the single quotes. we use double quotes so that $whichTics is automatically expanded to the user supplied tics name.

Read Full Post »

let me first describe the problem that way annoying me for a long long long time.

i use tmux and do my compiling and coding in one window and then many a times i need to open a new window to do some other stuff. the problem i face is that the bash commands that i write in one window are not present in the new window’s bash history.

for example note a typical annoyance

cd code/genetic/convergence/zdt1/population100/

do some work and then create a new window in tmux (C-b c) in order to do some work in the same directory.

and now most probably you will be placed in your home folder if that is where you started tmux initially.  so now in the new window i have to do this long change directory command.  the long cd command will not be written to bash history unless the shell exits.

this was a major annoyance to me for a long time. i wanted all the bash sessions to share the history concurrently.  i found a hack which lets me do what i want.

put the following in your .bashrc

shopt -s histappend

If the histappend shell option is enabled the lines are appended to the history file, otherwise the history file is overwritten. to find out more about histappend just do a man bash and search for histappend.

the history command we refer to here is the bash built-in history command to know more about it do a

help history

yes that is help history **not** man history

if i have understood it correctly i guess the cleverness of the hack is in automatically doing a “history -a” after each command and what better way than to modify the PROMPT_COMMAND which defines how the prompt should be constructed each time. sweet 🙂

Read Full Post »

copy paste in tmux

i m assuming that the tmux prefix is Control+b and that you have emacs style key bindings on

1) enter copy mode using Control+b [
2) navigate to beginning of text, you want to select and hit Control+Space
3) move around using arrow keys to select region
4) when you reach end of region simply hit Alt+w to copy the region
5) now Control+b ] will paste the selection

you can navigate the text using the emacs style navigation key
Control+p, Control+n, Control+f, Control+b etc.

Dan in the comments informs me that if you have vi style key bindings on then the following applies:

1) enter copy mode using Control+b [
2) navigate to beginning of text, you want to select and hit Space
3) move around using arrow keys to select region
4) when you reach end of region simply hit Enter to copy the region
5) now Control+b ] will paste the selection

To enable vi like cursor movement in copy mode put the following in your ~/.tmux.conf:

set-window-option -g mode-keys vi

more over what ever you copy, you may dump that out in your terminal using

tmux show-buffer

and even save to a file(say, foo.txt) using

tmux save-buffer foo.txt

To see all the paste buffers try Control + b #. To dump out the varios buffers on to the terminal or file you may use

tmux list-buffers
tmux show-buffer -b n
tmux save-buffer -b n foo.txt

where n is the index of the paste buffer.

Read Full Post »

in a typical c++ file i have many functions and many a times i needed to search a keyword/variable or carry out a search and replace operation … however it becomes very confusing if multiple functions exist that use the same variable names.

often times i keep hitting C-s and i never can know if i m still within the function i started in or ventured in to a different function altogether … this is more confusing since i use long functions spanning many screenfuls of code 😦

a good thing that i discovered is which-function-mode that i talked about here … which can be helpful but one has to always keep a watch on the modeline …

but i wanted to confine the search or  search and replace within the scope of a function definition … turns out the all powerful emacs can do that and it does it well i think 🙂

first …

emacs has the ability to make every thing else invisible … everything else but your region of interest … the stuff won’t disappear it will simply be not visible… of course u can make it visible again at the click of a few key chords … here is how you do it

first select the region of interest if you simply want to select the entire function simply hit the following keychord within the body of function definition


then to make everything else disappear hit the following

C-x n n

you might have to first all the usage of this if you haven’t used this before.. apparently it confuses some beginners so they disable it by default and warn u on its first use.  onwards now …

now that everything else has become invisible… the search and replace commands miraculously behave as if the other stuff does not exist … buffer movement keys also behave as if the selected region alone exists in the buffer … lucky for us this is precisely what we wanted … after you are done with search and or replace simply hit the following key chord

C-x n w

and everything else will come back !!!

of course its not limited to c++ files alone


Read Full Post »

remap Caps Lock key to Control key

i finally took the plunge. all emacs gurus advocate that the caps lock key should be remapped to be a control key. i have been defferring that for some time now but today i finally took the plunge when i had to hit C-u M-. several times in conjunction with source code browsing using etags. its hard to rewire the brain and its tough to fight the muscle memory. anyways

setxkbmap -option ctrl:swapcaps



update :: 18april2010
on arch linux i wanted to do the same so i put the following in my .bashrc

setxkbmap -option ctrl:nocaps

this just makes the caps lock key in to another control key rather than swapping it.

Read Full Post »