Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
6a5e11bf18 | |||
0dbb3cee34 | |||
106181f022 | |||
36c8b4d2d7 |
9
hook.zsh
9
hook.zsh
@ -1,14 +1,9 @@
|
||||
prompt_precmd() {
|
||||
export PS1=$'`prim --ps1 --col $COLUMNS --row $LINES --status $? --pchar ❯`'
|
||||
export RPS1=$'`prim --rps1 --col $COLUMNS --row $LINES --status $?`'
|
||||
}
|
||||
|
||||
prompt_preexec() {
|
||||
# print -P `prim --preexec --col $COLUMNS --row $LINES --status $?`
|
||||
export PS1=$'`prim --ps1 --col "$COLUMNS" --row "$LINES" --status "$?" --pchar "*"`'
|
||||
export RPS1=$'`prim --rps1 --col "$COLUMNS" --row "$LINES" --status "$?"`'
|
||||
}
|
||||
|
||||
autoload -Uz add-zsh-hook
|
||||
setopt promptsubst
|
||||
|
||||
add-zsh-hook precmd prompt_precmd
|
||||
add-zsh-hook preexec prompt_preexec
|
||||
|
18
source/app.d
18
source/app.d
@ -14,14 +14,22 @@ Opts defaultOpts() {
|
||||
Opts opts;
|
||||
|
||||
opts.pathlen = 3;
|
||||
opts.pchar = "|>";
|
||||
opts.pchar = "*";
|
||||
|
||||
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) {
|
||||
Opts opts = defaultOpts();
|
||||
|
||||
try {
|
||||
|
||||
GetoptResult args = getopt(
|
||||
argv,
|
||||
std.getopt.config.bundling,
|
||||
@ -43,9 +51,11 @@ void main(string[] argv) {
|
||||
);
|
||||
|
||||
if (args.helpWanted) {
|
||||
defaultGetoptPrinter("prim prompt:\n", args.options);
|
||||
writeln("\nEnvironment:\n",
|
||||
"\tNO_COLOR\tsee https://no-color.org");
|
||||
printHelp(args);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
writeln(e.msg);
|
||||
writeln("try '--help' for more information");
|
||||
}
|
||||
|
||||
dorun(opts);
|
||||
|
22
source/comp/ssh.d
Normal file
22
source/comp/ssh.d
Normal 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;
|
||||
}
|
@ -6,6 +6,7 @@ import prim.opt;
|
||||
|
||||
import comp.hr;
|
||||
import comp.path;
|
||||
import comp.ssh;
|
||||
|
||||
import style;
|
||||
import style.color;
|
||||
@ -18,9 +19,10 @@ string ps1(Opts opt) {
|
||||
|
||||
ps ~= "\n";
|
||||
ps ~= (",-(" ~ pathstr ~ ")".set(Color.black)).set(Color.black);
|
||||
ps ~= " " ~ ssh().set(Color.cyan);
|
||||
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);
|
||||
return ps;
|
||||
}
|
||||
|
@ -38,3 +38,16 @@ enum Bg {
|
||||
def,
|
||||
reset = 0
|
||||
}
|
||||
|
||||
enum BrightBg {
|
||||
black = 100,
|
||||
red,
|
||||
green,
|
||||
yellow,
|
||||
blue,
|
||||
magenta,
|
||||
cyan,
|
||||
white,
|
||||
def,
|
||||
reset = 0
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user