lilalo

view l3prompt.c @ 157:137cf5a580be

bsd fix
author Igor Chubin <igor@chub.in>
date Mon Nov 28 13:26:46 2011 +0200 (2011-11-28)
parents
children
line source
2 /*
3 * export PS1='\[$($L3_HOME/l3prompt "v3#\!#$?#$UID#$$#$(/bin/date +%s)#$PWD#$RANDOM#")$(l3_save_last_line >& /dev/null)\]'$PS1
4 *
5 *
6 * l3prompt perl code:
7 *
8 * my $string=$ARGV[0];
9 * my $insert="\e[1K\e[10D";
10 * my $max=5;
11 *
12 * while (length($string) > $max) {
13 * $res .= substr($string, 0, $max).$insert;
14 * $string = substr($string, $max);
15 * }
16 * $res .= $string.$insert;
17 * print "$res";
18 *
19 */
20 #include <stdio.h>
21 #define N 5
22 #define BUF_SIZE N+1
23 char* mixin="\e[1K\e[10D";
24 char buf[BUF_SIZE];
25 int main(int argc, char **argv)
26 {
27 char *i,*j;
28 int n;
29 argc--;
30 argv++;
31 while (argc > 0) {
32 i=argv[0];
33 j=&buf[0];
34 n=0;
35 while(*i) {
36 *j=*i;i++;j++;
37 n++;
38 if (n==N) {
39 *j=0;
40 fputs(buf, stdout);
41 fputs(mixin,stdout);
42 j=&buf[0];
43 n=0;
44 }
45 }
46 *j=*i;
47 fputs (buf, stdout);
48 if (n) fputs(mixin,stdout);
49 argc--;
50 argv++;
51 };
52 }