ssh indicator
This commit is contained in:
parent
b2c4dd008f
commit
84ee4983ae
5
.idea/.gitignore
vendored
Normal file
5
.idea/.gitignore
vendored
Normal file
@ -0,0 +1,5 @@
|
|||||||
|
# Default ignored files
|
||||||
|
/shelf/
|
||||||
|
/workspace.xml
|
||||||
|
# Editor-based HTTP Client requests
|
||||||
|
/httpRequests/
|
11
.idea/PrettyPrompt.iml
Normal file
11
.idea/PrettyPrompt.iml
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<module type="EMPTY_MODULE" version="4">
|
||||||
|
<component name="NewModuleRootManager">
|
||||||
|
<content url="file://$MODULE_DIR$">
|
||||||
|
<sourceFolder url="file://$MODULE_DIR$/src" isTestSource="false" />
|
||||||
|
<excludeFolder url="file://$MODULE_DIR$/target" />
|
||||||
|
</content>
|
||||||
|
<orderEntry type="inheritedJdk" />
|
||||||
|
<orderEntry type="sourceFolder" forTests="false" />
|
||||||
|
</component>
|
||||||
|
</module>
|
8
.idea/modules.xml
Normal file
8
.idea/modules.xml
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="ProjectModuleManager">
|
||||||
|
<modules>
|
||||||
|
<module fileurl="file://$PROJECT_DIR$/.idea/PrettyPrompt.iml" filepath="$PROJECT_DIR$/.idea/PrettyPrompt.iml" />
|
||||||
|
</modules>
|
||||||
|
</component>
|
||||||
|
</project>
|
6
.idea/vcs.xml
Normal file
6
.idea/vcs.xml
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
<?xml version="1.0" encoding="UTF-8"?>
|
||||||
|
<project version="4">
|
||||||
|
<component name="VcsDirectoryMappings">
|
||||||
|
<mapping directory="" vcs="Git" />
|
||||||
|
</component>
|
||||||
|
</project>
|
23
src/main.rs
23
src/main.rs
@ -4,12 +4,13 @@ use std::env::args;
|
|||||||
use std::path::PathBuf;
|
use std::path::PathBuf;
|
||||||
//use std::ffi::OsString;
|
//use std::ffi::OsString;
|
||||||
use colored::Colorize;
|
use colored::Colorize;
|
||||||
|
use colored::ColoredString;
|
||||||
|
|
||||||
fn get_shell_char (shell: String) -> String {
|
fn get_shell_char (shell: String) -> String {
|
||||||
let shell_char = match shell.as_str() {
|
let shell_char = match shell.as_str() {
|
||||||
"bash"|"/bin/bash"
|
"bash"|"/bin/bash"
|
||||||
=> "",
|
=> "",
|
||||||
"zsh"|"/bin/zsh"|"/usr/bin/zsh"
|
"zsh"|"/bin/zsh"|"/usr/bin/zsh"|"-zsh"
|
||||||
=> "",
|
=> "",
|
||||||
"fish"
|
"fish"
|
||||||
=> "",
|
=> "",
|
||||||
@ -39,7 +40,7 @@ fn abrev_path (pwd: PathBuf, homedir: String) -> String {
|
|||||||
|
|
||||||
for p in &parts[0..len] {
|
for p in &parts[0..len] {
|
||||||
let part = p;
|
let part = p;
|
||||||
if part.to_string() != "" { // to avoid "/"
|
if part.to_string() != "" { // to avoid the 1st "/"
|
||||||
fch = part.chars().next().expect(p).to_string(); // 1st char of p
|
fch = part.chars().next().expect(p).to_string(); // 1st char of p
|
||||||
short_dir = short_dir.replace(part, &fch);
|
short_dir = short_dir.replace(part, &fch);
|
||||||
}
|
}
|
||||||
@ -55,7 +56,8 @@ fn main() -> std::io::Result<()> {
|
|||||||
let shell: String;
|
let shell: String;
|
||||||
let _user = var_os("USER").expect("UnknownUser").to_str().expect("UnknownUser").to_string();
|
let _user = var_os("USER").expect("UnknownUser").to_str().expect("UnknownUser").to_string();
|
||||||
let homedir = var_os("HOME").expect("UnknownDir").to_str().expect("UnknownDir").to_string();
|
let homedir = var_os("HOME").expect("UnknownDir").to_str().expect("UnknownDir").to_string();
|
||||||
|
let ssh_char:ColoredString;
|
||||||
|
let mut ssh_char_space: String = "".to_string();
|
||||||
|
|
||||||
if args.len() > 1 {
|
if args.len() > 1 {
|
||||||
shell = args[1].clone();
|
shell = args[1].clone();
|
||||||
@ -67,10 +69,21 @@ fn main() -> std::io::Result<()> {
|
|||||||
if user == "root" {
|
if user == "root" {
|
||||||
println!("heh");
|
println!("heh");
|
||||||
}*/
|
}*/
|
||||||
|
match var_os("SSH_TTY") {
|
||||||
|
Some(_val) => {
|
||||||
|
ssh_char = "".truecolor(34,109,155);
|
||||||
|
ssh_char_space = " ".to_string();
|
||||||
|
},
|
||||||
|
None => {
|
||||||
|
ssh_char = "".truecolor(34,109,155);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
print!("{} {}{} ",
|
print!("{}{}{} {}{} ",
|
||||||
|
ssh_char,
|
||||||
|
ssh_char_space,
|
||||||
get_shell_char(shell).truecolor(75,75,75),
|
get_shell_char(shell).truecolor(75,75,75),
|
||||||
abrev_path(pwd,homedir).italic().truecolor(75,75,75),
|
abrev_path(pwd,homedir).italic().truecolor(82,82,82),
|
||||||
angle.truecolor(0, 255, 180),
|
angle.truecolor(0, 255, 180),
|
||||||
);
|
);
|
||||||
Ok(())
|
Ok(())
|
||||||
|
Loading…
Reference in New Issue
Block a user