bash case-insensitive filename tab-competion
Edit /etc/inputrc:
add this line:
set completion-ignore-case on
shortcuts to find and grep
Writing these 2 line way too much a day.
Edit ~.bashrc:
function gr {
grep -Hrni $1 *
}
function f {
find . -iname *$1* | grep -i $1
}
colorful man pages
Edit ~./Xdefaults:
*VT100*colorULMode: on *VT100*colorUL: yellow !*VT100*italicULMode: on *VT100*underLine: off ! Uncomment this to use color for the bold attribute *VT100*colorBDMode: on *VT100*colorBD: cyan
merge two pdf documents
I had to sign a document, which was basically:
- Print the last, 5th page of the pdf.
- Sign the sheet.
- Scan it as a one-paged pdf.
- Change the 5th page from the pdf with the new one.
Again, the solution was pdfjam, which did the job of merging the first 4 page of the original document with the new pdf.
pdfjam original.pdf '1-4' new.pdf '-' --outfile merged.pdf
I found nice pdfjam examples at the The Bit Brothers.
perl regexp – threat whole string as one line
s - Treat the whole string as one line, so that even /./ will match a "newline" character.
#!/usr/bin/perl
my $multiline =
"In the town where I was born,\n" .
"Lived a man who sailed to sea,\n" .
"And he told us of his life,\n" .
"In the land of submarines.";
if ($multiline =~ /born,.Lived/s) {
print "found\n"; # found in deed
} else {
print "not found\n";
}
xterm colors
The blue is too dark for my eyes, specially then it's used by colorgcc to highlight line numbers.
...and I just can't get angry with a cheerful orange cursorColor
~./Xdefaults:
xterm*foreground: #ffffff xterm*background: #000000 xterm*cursorColor: orange xterm*color4: #526fcf
find and remove files
With rm and find:
rm $(find . -name *.gcda)
Or with the -exec paramter of find
find . -name *.gcda -exec rm -rf {} \;
git tag
Tag commit:
git tag -m <msg> <tagname> <commit>
Push tags (not done by default):
git push --tags <remote> <branch>
Fetch tags:
git fetch --tags <remote> <branch>
or
git remote update <remote>
choose default answers at make oldconfig
Linux command yes outputs parameter string.
yes "" | make oldconfig
Stringizing Operator, Token concatenation
After many years, even C shows new stuff:
Stringizing Operator
#define QUOTEME(x) #x
According to wiki:
Although macro expansion does not occur within a quoted string, the text of the macro arguments can be quoted and treated as a string literal by using the "#" directive (also known as the "Stringizing Operator").
the code
printf("%s\n", QUOTEME(1+2));
will expand to
printf("%s\n", "1+2");
Token concatenation
Token concatenation, also called token pasting, is one of the most subtle — and easy to abuse — features of the C macro preprocessor. Two arguments can be 'glued' together using ## preprocessor operator; this allows two tokens to be concatenated in the preprocessed code. This can be used to construct elaborate macros which act like a crude version of C++ templates.
For instance:
#define MYCASE(item,id) \ case id: \ item##_##id = id;\ break
the code
MYCASE(widget,23);
will expand to
widget_23 = 23;