Updates from May, 2011 Toggle Comment Threads | Keyboard Shortcuts

  • tech0x20 2:51 pm on May 10, 2011 Permalink | Reply
    Tags: bash, korn shell, ksh, ps1   

    Using Escape Codes and Setting Window Title on PS1 for ksh (Korn Shell) 

    I set up the following in my ~/.profile for my ksh login:

    export HOST=$(hostname)
    
    export PS1=$(perl -e 'printf "33]0;${USER}@${HOST}:${PWD}07$"')

    Unfortunately, ksh doesn’t understand escape codes, so perl or awk is necessary to pull this off–or you can enter them literally via your editor. I like the perl route just for ease of maintenance.

    This was inspired by: Setting window title via escape sequences. Of course, the bash version is *much* simpler:

    export PS1="e]2;${USER}@${HOSTNAME}: ${PWD}a"

    Other links of interest:

     
  • tech0x20 3:53 pm on March 21, 2011 Permalink | Reply
    Tags: , , ,   

    Date formatting for Single Unix Specification(R) versions of “date” 

    The date command is wonderful for formatting dates, as such

    date --date="2010-01-01" +%Y%j

    But what happens when you’re on a system whose date command only supports the -u [UTC] and + [for formatting] options?

    Below is a quick hack in straight C that provides the ability to format a date that you provide. This is ideal if your unix install of perl is very basic or non-existent, but you still have access to the C compiler.

    Compiling the target would go as follows:

    gcc strptime.c -o strptime

    Running the output would be as follows:

    ./strptime "2010-01-01" "%Y%j"

    strptime.c source code–Please note: there is limited error checking for the wrong arguments, etc., and overlapping a built-in name such as strptime() isn’t the best of practices…

    #include 
    #include 
    
    int main(int argc, char *argv[]) {
        struct tm tm;
        time_t t;
        char string[255];
    
        if(strptime(argv[1], "%Y-%m-%d", &tm) == NULL) {
            if (strptime(argv[1], "%m/%d/%Y", &tm) == NULL ) {
                fprintf(stderr, "format errorn");
                return 1;
            }
        }
        strftime(string, sizeof(string) - 1, argv[2], &tm);
        printf("%s",string);
        return 0;
    }
    
     
  • tech0x20 9:27 am on January 19, 2011 Permalink | Reply
    Tags: bookmarklets, ,   

    Perl Documentation Bookmarklets 

    Below are some bookmarklets to quick link to CPAN documentation… Click and drag the links to your bookmark bar or use the included source code to create the bookmarklets.

    They will generate a prompt something like this when clicked:

    Bookmarklet to search for a keyword in CPAN documentation: Search CPAN

    Source:

    javascript:{x=prompt("Search%20for%20module");window.location='http://search.cpan.org/search?mode=module;query='+x;}

    Bookmarklet to bring up specific module page [case-sensitive, e.g., GetOpt::Long]: CPAN Page

    Source:

    javascript:{x=prompt("Enter%20Perldoc%20keyword");window.location='http://search.cpan.org/perldoc/'+x;}

    Inspired by

     
c
Compose new post
j
Next post/Next comment
k
Previous post/Previous comment
r
Reply
e
Edit
o
Show/Hide comments
t
Go to top
l
Go to login
h
Show/Hide help
shift + esc
Cancel
%d bloggers like this: