A piggy bank of commands, fixes, succinct reviews, some mini articles and technical opinions from a (mostly) Perl developer.

Jump to

Quick reference

Showing posts with label terminal. Show all posts
Showing posts with label terminal. Show all posts

URLs open in Safari instead of Chrome from Mac OSX Terminal

To set the correct default browser on OSX, go to System preferences | General | Default web browser.

If the default browser is correct but Terminal is still not behaving correctly, then change the default browser, and change it back again.

TIOA-TIOA FTW

(source)

Don't grep, but filter terminal output and colour certain lines (and print all other lines too)

Ruby:

acoc source with dependency of term-ansicolor gem.

Perl:

tail -f /some/log | perl -MTerm::ANSIColor -ne'print color("red") if /error/i; print $_; print color("reset");'

or

tail -f /some/log | perl -MTerm::ANSIColor -pne's/foo/color("cyan")."foo".color("reset")/e;'

or

tail -f /some/log | perl -MTerm::ANSIColor -pne's/(error|bar)/color("green").$1.color("reset")/eig;'

Bash:

Emacs font-lock-keywords can easily be implemented in a 3 line bash script. Call it "highlight":

    # Usage: tail -f error.log | highlight "error"
    RED="$(tput setaf 1)"
    RESET="$(tput setaf 7)"
    sed "s/$1/$RED$1$RESET/"

Terminal does not wrap properly in linux

Sometimes lines don't wrap correctly in a bash terminal in linux - long lines overlap and overwrite the beginning of the line instead of continuing onto the next line.

To fix it:
shopt -s checkwinsize

To check it:
shopt  | grep checkwinsize
You should see:
checkwinsize    on

If it still isn't working, try:
reset

(source)

Colouring terminal output


Thanks to StackOverflow

UPDATE: You can actually do this yourself with pretty much any programming language that has an ANSI colours library.

Enable scrolling in GNU screen

.screenrc: 
termcapinfo xterm* ti@:te@ 


Text-based web browsers

  • http://w3m.sourceforge.net/
  • http://lynx.browser.org/
  • http://www.jikos.cz/~mikulas/links/

Coloured log output

Tail the log and pipe it through this:

#!/usr/bin/perl

use warnings;
use strict;
use Term::ANSIColor qw(color);

while( <> ) {
chomp;
s/\t/ /g;
(/ERROR|failed/) && do {
print( color( 'red' ). $_ .color( 'reset' )."\n" );
next;
};
(/WARN/) && do {
print( color( 'magenta' ). $_ .color( 'reset' )."\n" );
next;
};
(/succeeded/) && do {
print( color( 'green' ). $_ .color( 'reset' )."\n" );
next;
};
(/INFO/) && do {
print( color( 'yellow' ). $_ .color( 'reset' )."\n" );
next;
};
(/DEBUG/) && do {
print( color( 'blue' ). $_ .color( 'reset' )."\n" );
next;
};
print $_."\n";
}