#include #include #include #include #include #include #define MAXPATH 2048 #define MAXHOME 256 #define MAXUSER 64 #define MAXHOST 64 #define MAXTRENNER 64 #define VERSION "0.2" #define CMDLINE "c:C:nufbi~+:-:ot:T:hH" int main(int argc, char *argv[]) { char PATH[MAXPATH+1]; char TMPPATH[MAXPATH+1]; char HOME[MAXHOME+1]; char USER[MAXUSER+1]; char HOST[MAXHOST+1]; char TRENN[MAXTRENNER+1]; char INVERS[]="\\033[7m"; char BOLD[]="\\033[5m"; char *z1,*z2; int i1; int color=34; int backcolor=-1; int full=0; int bold=0; int invers=0; int before=10; int after=20; int tilde=1; int onlypath=0; unsigned char trenner='>'; struct passwd *PASSWD; strcpy(TRENN,"[...]"); PASSWD=getpwuid(getuid()); if(PASSWD==NULL) { printf("ERR: Cannot allocate passwd"); exit(-1); } if(getcwd(PATH,MAXPATH) == NULL) { printf("ERR: PWD failed"); exit(-1); } if(realpath(PATH,TMPPATH)!=NULL) strcpy(PATH,TMPPATH); if(strlen(PASSWD->pw_dir)>MAXHOME) { printf("ERR: HOME too long"); exit(-1); } strcpy(HOME,PASSWD->pw_dir); if(realpath(HOME,TMPPATH)!=NULL) strcpy(HOME,TMPPATH); if(strlen(PASSWD->pw_name)>MAXUSER) { printf("ERR: USERNAME too long"); exit(-1); } strcpy(USER,PASSWD->pw_name); if(gethostname(HOST,MAXHOST) < 0) HOST[0]=(char)NULL; i1=getopt(argc,argv,CMDLINE); while(i1 != -1) { switch(i1) { case 'T': /*separator between path*/ if(strlen(optarg)`\n",argv[0]); printf("Options:\n"); printf("-t \t\tlast char at prompt\n"); printf("-o\t\t\tonly path, you don`t really want this !\n"); printf("-+ \t\tmaximum chars at the beginning of the path\n"); printf("-- \t\tmaximum chars at the end of the path\n"); printf("-c \tColor to user for foreground\n"); printf("-C \tColor to user for background\n"); printf("-n\t\t\tno hostname is shown\n"); printf("-u\t\t\tno user is shown\n"); printf("-f\t\t\tfull path is shown\n"); printf("-b\t\t\tbold fonts\n"); printf("-i\t\t\tinverse fonts\n"); printf("-~\t\t\tno ~-substitution for home\n"); printf("-h\t\t\tguess what !\n"); printf("-T \t\tSeparator when cutting Path\n"); printf("Valid colors are:\n"); printf("none, black, red, green, yellow, blue, magenta, cyan, white,\n"); printf("BLACK, RED, GREEN, YELLOW, BLUE, MAGENTA, CYAN, WHITE\n"); printf("Yes, that are 16+1 colors and yes, it is case sensitive !!!\n"); return(0); break; default: break; } i1=getopt(argc,argv,CMDLINE); } /* create PATH */ if(tilde == 1) { /* ~ instead of $HOME */ z1=PATH; z2=HOME; if(strstr(z1,z2)==z1) { sprintf(PATH,"~%s",z1+strlen(HOME)); } } if(full == 0) { if(strlen(PATH) > before+after) { z1=PATH; z1+=before; z2=PATH+strlen(PATH); z2-=after; sprintf(TMPPATH,"%s%s",TRENN,z2); strcpy(z1,TMPPATH); } } /* Header */ if(!onlypath) { printf("\\["); if(color > 0) printf("\\033[%im",color); if(backcolor > 0) printf("\\033[%im",backcolor); if(bold) printf("%s",BOLD); if(invers) printf("%s",INVERS); printf("\\]"); } /* Body */ if(onlypath) { printf("%s",USER); if((USER[0] != (unsigned char)NULL) & (HOST[0] != (unsigned char)NULL)) printf("@"); printf("%s",HOST); if(HOST[0] != (unsigned char)NULL) printf(":"); } if(onlypath) { printf("%s%c ",PATH,trenner); } else { if(realpath(argv[0],TMPPATH)==NULL) { printf("ERR: Unable to get full path of %s\n",argv[0]); exit(-1); } printf("$(%s -o ",realpath(argv[0],TMPPATH)); for(i1=1; i1 0 | backcolor > 0) printf("\\033[0m"); printf("\\]"); } return(0); }