Commit Graph

21 Commits

Author SHA1 Message Date
Érico Nogueira 8e956a0ded Change prompt character.
It's just more stylish.
2022-08-12 04:37:34 -03:00
Érico Nogueira bd30334277 Manually set thread stack sizes.
8KB was empirically determined to work on musl. We can't go lower (musl
supports up to 2KB) because posix_spawn allocates a temporary stack for
vfork (via clone(2)) on its own stack.

This improves our resource consumption and increases the likeliness for
pthread_create to work even when there isn't a lot of free memory.

Using pthread_setattr_default_np isn't possible, because on musl it
doesn't allow us to go below the default thread stack size. This way is
also more portable.

We don't remove the guard pages entirely, because a shell prompt might
be active in attacker controlled directories, and it's a reasonable
protection against any stack overflow exploits that might appear.
2021-07-17 20:58:16 -03:00
Érico Nogueira 9dc6a30743 Make pthread_create failures non-fatal. 2021-07-17 20:04:15 -03:00
Érico Nogueira 089bb40acc Use color support where appropriate.
Color choice might still be refined, as could support for 8 bit colors.
2021-07-17 19:47:50 -03:00
Érico Nogueira d5a37495b0 Remove outdated comment.
We treat allocation failures correctly: some features are lost, but most
of the prompt is still printed.
2021-07-17 18:46:26 -03:00
Érico Nogueira fe592ae335 Keep special characters in a #define block.
Makes it easy to customize their usage.
2021-07-17 18:23:51 -03:00
Érico Nogueira fbb035e1f9 Fix memory leak in ep.c.
The masks were allocated in the lang scanner function and should be
freed after being read. Add macro to do the whole operation cleanly.
2021-06-23 16:05:22 -03:00
Érico Rolim 46ea87ea21 Fix showing current path again.
Avoid unnecessary heap allocations (though we added new ones in main())
if possible by using a PATH_MAX buffer.

Check for PWD matching current directory ourselves, which allows us to
save a stat syscall, by re-using the stat(".") result to compare to
stat("$HOME"). Improve how we check if HOME is actually part of pwd -
previous would get confused with "${HOME}char", which should not get the
prompt to display '~'.

Use strtok_r to scan characters now. Writing directly to p() makes more
sense than writing chars to a buffer, so remove that.

I'm somewhat unhappy with the rpwd and mrpwd solution, since while
coding I forgot to set one or the other a couple of times. It would be
nice if I could "unconst" the variable at some point, though I greatly
dislike that pattern.
2021-03-07 04:17:23 -03:00
Érico Rolim cd48564223 Remove global variables from git.c.
Use a struct to handle the produced values and pass them around.
Also improve error handling very slightly, and free some memory.
2021-03-07 02:36:13 -03:00
Érico Rolim 89d0c706a6 Show time as 1h31m45s for command duration. 2021-02-23 01:09:41 -03:00
Érico Rolim 815fdf1294 Fix hostname printing.
ssh doesn't set HOSTNAME in env, that has to be determined separately.
What indicates a ssh session are some SSH_* env vars.
2021-02-22 12:34:34 -03:00
Érico Rolim 1f1adc1663 Don't print exit status when it's due to command not found. 2021-02-22 12:24:07 -03:00
Érico Rolim 54c8d17c2b Add support for printing information about previous process. 2021-02-22 05:52:34 -03:00
Érico Rolim 14cb4cbed4 Avoid using any globals in language detection. 2021-02-22 05:00:11 -03:00
Érico Rolim 81c7f243a7 Add framework to display detected programming languages.
Very dumb initial C detection.
2021-02-22 04:43:40 -03:00
Érico Rolim dc4a59881c Enable git status reporting.
Also reorganize git.c to contain most of the implementation details,
main just calls the functions without any arguments.
2021-02-22 02:40:31 -03:00
Érico Rolim fdf2b43b34 Move output and path handling code outside main.
Temporarily add static to translation strings to allow compilation to
work.
2021-02-22 01:53:44 -03:00
Érico Rolim d8b6432c6b Fix git.h, move it to ep.h. 2021-02-22 01:43:22 -03:00
Érico Rolim 3fe513c4c9 Add basic git functionality and error logging. 2021-02-22 01:39:58 -03:00
Érico Rolim c5cb3277a9 Add chroot and job count support. 2021-02-22 01:09:07 -03:00
Érico Rolim e779146066 Initial commit. 2021-02-22 00:38:41 -03:00