Compare commits
4 Commits
Author | SHA1 | Date | |
---|---|---|---|
6a5e11bf18 | |||
0dbb3cee34 | |||
106181f022 | |||
36c8b4d2d7 |
9
hook.zsh
9
hook.zsh
@ -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
|
|
||||||
|
50
source/app.d
50
source/app.d
@ -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
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.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;
|
||||||
}
|
}
|
||||||
|
@ -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
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user