sophuwu.site > bashprompt
move things into more neat dirs
sophuwu sophie@skisiel.com
Fri, 19 Apr 2024 19:10:58 +0200
commit

8d2601cd5d564c13d378a7130a54b8712c4a9d6d

parent

b2262b8a300f0df10afc5c7d7afc265b3bf3fcaf

5 files changed, 1 insertions(+), 125 deletions(-)

jump to
M MakefileMakefile

@@ -12,44 +12,10 @@ endif

CMAKELISTS = CMakeLists.txt endif -ifeq ($(shell command -v strip), ) -STRIPCMD = echo Strip not found. Binary size may be larger than expected. -else -STRIPCMD = strip --strip-all build/bashprompt -endif -ifeq ($(shell command -v upx), ) -UPXCMD = echo UPX not found. Binary size may be larger than expected. -else -UPXCMD = upx --best build/bashprompt > /dev/null -endif - build: main.cpp $(CMAKELISTS) - @echo Building with $(COMPMSG). - @sleep 2 - @mkdir -p build @$(COMPCMD) - @echo Compiled successfully. - @echo Program is located at build/bashprompt. - @echo "make small" to reduce binary size. Requires strip and/or upx. - @echo "sudo make install" to install the program into /usr/local/bin. - @echo And "make clean" to remove the build directory. clean: build/ @echo Cleaning up. @rm -rf build - @echo Cleaned up successfully. - -small: build/bashprompt - @cp build/bashprompt build/bashprompt.bak - @echo Stripping binary. - @$(STRIPCMD) - @$(UPXCMD) - @echo Old Size: && du -sh build/bashprompt.bak - @echo New size: && du -sh build/bashprompt - - -install: build/bashprompt - @echo Installing to /usr/local/bin. - @sudo cp build/bashprompt /usr/local/bin/bashprompt - @echo Installed successfully. - @echo Run "bashprompt" to use the program. + @echo Cleaned up successfully.
D bashvar

@@ -1,1 +0,0 @@

-PROMPT_COMMAND='` bashprompt ` ; PS1=` bashprompt p ` '
M main.cppsrc/prompt.cpp

@@ -5,9 +5,6 @@ * It can also be used to generate the necessary environment variables

* */ -#include <cstdlib> -#include <string> -#include <ctime> #include <filesystem> #include "rainbow.h"

@@ -86,12 +83,6 @@ printf("%s", outbuff.c_str());

} int main(int argc, char* argv[]) { - /*Bash prompt should: - - show current folder - - count how many commands were executed - - show random emoticon - - display in rainbow colors (choose rainbow length with env variable) - */ if (argc > 1 && argv[1][0]=='h') { printf("To use this program\n");

@@ -118,8 +109,6 @@ exportEnv("RAINBOWPSG", r.c.g);

exportEnv("RAINBOWPSB", r.c.b); printf(" RAINBOWPSC=%d", 1+count); printf("\n"); - - return 0; }
M rainbow.hsrc/rainbow.h

@@ -7,8 +7,6 @@ * License: MIT

*/ #ifndef RAINBOW_H #define RAINBOW_H 1 - -#include <stdio.h> #include <string> void panic(std::string s) {
D test.cpp

@@ -1,76 +0,0 @@

-#include <string> -#include <chrono> -#include <ctime> - -void appendTest(std::string test) { - std::string buff = ""; - for (int j = 0; j < test.length(); j++) { - buff.append("\033[38;2;").append(std::to_string(j)) - .append(";").append(std::to_string(j)) - .append(";").append(std::to_string(j)) - .append("m").append(test.substr(j, 1)) - .append("\033[0m "); - } - buff.append("\n"); - printf("\n"); -} - -void sprintfTest(std::string test) { - char cBuff[40]; - std::string buff = ""; - for (int j = 0; j < test.length(); j++) { - sprintf(cBuff, "\033[38;2;%d;%d;%dm%s\033[0m", j, j, j, test.substr(j, 1).c_str()); - buff.append(cBuff); - cBuff[0] = '\0'; - } - buff.append("\n"); - printf("\n"); -} - -void printfTest(std::string test) { - for (int j = 0; j < test.length(); j++) { - printf("\033[38;2;%d;%d;%dm%s\033[0m", j, j, j, test.substr(j, 1).c_str()); - } - printf("\n"); -} - -struct timetype { - std::chrono::time_point<std::chrono::steady_clock> t; - int ms(); - void get(); - int operator-(timetype& t2) { - return this->ms() - t2.ms(); - } -}; -int timetype::ms() { - return std::chrono::duration_cast<std::chrono::milliseconds>(this->t.time_since_epoch()).count(); -} -void timetype::get() { - this->t = std::chrono::steady_clock::now(); -} - -void resolve(const char* name,timetype& start,timetype& end) { - fprintf(stderr,"%s method: %d ms\n", name, end-start); -} - -int main() { - std::string test = "hello i am a really weird string that is really long and i am just typing random stuff to make it longer"; - timetype t1, t2, t3, t4; - - t1.get(); - for (int i = 0; i < 100000; i++) { - appendTest(test); - } - t2.get(); - for (int i = 0; i < 100000; i++) { - sprintfTest(test); - } - t3.get(); - for (int i = 0; i < 100000; i++) { - printfTest(test); - } - t4.get(); - resolve("append", t1, t2); - resolve("sprintf", t2, t3); - resolve("printf", t3, t4); -}