Compare commits

...

4 Commits
v0.1.0 ... main

Author SHA1 Message Date
6a5e11bf18 Add ssh component 2023-09-26 09:00:14 -04:00
0dbb3cee34 Set status to color yellow 2023-08-23 00:08:22 -04:00
106181f022 Add brightbg colors 2023-08-11 15:05:12 -04:00
36c8b4d2d7 Catch flag parse error 2023-08-10 11:55:20 -04:00
5 changed files with 70 additions and 28 deletions

View File

@ -1,14 +1,9 @@
prompt_precmd() { prompt_precmd() {
export PS1=$'`prim --ps1 --col $COLUMNS --row $LINES --status $? --pchar `' export PS1=$'`prim --ps1 --col "$COLUMNS" --row "$LINES" --status "$?" --pchar "*"`'
export RPS1=$'`prim --rps1 --col $COLUMNS --row $LINES --status $?`' export RPS1=$'`prim --rps1 --col "$COLUMNS" --row "$LINES" --status "$?"`'
}
prompt_preexec() {
# print -P `prim --preexec --col $COLUMNS --row $LINES --status $?`
} }
autoload -Uz add-zsh-hook autoload -Uz add-zsh-hook
setopt promptsubst setopt promptsubst
add-zsh-hook precmd prompt_precmd add-zsh-hook precmd prompt_precmd
add-zsh-hook preexec prompt_preexec

View File

@ -14,38 +14,48 @@ Opts defaultOpts() {
Opts opts; Opts opts;
opts.pathlen = 3; opts.pathlen = 3;
opts.pchar = "|>"; opts.pchar = "*";
return opts; return opts;
} }
void printHelp(GetoptResult args) {
defaultGetoptPrinter("prim prompt:\n", args.options);
writeln("\nEnvironment:\n",
"\tNO_COLOR\tsee https://no-color.org");
}
void main(string[] argv) { void main(string[] argv) {
Opts opts = defaultOpts(); Opts opts = defaultOpts();
GetoptResult args = getopt( try {
argv,
std.getopt.config.bundling,
"ps1|p", "print PS1", &opts.ps1,
"rps1|r", "print RPS1", &opts.rps1,
"preexec|x", "print preexec", &opts.preexec,
std.getopt.config.required, GetoptResult args = getopt(
"col", "terminal width", &opts.col, argv,
std.getopt.config.bundling,
"ps1|p", "print PS1", &opts.ps1,
"rps1|r", "print RPS1", &opts.rps1,
"preexec|x", "print preexec", &opts.preexec,
std.getopt.config.required, std.getopt.config.required,
"row", "terminal height", &opts.row, "col", "terminal width", &opts.col,
std.getopt.config.required, std.getopt.config.required,
"status", "previous command exit code", &opts.status, "row", "terminal height", &opts.row,
"pathlen", "set length of displayed path", &opts.pathlen, std.getopt.config.required,
"pchar", "override default prompt character", &opts.pchar, "status", "previous command exit code", &opts.status,
);
if (args.helpWanted) { "pathlen", "set length of displayed path", &opts.pathlen,
defaultGetoptPrinter("prim prompt:\n", args.options); "pchar", "override default prompt character", &opts.pchar,
writeln("\nEnvironment:\n", );
"\tNO_COLOR\tsee https://no-color.org");
if (args.helpWanted) {
printHelp(args);
}
} catch (Exception e) {
writeln(e.msg);
writeln("try '--help' for more information");
} }
dorun(opts); dorun(opts);

22
source/comp/ssh.d Normal file
View File

@ -0,0 +1,22 @@
module comp.ssh;
import std.process : environment;
import std.socket : Socket;
string ssh() {
string ssh = environment.get("SSH_TTY");
string username = environment.get("USER");
username = username ? username : "";
if (!ssh) {
return "";
}
auto s = new Socket();
scope (exit)
s.close();
string hostname = s.hostName;
return username ~ "@" ~ hostname;
}

View File

@ -6,6 +6,7 @@ import prim.opt;
import comp.hr; import comp.hr;
import comp.path; import comp.path;
import comp.ssh;
import style; import style;
import style.color; import style.color;
@ -18,9 +19,10 @@ string ps1(Opts opt) {
ps ~= "\n"; ps ~= "\n";
ps ~= (",-(" ~ pathstr ~ ")".set(Color.black)).set(Color.black); ps ~= (",-(" ~ pathstr ~ ")".set(Color.black)).set(Color.black);
ps ~= " " ~ ssh().set(Color.cyan);
ps ~= "\n"; ps ~= "\n";
ps ~= ("'-(" ~ to!string(opt.status) ~ ") ").set(Color.black); // prompt char ps ~= ("`-(" ~ to!string(opt.status).set(Color.yellow) ~ ") ".set(Color.black)).set(Color.black); // prompt char
ps ~= (opt.pchar ~ " ").set(Font.bold).set(opt.status == 0 ? Color.green : Color.red); ps ~= (opt.pchar ~ " ").set(Font.bold).set(opt.status == 0 ? Color.green : Color.red);
return ps; return ps;
} }

View File

@ -38,3 +38,16 @@ enum Bg {
def, def,
reset = 0 reset = 0
} }
enum BrightBg {
black = 100,
red,
green,
yellow,
blue,
magenta,
cyan,
white,
def,
reset = 0
}