Skip to content

Instantly share code, notes, and snippets.

@TrilbyWhite
Created March 6, 2016 14:19
Show Gist options
  • Save TrilbyWhite/fa56b86a66697755233a to your computer and use it in GitHub Desktop.
Save TrilbyWhite/fa56b86a66697755233a to your computer and use it in GitHub Desktop.
PS1 in C
// compile: gcc -o /somewhere/in/your/path/myprompt thisfile.c
// usage: PS1='$(myprompt $? \h \w)'
#include <stdlib.h>
#include <stdio.h>
#include <unistd.h>
void cprint(int col, const char *str) { printf("\001\033[%dm\002%s", col, str); }
int main(int argc, const char **argv) {
int uid = (getuid() ? 32 : 31);
int err = (argv[1][0] == '0' ? 32 : 31);
cprint(37, "\342\224\214\342\224\200[");
cprint(uid, argv[2]);
cprint(37, "]\342\224\200[");
cprint(err, argv[3]);
cprint(37, "]\n\342\224\224\342\224\200\342\224\200\342\225\274");
cprint(0, " ");
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment