From 10345f6e3a25f90030115982a74363063f8b6753 Mon Sep 17 00:00:00 2001 From: Martinez Date: Sat, 26 Dec 2015 16:00:20 +0100 Subject: [PATCH] organize the repo remove unused files create config file update dotfiles update ebuild --- cfg/main.cfg | 13 + data.cpp | 454 ------------------ screeenrc.over => dotfiles/etc/screeenrc.over | 24 +- {etc => dotfiles/etc}/zsh/zprofile | 4 +- {etc => dotfiles/etc}/zsh/zshrc | 32 +- dotfiles/personal/.ssh/config | 54 +++ ebuild/over-prompt-9999.ebuild | 43 ++ render.py => libexec/render.py | 39 +- en_OV => locale/en_OV | 0 over-prompt-9999.ebuild | 44 -- render.cpp | 441 ----------------- zsh-init => share/zsh-init | 5 +- .../256-xterm-colors.py | 0 13 files changed, 178 insertions(+), 975 deletions(-) create mode 100644 cfg/main.cfg delete mode 100755 data.cpp rename screeenrc.over => dotfiles/etc/screeenrc.over (50%) rename {etc => dotfiles/etc}/zsh/zprofile (88%) rename {etc => dotfiles/etc}/zsh/zshrc (76%) create mode 100644 dotfiles/personal/.ssh/config create mode 100644 ebuild/over-prompt-9999.ebuild rename render.py => libexec/render.py (89%) rename en_OV => locale/en_OV (100%) delete mode 100644 over-prompt-9999.ebuild delete mode 100644 render.cpp rename zsh-init => share/zsh-init (59%) rename 256-xterm-colors.py => tools/256-xterm-colors.py (100%) diff --git a/cfg/main.cfg b/cfg/main.cfg new file mode 100644 index 0000000..d27ada6 --- /dev/null +++ b/cfg/main.cfg @@ -0,0 +1,13 @@ +#! /bin/zsh + +# Indicators of system load will turn yellow when system load (loadavg divided by nproc) exceeds this value. +#OVER_PROMPT_SYSLOAD_WARN=1.25 + +# Indicators of system load will turn red when system load (loadavg divided by nproc) exceeds this value. +#OVER_PROMPT_SYSLOAD_YELL=2.50 + +# Indicators of free space (storage, memory and swap) will turn yellow when there's at most this fraction of free space left. +#OVER_PROMPT_FREESPACE_WARN=0.15 + +# Indicators of free space (storage, memory and swap) will turn red when there's at most this fraction of free space left. +#OVER_PROMPT_FREESPACE_YELL=0.05 diff --git a/data.cpp b/data.cpp deleted file mode 100755 index ecca469..0000000 --- a/data.cpp +++ /dev/null @@ -1,454 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -class Space { - public: - Space(const char *name, float available, float total) { - if (strlen(name) > 15) { - strcpy(this->name, "!!!"); - } else { - strcpy(this->name, name); - } - - this->available = available; - - if (total > 0) { - this->percent = available*100 / total; - this->active = true; - } else { - this->percent = 100; - this->active = false; - } - } - - char name[16]; - float available; - float percent; - bool active; -}; - -typedef struct { - float load; - char proc[16]; - unsigned int color; -} Sysload; - -typedef struct { - unsigned short int m1, m2; - bool long_names; -} Config; - -/// Data gatherers -void get_available_space(std::vector &space); -void get_memswap(std::vector &space); -void get_sysload(Sysload &sysload); - -/// Formatting and parsing -void append(char *output, const char *string, int color=-1); -const char *float_to_str(float value, char *output); -int space_to_color(Space &space); -float grepf(const std::string &data, const char *marker); -std::vector read_lines_from_file(std::string filename); -bool column_contains_substr(std::string line, unsigned int column, std::string substr, int position=0); -std::string get_column(std::string line, unsigned int column); -bool str_in_list(std::string str, std::vector list); - -/// Global -std::map color_map; -Config config; -std::vector ignored; - -enum { - COL_GREEN, - COL_DARKGREEN, - COL_YELLOW, - COL_BLUE, - COL_RED, - COL_RFLASH, - COL_CYAN, - COL_NONE -}; - -int main(int argc, char **argv) { - char output[512]; - char tmp[16]; - - std::vector space; - Sysload sysload; - - output[0] = 0; - - color_map[COL_GREEN] = "\e[1;32m"; - color_map[COL_DARKGREEN] = "\e[0;32m"; - color_map[COL_YELLOW] = "\e[1;33m"; - color_map[COL_BLUE] = "\e[1;34m"; - color_map[COL_RED] = "\e[1;31m"; - color_map[COL_RFLASH] = "\e[5;31m"; - color_map[COL_CYAN] = "\e[1;36m"; - color_map[COL_NONE] = "\e[0m"; - - ignored.push_back("rootfs"); - ignored.push_back("proc"); - ignored.push_back("sysfs"); - ignored.push_back("udev"); - ignored.push_back("devpts"); - ignored.push_back("shm"); - ignored.push_back("usbfs"); - ignored.push_back("binfmt_misc"); - ignored.push_back("fusectl"); - - if (argc == 4) { - config.m1 = atoi(argv[1]); - config.m2 = atoi(argv[2]); - if (strcmp(argv[3], "long") == 0) { - config.long_names = true; - } else { - config.long_names = false; - } - } else { - config.m1 = 20; - config.m2 = 10; - config.long_names = false; - } - - get_available_space(space); - get_memswap(space); - get_sysload(sysload); - - append(output, "%m", sysload.color); // host - append(output, ":"); - append(output, "%l", COL_DARKGREEN); // tty - append(output, " "); - append(output, "%~", COL_DARKGREEN); // cwd - append(output, ":::"); - - for (unsigned int i = 0; i < space.size(); i++) { - append(output, space[i].name); - // TODO Active only - append(output, float_to_str(space[i].available, tmp), space_to_color(space[i])); - append(output, " "); - } - - append(output, "| "); - append(output, float_to_str(sysload.load, tmp), sysload.color); - append(output, " "); - append(output, sysload.proc, sysload.color); - - std::cout << output; - - return 0; -} - -void append(char *output, const char *input, int color) { - unsigned int len_o, len_i, len_c = 0; - - len_o = strlen(output); - len_i = strlen(input); - if (color != -1) len_c = strlen(color_map[color].c_str()); - - if (color != -1) strcpy(output + len_o, color_map[color].c_str()); - strcpy(output + len_o + len_c, input); - if (color != -1) strcpy(output + len_o + len_i + len_c, color_map[COL_NONE].c_str()); -} - -const char *float_to_str(float value, char *output) { - char suffix; - - output[0] = 0; - - if (value > 2*1099511627776.0) { // 2T - value /= 1099511627776.0; - suffix = 'T'; - } else if (value > 2*1073741824.0) { // 2G - value /= 1073741824.0; - suffix = 'G'; - } else if (value > 2*1048576.0) { // 2M - value /= 1048576.0; - suffix = 'M'; - } else if (value > 2*1024.0) { // 2k - value /= 1024.0; - suffix = 'k'; - } else { - suffix = 0; - } - - sprintf(output, "%.2f%c", value, suffix); - - return output; -} - -int space_to_color(Space &space) { - if (space.percent >= config.m1) { - return COL_GREEN; - } else if (space.percent >= config.m2) { - return COL_YELLOW; - } else if (space.percent > (config.m2/32.0)) { - return COL_RED; - } else { - return COL_RFLASH; - } -} - -void get_sysload(Sysload &sysload) { - float dump; - std::ifstream in; - - in.open("/proc/loadavg", std::ifstream::in); - - in >> sysload.load; - in >> dump; - in >> dump; - in >> sysload.proc; - - in.close(); - - if (sysload.load > 12) { - sysload.color = COL_RFLASH; - } else if (sysload.load > 8) { - sysload.color = COL_RED; - } else if (sysload.load > 4) { - sysload.color = COL_YELLOW; - } else { - sysload.color = COL_GREEN; - } -} - -float grepf(const std::string &data, const char *marker) { - unsigned int pos, offset; - char value[16]; - float out; - - offset = 0; - pos = data.find(marker) + strlen(marker); - - // skip through spaces - while (data[pos] == ' ') { - pos++; - } - - // read the number - for (; data[pos] != ' '; pos++, offset++) { - value[offset] = data[pos]; - } - - // terminator - value[offset] = 0; - - out = atof(value); - - return out; -} - -void get_memswap(std::vector &space) { - std::string s; - std::ifstream in; - char c; - - in.open("/proc/meminfo", std::ifstream::in); - - while (true) { - c = in.get(); - - if (in.good()) { - s += c; - } else { - break; - } - } - - in.close(); - - // memory - space.push_back(Space("mem", grepf(s, "MemFree:")*1024 + grepf(s, "Buffers:")*1024 + grepf(s, "Cached:")*1024, grepf(s, "MemTotal:")*1024)); - - // swap - space.push_back(Space("swp", grepf(s, "SwapFree:")*1024.0, grepf(s, "SwapTotal:")*1024.0)); -} - -void get_available_space(std::vector &space) { - // Go through physical RW mounts and query them re: free space - // Ignore /dev and everything below it - // Generate a unique name: mountpoint basename? or maybe shortened to smallest unique part. - - std::vector mounts; - struct statfs stats; - std::string fullname, name, mountpoint; - int ptr, len; - size_t str_pos; - bool OK; - - mounts = read_lines_from_file("/etc/mtab"); - - for (unsigned int i = 0; i < mounts.size(); i++) { - if (column_contains_substr(mounts[i], 3, "rw") and column_contains_substr(mounts[i], 0, "/dev", -1)) { - - // no CDs - loops have rw set - if (column_contains_substr(mounts[i], 2, "iso9660")) { - continue; - } - - // no binds - if (column_contains_substr(mounts[i], 3, "bind")) { - continue; - } - - mountpoint = get_column(mounts[i], 1); - - // handle spaces in mount point names - /proc/mounts uses a 4-byte '\\040' sequence to signify a space - while (true) { - str_pos = mountpoint.find("\\040"); - - if (str_pos == std::string::npos) { - break; - } else { - mountpoint.replace(str_pos, 4, " "); - } - } - - // generate name FIXME basenames are unique on systems with obsessive-compulsive roots only - fullname = basename((char*)mountpoint.c_str()); - if (config.long_names or fullname == "/") { - name = fullname; - } else { - ptr = 1; - len = fullname.size(); - name = fullname.substr(0, ptr); - - OK = false; - while (not OK) { - OK = true; - for (unsigned int j = 0; j < space.size(); j++) { - if (name == space[j].name) { - OK = false; - if (ptr == len) { - // too bad, we give up - name += "!"; - OK = true; - } else { - name = fullname.substr(0, ++ptr); - } - - break; - } - } - } - } - - // figure out free and total space - statfs(mountpoint.c_str(), &stats); - - // pass it on - space.push_back(Space(name.c_str(), stats.f_bavail * stats.f_bsize, stats.f_blocks * stats.f_bsize)); - } - } -} - -std::string get_column(std::string line, unsigned int column) { - std::string output; - unsigned int col_counter; - bool eating_chars; // else eating whitespace - char c; - - col_counter = -1; // Dirty? Maybe. It's called 'creative' where I come from. - eating_chars = false; // ignore leading whitespace - - // start eating bytes - for (unsigned int i = 0; i < line.size(); i++) { - c = line[i]; - - if (eating_chars and isspace(c)) { // end of a column - eating_chars = false; - - if (col_counter == column) { - break; - } - - } else if (not (eating_chars or isspace(c))) { // beginning of a column - eating_chars = true; - col_counter++; - } - - if (col_counter == column) { - output += c; - } - } - - return output; -} - -bool column_contains_substr(std::string line, unsigned int column, std::string substr, int position) { - std::string str; - - str = get_column(line, column); - - switch (position) { - case -1: - // beginning - if (str.substr(0, substr.size()) == substr) { - return true; - } else { - return false; - } - - break; - case 0: - // anywhere - if (str.find(substr) == std::string::npos) { - return false; - } else { - return true; - } - - break; - case 1: - // end - if (str.substr(str.size() - substr.size() - 1, substr.size()) == substr) { - return true; - } else { - return false; - } - - break; - }; - - return false; -} - -std::vector read_lines_from_file(std::string filename) { - char buf[512]; - std::ifstream in; - std::vector lines; - - in.open(filename.c_str(), std::ifstream::in); - - while (in.good()) { - in.getline(buf, 512); - - if (in.gcount()) { - lines.push_back(buf); - } - } - - return lines; -} - -bool str_in_list(std::string str, std::vector list) { - for (unsigned int i = 0; i < list.size(); i++) { - if (list[i] == str) { - return true; - } - } - - return false; -} diff --git a/screeenrc.over b/dotfiles/etc/screeenrc.over similarity index 50% rename from screeenrc.over rename to dotfiles/etc/screeenrc.over index 4deeeeb..f444f46 100644 --- a/screeenrc.over +++ b/dotfiles/etc/screeenrc.over @@ -7,8 +7,8 @@ defscrollback 10240 termcapinfo xterm* ti@:te@ # let's get high-tech with 256 colors over here -attrcolor b ".I" # allow bold colors - necessary for some reason -termcapinfo xterm "Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm" # tell screen how to set colors. AB = background, AF=foreground +#attrcolor b ".I" # allow bold colors - necessary for some reason +#termcapinfo xterm "Co#256:AB=\E[48;5;%dm:AF=\E[38;5;%dm" # tell screen how to set colors. AB = background, AF=foreground defbce on # use current bg color for erased chars # remapping dangerous keybindings @@ -38,14 +38,12 @@ bind '/' eval "scrollback 0" "scrollback 15000" setenv DISPLAY ":0" # start with a bunch of windows -#screen -t "Nice Rootshell" 0 sudo ionice -c 3 nice su - -#screen -t "Nice Rootshell" 1 sudo ionice -c 3 nice su - -#screen -t "Rootshell" 2 sudo su - -#screen -t "Shell" 3 zsh -#screen -t "Shell" 4 zsh -#screen -t "Shell" 5 zsh -#screen -t "Shell" 6 zsh -#screen -t "Dictionary" 7 /home/eridanus/Software/Development/Et/et-dictionary/screen-wrapper.sh -#screen -t "Equalizer" 8 alsamixer -D equal -#screen -t "Red Noise" 9 red-noise.sh -#screen -t "Syncthing" 10 syncthing -no-browser +screen 0 sudo su - +screen 1 sudo ionice -c 3 nice su - +screen 2 sudo ionice -c 3 nice su - +screen 3 sudo ionice -c 3 nice su - +screen 4 sudo ionice -c 3 nice su - +screen 5 red-noise.sh +screen 6 syncthing -no-browser +screen 7 /home/overwatch/Research/old/Development/Et/et-dictionary/screen-wrapper.sh +screen 8 zsh diff --git a/etc/zsh/zprofile b/dotfiles/etc/zsh/zprofile similarity index 88% rename from etc/zsh/zprofile rename to dotfiles/etc/zsh/zprofile index 36f9d82..c8e41a0 100644 --- a/etc/zsh/zprofile +++ b/dotfiles/etc/zsh/zprofile @@ -1,5 +1,5 @@ # /etc/zsh/zprofile -# $Header: /var/cvsroot/gentoo-x86/app-shells/zsh/files/zprofile-1,v 1.1 2010/08/15 12:21:56 tove Exp $ +# $Id$ # Load environment settings from profile.env, which is created by # env-update from the files in /etc/env.d @@ -26,7 +26,7 @@ umask 022 if [ "$EUID" = "0" ] || [ "$USER" = "root" ] ; then PATH="/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:${ROOTPATH}" else - PATH="/usr/local/bin:/usr/bin:/bin:${PATH}" + PATH="/usr/local/bin:/usr/bin:/bin:${PATH}:/home/${USER}/Apps/bin" fi export PATH unset ROOTPATH diff --git a/etc/zsh/zshrc b/dotfiles/etc/zsh/zshrc similarity index 76% rename from etc/zsh/zshrc rename to dotfiles/etc/zsh/zshrc index 29f2646..663d3cd 100644 --- a/etc/zsh/zshrc +++ b/dotfiles/etc/zsh/zshrc @@ -5,10 +5,10 @@ bindkey ' ' magic-space # mezerník rozbaluje odkazy na historii alias ls="ls -F --color" # BAREVNÉ soubory alias l="ls -hl" # bez ll nemá smysl žít alias ll="l -a" -alias grep="grep --color=auto" -alias mencoderize="mencoder -oac mp3lame -lameopts q=0 -ovc lavc -lavcopts vcodec=mpeg4:mbd=1:vbitrate=5120" +alias grep="grep -a --color=auto" alias pull_website="wget --no-parent --recursive --page-requisites --convert-links --html-extension --no-clobber" alias ..="cd .." +alias pp=python2 alias ppp=python3 alias htop="htop -d 3" alias O=xdg-open @@ -16,6 +16,16 @@ alias gits="git status" alias gita="git add" alias gitc="git commit" alias gitp="git push" +alias gitl="git log" +alias http-dir="echo "Serving $CWD on 0.0.0.0:55555"; /usr/sbin/thttpd -D -d . -p 55555 -l -" +alias Yvid="youtube-dl --no-check-certificate" +alias Yall="youtube-dl -o \"%(autonumber)s-%(title)s.%(ext)s\"" +alias units="units -v" + +# Edit the current command line in $EDITOR +autoload -U edit-command-line +zle -N edit-command-line +bindkey '\C-x\C-e' edit-command-line mkcd () { mkdir -p "$1" && cd "$1" @@ -32,7 +42,7 @@ mkv-fixtitles () { done } -psg () { ps ax | grep -v grep | grep -i $* } # hledání v běžících procesech +psg () { ps axu | grep -v grep | grep -i $* } # hledání v běžících procesech pskill () { pids=($(psg $1|awk '{print $1}')) @@ -65,17 +75,21 @@ wt-goto_c() { } wt-list_prefixes() { - ls $* $HOME/.local/share/wineprefixes + ls $* $HOME/.local/share/wineprefixes/ } HISTFILE=~/.history # soubor pro ukládání do historie SAVEHIST=5000 # ukládá se 5000 příkazů HISTSIZE=5000 # :) -setopt HIST_IGNORE_SPACE # řádek začínající mezerou si nepamatuje -setopt HIST_IGNORE_ALL_DUPS # vyhazuje z historie staré duplikáty -setopt EXTENDED_GLOB # rozšířené žolíkové znaky -unsetopt NO_CLOBBER # ochrana při přesměrovávání výstupů -unsetopt CORRECTALL # opravy překlepů +setopt HIST_IGNORE_SPACE +setopt HIST_IGNORE_ALL_DUPS +#setopt SHARE_HISTORY +#setopt EXTENDED_HISTORY +setopt INC_APPEND_HISTORY + +setopt EXTENDED_GLOB +unsetopt NO_CLOBBER # ochrana při přesměrovávání výstupů +unsetopt CORRECTALL # opravy překlepů setopt NO_BEEP # nepípat při chybách unsetopt equals # kvůli emerge =něco export ZLE_REMOVE_SUFFIX_CHARS=$' \t\n;&' diff --git a/dotfiles/personal/.ssh/config b/dotfiles/personal/.ssh/config new file mode 100644 index 0000000..ca981ee --- /dev/null +++ b/dotfiles/personal/.ssh/config @@ -0,0 +1,54 @@ +VisualHostKey=yes + +Host S202 + Hostname 192.168.201.202 + User msekera + +Host K92 + Hostname 10.2.0.92 + User tech + +Host T202 + Hostname 192.168.202.202 + User root + +Host covalent.cz + Hostname covalent.cz + User overwatch + +Host kralux + Hostname kralu.overtech.cz + User root + +Host kralu + Hostname 10.0.0.1 + User root + +Host S202x + Hostname covalent.cz + Port 50022 + User msekera + +Host T202x + Hostname covalent.cz + Port 44422 + User root + +Host K92x + Hostname covalent.cz + Port 55522 + User tech + +Host R89 + Hostname 192.168.201.89 + User root + +Host tellus.kklan + Hostname 192.168.2.222 + Port 50022 + User eridanus + +Host over.kk + Hostname 192.168.2.250 + Port 22 + User root diff --git a/ebuild/over-prompt-9999.ebuild b/ebuild/over-prompt-9999.ebuild new file mode 100644 index 0000000..4c17432 --- /dev/null +++ b/ebuild/over-prompt-9999.ebuild @@ -0,0 +1,43 @@ +# Copyright 1999-2014 Gentoo Foundation +# Distributed under the terms of the GNU General Public License v2 +# $Header: $ + +EAPI=5 + +inherit git-2 + +DESCRIPTION="A nonintrusive zsh prompt that provides useful data like pwd, git info and system stats to the user." + +HOMEPAGE="https://git.covalent.cz/overwatch/over-prompt" +SRC_URI="" +EGIT_REPO_URI="https://git.covalent.cz/overwatch/over-prompt.git" + +LICENSE="AOJSL" +SLOT="0" +KEYWORDS="x86 amd64" + +src_compile() { + ewarn "This is a prototype written in Python. Expect lower performance." + #g++ -ansi -Wall -o data data.cpp +} + +src_install() { + insopts -m755 + + insinto /usr/share/libexec/ + newexe libexec/render.py ${PN}.py + + insinto /usr/share/${PN}/ + doexe share/zsh-init + + insinto /etc/${PN}/ + doins cfg/main.cfg + + insinto /usr/share/i18n/locales/ + doins locale/en_OV +} + +pkg_postinst() { + einfo "Source /usr/share/${PN}/zsh-init to enable the prompt." + einfo "The config file is in /etc/${PN}/." +} diff --git a/render.py b/libexec/render.py similarity index 89% rename from render.py rename to libexec/render.py index 9b7d3b7..b34d8dc 100755 --- a/render.py +++ b/libexec/render.py @@ -18,6 +18,7 @@ COLOR_SESSION_REMOTE = 202 COLOR_TERM_SCREEN = 27 COLOR_CLOCK = 27 +COLOR_CLOCK_DELTA = 11 COLOR_MEMSWAP = 8 COLOR_SPACE_OK = 2 COLOR_SPACE_WARN = 3 @@ -113,14 +114,15 @@ class Settings: try: self.return_value = int(argv[1]) self.term_width = int(argv[2]) - self.load_warn = float(argv[3]) - self.load_error = float(argv[4]) - self.space_warn = float(argv[5]) - self.space_error = float(argv[6]) + self.last_refresh = int(argv[3]) if argv[3] else None + self.load_warn = float(argv[4]) + self.load_error = float(argv[5]) + self.space_warn = float(argv[6]) + self.space_error = float(argv[7]) self.is_root = os.geteuid() == 0 except: - print("Usage: %s return_value $COLUMNS load_warn load_error space_warn space_error") - print(" e.g. %s 1 $COLUMNS 1.25 2.5 0.15 0.05") + print("Usage: %s return_value $COLUMNS last_refresh load_warn load_error space_warn space_error") + print(" e.g. %s 1 $COLUMNS 25 1.25 2.5 0.15 0.05") print() raise @@ -322,7 +324,7 @@ class GitPart(Part): branch_name = command("git name-rev --name-only --no-undefined --always HEAD").strip() if branch_name: - self.fragments.append("| ") + self.fragments.append("↱ ") count_to_pull = command("git log --oneline ..@{u}").count("\n") count_to_push = command("git log --oneline @{u}..").count("\n") @@ -376,8 +378,9 @@ class Padding(Part): class StatsPart(Part): """ - [ clock | sysload tasks | m:memory (?s:swap?) mountpoint_spaces... - - clock shows current day and time (in DD HH:MM) + [ ?Δ1? clock | sysload tasks | m:memory ?s:swap? mountpoint_spaces... + - delta is shown if the last prompt refresh was before midnight, and displays how many midnights elapsed since + - clock shows current time (in HH:MM) - sysload is current loadavg divided by amount of cores (in 1) - tasks is the total amount of tasks on the system - memory shows current free memory (in octets) @@ -387,8 +390,21 @@ class StatsPart(Part): def __init__(self, settings, sysload): Part.__init__(self) + self.fragments.append("[ ") + self.fragments.append(style_bold()) + + # delta + if settings.last_refresh: + then = datetime.datetime.fromtimestamp(settings.last_refresh).replace(hour=0, minute=0, second=0, microsecond=0) + now = datetime.datetime.now().replace(hour=0, minute=0, second=0, microsecond=0) + midnights = (now - then).days + + if midnights: + self.fragments.append(style_color(COLOR_CLOCK_DELTA)) + self.fragments.append("Δ%d " %(midnights)) + # clock - self.fragments.append(datetime.datetime.now().strftime("[ %%d \033[38;5;%dm%%H:%%M\033[0m | " %(COLOR_CLOCK))) + self.fragments.append(datetime.datetime.now().strftime("\033[38;5;%dm%%H:%%M\033[0m | " %(COLOR_CLOCK))) # sysload self.fragments.append(style_color(settings.get_load_color(sysload.load1))) @@ -417,6 +433,7 @@ class StatsPart(Part): self.fragments.append(style_color(COLOR_MEMSWAP)) self.fragments.append("m") + self.fragments.append(style_bold()) self.fragments.append(style_color(settings.get_space_color(mem_free, mem_total))) mem_free_si = si_number(mem_free) self.fragments.append(space_string(mem_free) %(mem_free_si[0], mem_free_si[1])) @@ -425,6 +442,7 @@ class StatsPart(Part): if swap_total - swap_free > 2**20: self.fragments.append(style_color(COLOR_MEMSWAP)) self.fragments.append(" s") + self.fragments.append(style_bold()) self.fragments.append(style_color(settings.get_space_color(swap_free, swap_total))) swap_free_si = si_number(swap_free) self.fragments.append(space_string(swap_free) %(swap_free_si[0], swap_free_si[1])) @@ -469,6 +487,7 @@ class StatsPart(Part): stor_free = stat.f_bavail * stat.f_bsize self.fragments.append(short_name) + self.fragments.append(style_bold()) self.fragments.append(style_color(settings.get_space_color(stor_free, stor_total))) stor_free_si = si_number(stor_free) self.fragments.append(space_string(stor_free) %(stor_free_si[0], stor_free_si[1])) diff --git a/en_OV b/locale/en_OV similarity index 100% rename from en_OV rename to locale/en_OV diff --git a/over-prompt-9999.ebuild b/over-prompt-9999.ebuild deleted file mode 100644 index 3d218df..0000000 --- a/over-prompt-9999.ebuild +++ /dev/null @@ -1,44 +0,0 @@ -# Copyright 1999-2014 Gentoo Foundation -# Distributed under the terms of the GNU General Public License v2 -# $Header: $ - -EAPI=5 - -inherit git-2 - -DESCRIPTION="A nonintrusive zsh prompt that provides useful data like pwd, git info and system stats to the user." - -HOMEPAGE="https://git.covalent.cz/overwatch/over-prompt" -SRC_URI="" -export GIT_SSL_NO_VERIFY=true # git.covalent.cz has a self-signed cert for now -EGIT_REPO_URI="https://git.covalent.cz/overwatch/over-prompt.git" - -LICENSE="AOJSL" -SLOT="0" -KEYWORDS="x86 amd64" - -src_compile() { - g++ -ansi -Wall -o data data.cpp -} - -src_install() { - insinto /usr/share/${PN} - insopts -m755 - doins data - doins zsh-init - - insinto /usr/share/i18n/locales/ - doins en_OV -} - -pkg_postinst() { - einfo "Source /usr/share/${PN}/zsh-init to enable the prompt." - einfo "If you wish, write the following into /etc/over/prompt.cfg:" - einfo "" - einfo "export OVER_PROMPT_OPTS=\"A B C\"" - einfo "" - einfo "where A is the percentage at which your free space indicator turns" - einfo "yellow, B is the threshold for red color, and C is either 'short' or" - einfo "'long' (without the quotes), indicating whether you want to display" - einfo "short or long mount point names. The default is \"20 10 short\"." -} diff --git a/render.cpp b/render.cpp deleted file mode 100644 index 424e6ef..0000000 --- a/render.cpp +++ /dev/null @@ -1,441 +0,0 @@ -#include -#include -#include -#include -#include -#include -#include - -#define ATTR_NONE 0 -#define ATTR_BOLD 1 -#define ATTR_UNDER 4 -#define ATTR_BLINK 5 - -#define SYM_GIT "\ue0a0" -#define SYM_LN "\ue0a1" -#define SYM_LOCK "\ue0a2" -#define SYM_RIGHTBLK "\ue0b0" -#define SYM_RIGHT "\ue0b1" -#define SYM_LEFTBLK "\ue0b2" -#define SYM_LEFT "\ue0b3" - -#define COL_DEFAULT_FG 7 -#define COL_DEFAULT_BG 0 -#define COL_LOGIN_USER_FG 202 -#define COL_LOGIN_USER_BG 232 -#define COL_LOGIN_ROOT_FG 232 -#define COL_LOGIN_ROOT_BG 124 -#define COL_SCREEN_FG 232 -#define COL_SCREEN_BG 27 -#define COL_PATH_FG 202 -#define COL_PATH2_FG 232 -#define COL_PATH_BG 232 -#define COL_GIT_CLEAN_FG 232 -#define COL_GIT_CLEAN_BG 88 -#define COL_GIT_DIRTY_FG 232 -#define COL_GIT_DIRTY_BG 46 -#define COL_LOCK_FG 196 -#define COL_TIME_FG 202 -#define COL_TIME_BG 232 -#define COL_LOAD_OK_FG 202 -#define COL_LOAD_OK_BG 232 -#define COL_LOAD_WARN_FG 232 -#define COL_LOAD_WARN_BG 3 -#define COL_LOAD_HIGH_FG 232 -#define COL_LOAD_HIGH_BG 202 -#define COL_LOAD_OVER_FG 15 -#define COL_LOAD_OVER_BG 196 -#define COL_PROMPT_OK_FG 232 -#define COL_PROMPT_OK_BG 34 -#define COL_ERR_FG 15 -#define COL_ERR_BG 196 - - -#define PATH_MAX 4096 - -#ifndef uint -#define uint unsigned int -#endif - -/* -------------------------------------------------- */ - -class Config { -public: - Config(int argc, char **argv) { - if (argc != 5) { - fprintf(stderr, "Usage: %s red_threshold yellow_threshold terminal_width last_exit_status\n", argv[0]); - this->failed = true; - return; - } - - this->red_thresh = strtof(argv[1], NULL); - this->yellow_thresh = strtof(argv[2], NULL); - this->term_width = strtol(argv[3], NULL, 10); - this->last_exit_status = strtol(argv[4], NULL, 10); - this->is_root = (geteuid() == 0); - - this->failed = false; - } - - uint term_width; - float red_thresh; - float yellow_thresh; - uint last_exit_status; - bool is_root; - - bool failed; -}; - -class Segment { -public: - Segment(const char *str, bool printable=true) { - this->raw_length = strlen(str); - this->raw_str = new char[(this->raw_length + 1) * sizeof(char)]; // +1 for null - strcpy(this->raw_str, str); - - if (printable) { - this->printable_length = u8_mbsnlen((const uint8_t*)str, this->raw_length); - } else { - this->printable_length = 0; - } - } - - ~Segment(void) { - delete[] this->raw_str; - } - - char *raw_str; - size_t raw_length; - size_t printable_length; -}; - -class Output { -public: - Output(void) { - this->printable_length = 0; - this->raw_length = 0; - this->ptr = 0; - this->max = 256; // a reasonable amount? - - this->segments = new Segment*[this->max]; - - this->set_colors(COL_DEFAULT_FG, COL_DEFAULT_BG); - } - - ~Output(void) { - for (uint i = 0; i < this->ptr; i++) { - delete this->segments[i]; - } - - delete[] this->segments; - } - - void output(FILE *stream) { - for (uint i = 0; i < this->ptr; i++) { - fputs(this->segments[i]->raw_str, stream); - } - } - - void set_colors(uint fg, uint bg, const char *transition=NULL, bool left_to_right=true) { - if (transition) { - this->push(" "); - } - - if (left_to_right) this->_push_color(bg, true); - - if (transition) { - this->_push_color(left_to_right? this->col_bg : bg); - this->push(transition); - if (left_to_right) this->push(" "); - } - - if (not left_to_right) this->_push_color(bg, true); - this->_push_color(fg); - - if (transition and not left_to_right) this->push(" "); - - this->col_fg = fg; - this->col_bg = bg; - } - - void _push_color(uint color=ATTR_NONE, bool bg=false) { - if (color == ATTR_NONE) { - this->set_attr(); - } else { - char tmp[16]; - snprintf(tmp, 16, "\e[%d;5;%dm", (bg? 48:38), color); - - this->push(new Segment(tmp, false)); - } - } - - void set_attr(uint attr=ATTR_NONE) { - char tmp[10]; - snprintf(tmp, 10, "\e[%dm", attr); - - this->push(new Segment(tmp, false)); - } - - void push(Segment *segment) { - if (this->ptr + 1 == this->max) { - fprintf(stderr, "Output.segments full, this will probably fail.\n"); - } - - this->segments[this->ptr++] = segment; - this->printable_length += segment->printable_length; - this->raw_length += segment->raw_length; - } - - void push(const char *str) { - this->push(new Segment(str)); - } - - void push(uint n) { - char tmp[1024]; - sprintf(tmp, "%d", n); - this->push(tmp); - } - - Segment **segments; - size_t ptr, max; - size_t raw_length; - size_t printable_length; - - uint col_fg, col_bg; -}; - -void render_screen(Output *output) { - char *tmp = getenv("WINDOW"); - - if (tmp) { - output->set_colors(COL_SCREEN_FG, COL_SCREEN_BG, SYM_RIGHTBLK); - output->push(tmp); - } -} - -void render_path(Output *output) { - char buf[PATH_MAX]; - - getcwd(buf, PATH_MAX); - - // tokenize path TODO replace homes with ~ - char *ptr = buf; - char *ptr_end; - char *tokens[100]; // a sensible default? - char token[4096]; - uint token_count = 0; - uint token_length; - - while (*ptr) { // until NULL terminator - ptr = strchrnul(ptr, '/') + 1; - ptr_end = strchrnul(ptr, '/'); - token_length = ptr_end - ptr; - memcpy(token, ptr, token_length); - token[token_length] = 0; - - if (token_length) { - tokens[token_count] = new char[(token_length + 1) * sizeof(char)]; - memcpy(tokens[token_count], token, token_length); - tokens[token_count][token_length] = 0; - token_count++; - } - } - - // render path with increasing background brightness - uint fg = COL_PATH_FG; - uint bg = COL_PATH_BG; - - for (uint i = 0; i < token_count; i++) { - if (bg == 241) fg = COL_PATH2_FG; - - if (bg < 255) { - output->set_colors(fg, bg++, SYM_RIGHTBLK); - } else { - output->push(" "); - output->push(SYM_RIGHT); - output->push(" "); - } - - output->push(tokens[i]); - delete[] tokens[i]; - } -} - -void render_git(Output *output) { - FILE *pipe; - char branch_name[1024]; - - pipe = popen("git rev-parse --abbrev-ref HEAD 2> /dev/null", "r"); - - if (pipe) { - if (fgets(branch_name, 1024, pipe)) { - branch_name[strlen(branch_name) - 1] = 0; // kill the newline - - // rebuild index - system("git update-index -q --ignore-submodules --refresh"); - - // so that I can check if there are unstaged changes - if (system("git diff-files --quiet --ignore-submodules")) { - output->set_colors(COL_GIT_CLEAN_FG, COL_GIT_CLEAN_BG, SYM_RIGHTBLK); - } else { - output->set_colors(COL_GIT_DIRTY_FG, COL_GIT_DIRTY_BG, SYM_RIGHTBLK); - } - - output->push(SYM_GIT); - output->push(" "); - output->push(branch_name); - } - - pclose(pipe); - } else { - fprintf(stderr, "--- failed to run git\n"); - } -} - -void render_lock(Output *output) { - if (access(".", W_OK) != 0) { -// output->set_colors(COL_LOCK_FG, COL_LOCK_BG, SYM_RIGHTBLK); - output->_push_color(COL_LOCK_FG); - output->push(" "); - output->push(SYM_LOCK); - } -} - -void render_padding(const uint term_width, const uint length, FILE *stream) { - int delta = term_width - length; - - if (delta >= 0) { - delta--; // fish refuses to write to the last column - - for (uint i = 0; i < (uint) delta; i++) { - fputc(' ', stream); - } - } else { - fputc('!', stream); - } -} - -void render_time(Output *output) { - time_t rawtime; - struct tm *info; - char buffer[1024]; - - time(&rawtime); - info = localtime(&rawtime); - - strftime(buffer, 1024, "%H:%M", info); - - output->push(buffer); -} - -void render_sysload(Output *output) { - double load; - char tmp[16]; - uint bg, fg; - - if (getloadavg(&load, 1) == 1) { - if (load > 12) { - fg = COL_LOAD_OVER_FG; - bg = COL_LOAD_OVER_BG; - } else if (load > 8) { - fg = COL_LOAD_HIGH_FG; - bg = COL_LOAD_HIGH_BG; - } else if (load > 4) { - fg = COL_LOAD_WARN_FG; - bg = COL_LOAD_WARN_BG; - } else { - fg = COL_LOAD_OK_FG; - bg = COL_LOAD_OK_BG; - } - - output->set_colors(fg, bg, SYM_RIGHTBLK); - sprintf(tmp, "%.2f", load); - output->push(tmp); - } else { - output->set_colors(COL_ERR_FG, COL_ERR_BG, SYM_RIGHTBLK); - output->push("ERR"); - } -} - -/* -------------------------------------------------- */ - -int main(int argc, char **argv) { - Config config(argc, argv); - if (config.failed) return 1; - - /* -------------------------------------------------- - * output init - */ - - Output top_left; - Output top_right; - Output prompt; - - /* -------------------------------------------------- - * top_left: user@host[:screen] path > to > cwd [git branch] [lock] - */ - - char buf[PATH_MAX]; - - if (config.is_root) { - top_left.set_colors(COL_LOGIN_ROOT_FG, COL_LOGIN_ROOT_BG); - } else { - top_left.set_colors(COL_LOGIN_USER_FG, COL_LOGIN_USER_BG); - } - - top_left.push(" "); - top_left.push(getlogin()); - top_left.push("@"); - - gethostname(buf, 256); - top_left.push(buf); - - render_screen(&top_left); - render_path(&top_left); - render_lock(&top_left); - render_git(&top_left); - - top_left.set_colors(COL_DEFAULT_FG, COL_DEFAULT_BG, SYM_RIGHTBLK); - - /* -------------------------------------------------- - * prompt: [last_exit_status:]$|# > - */ - - if (config.last_exit_status) { - prompt.set_colors(COL_ERR_FG, COL_ERR_BG); - prompt.push(" "); - prompt.push(config.last_exit_status); - } else { - prompt.set_colors(COL_PROMPT_OK_FG, COL_PROMPT_OK_BG); - prompt.push(" "); - - if (config.is_root) { - prompt.push("#"); - } else { - prompt.push("$"); - } - } - - prompt.set_colors(COL_DEFAULT_FG, COL_DEFAULT_BG, SYM_RIGHTBLK); - - /* -------------------------------------------------- - * top_right: < time < spaces < sysload - */ - - top_right.set_colors(COL_TIME_FG, COL_TIME_BG, SYM_LEFTBLK, false); - render_time(&top_right); - render_sysload(&top_right); - top_right.set_colors(COL_DEFAULT_FG, COL_DEFAULT_BG, SYM_RIGHTBLK); - - /* -------------------------------------------------- - * output the prompt - */ - - top_left.output(stdout); - render_padding(config.term_width, top_left.printable_length + top_right.printable_length, stdout); - top_right.output(stdout); - fputs("\n", stdout); - prompt.output(stdout); - - return 0; -} diff --git a/zsh-init b/share/zsh-init similarity index 59% rename from zsh-init rename to share/zsh-init index ab28bdb..8fccb14 100755 --- a/zsh-init +++ b/share/zsh-init @@ -1,6 +1,6 @@ #! /bin/zsh -OVER_PROMPT_CFG="/etc/over/prompt.cfg" +OVER_PROMPT_CFG="/etc/over-prompt/main.cfg" if [[ -a "$OVER_PROMPT_CFG" ]]; then source "$OVER_PROMPT_CFG" @@ -21,8 +21,9 @@ function preexec { function precmd { set_title "${PWD}" - python3 ./render.py $? $COLUMNS 1.25 2.5 0.15 0.05 + python3 /usr/libexec/over-prompt.py $? "${COLUMNS}" "${OVER_PROMPT_LAST_REFRESH}" "${OVER_PROMPT_SYSLOAD_WARN:=1.25}" "${OVER_PROMPT_SYSLOAD_YELL:=2.5}" "${OVER_PROMPT_FREESPACE_WARN:=0.15}" "${OVER_PROMPT_FREESPACE_YELL:=0.05}" PS1="$(print "%(?.%{\e[1;36m%}.%{\e[1;31m%}%?%{\e[0m%}:%{\e[1;31m%})%(\!.#.$)%{\e[0m%} ")" + OVER_PROMPT_LAST_REFRESH=$(date +%s) } unset OVER_PROMPT_CFG diff --git a/256-xterm-colors.py b/tools/256-xterm-colors.py similarity index 100% rename from 256-xterm-colors.py rename to tools/256-xterm-colors.py