Since we don't display the untracked files in the git repo info, we can
simply omit them from the git-status output. This makes it considerably
faster (about 5x - ~300ms to ~60ms - in my void-packages checkout) for
no loss of functionality.
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.
Use fwrite() directly instead of p(), since we know the string size.
Foreground color values from table in [1].
Also add NOCOLOR option in Makefile to completely disable color support.
[1] https://en.wikipedia.org/wiki/ANSI_escape_code#3-bit_and_4-bit
Instead of paying for multiple function calls and any string parsing at
all, use a fast integer that can fit at least two chars inside and
compare them directly.
We also move the struct and enum declarations into the only function
that uses them.
Also make the .s buffer for the resulting string smaller. It doesn't
need 64 chars.
calloc should receive the size of the variable mask points to, not the
size of the pointer itself. Could have lead to memory corruption in
32-bit platforms.
This is likely a standards bug and getenv should be re-entrant (it
should, after all, also be threadsafe if no one is writing to the
environment), but it didn't cost much to work around it.
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.
get_current_dir_name will use the value of PWD if it matches the current
directory, which allows us to show the current directory using the path
the shell's prompt would show (the shell exports PWD to the process).
Also re-organize the function, fixing the lack of path shortening in
paths outside HOME - fish_style_dir was being applied only for paths
under HOME.
Member launched of struct threaded_task should be accessed after some
sort of synchronization happens (what we currently do is join the thread
that touches the struct), so it doesn't need to be an atomic variable.