shorten pwd

This commit is contained in:
Candifloss 2024-11-26 13:43:39 +05:30
parent a9a7dc13b8
commit 18168cf0e1
5 changed files with 40 additions and 124 deletions

View File

@ -1,102 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="AutoImportSettings">
<option name="autoReloadType" value="ALL" />
</component>
<component name="CargoProjects">
<cargoProject FILE="$PROJECT_DIR$/Cargo.toml" />
</component>
<component name="ChangeListManager">
<list default="true" id="7404a252-decc-46ca-a3ce-8225afa42ca8" name="Changes" comment="" />
<option name="SHOW_DIALOG" value="false" />
<option name="HIGHLIGHT_CONFLICTS" value="true" />
<option name="HIGHLIGHT_NON_ACTIVE_CHANGELIST" value="false" />
<option name="LAST_RESOLUTION" value="IGNORE" />
</component>
<component name="ExecutionTargetManager" SELECTED_TARGET="RsBuildProfile:dev" />
<component name="Git.Settings">
<option name="RECENT_GIT_ROOT_PATH" value="$PROJECT_DIR$" />
</component>
<component name="MacroExpansionManager">
<option name="directoryName" value="6kwtndvm" />
</component>
<component name="ProjectColorInfo">{
&quot;associatedIndex&quot;: 2
}</component>
<component name="ProjectId" id="2kf6SCvTmKzhjLJnRhdDhchfDDs" />
<component name="ProjectViewState">
<option name="hideEmptyMiddlePackages" value="true" />
<option name="showLibraryContents" value="true" />
</component>
<component name="PropertiesComponent"><![CDATA[{
"keyToString": {
"Cargo.Run prettyprompt.executor": "Run",
"RunOnceActivity.ShowReadmeOnStart": "true",
"RunOnceActivity.rust.reset.selective.auto.import": "true",
"git-widget-placeholder": "main",
"last_opened_file_path": "/home/lcm/Works/PrettyPrompt",
"node.js.detected.package.eslint": "true",
"node.js.selected.package.eslint": "(autodetect)",
"nodejs_package_manager_path": "npm",
"org.rust.cargo.project.model.PROJECT_DISCOVERY": "true",
"org.rust.first.attach.projects": "true",
"vue.rearranger.settings.migration": "true"
}
}]]></component>
<component name="RunManager" selected="Cargo.Run prettyprompt">
<configuration name="Run prettyprompt" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="run --package prettyprompt --bin prettyprompt" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
<configuration name="Test prettyprompt" type="CargoCommandRunConfiguration" factoryName="Cargo Command">
<option name="command" value="test --workspace" />
<option name="workingDirectory" value="file://$PROJECT_DIR$" />
<envs />
<option name="emulateTerminal" value="true" />
<option name="channel" value="DEFAULT" />
<option name="requiredFeatures" value="true" />
<option name="allFeatures" value="false" />
<option name="withSudo" value="false" />
<option name="buildTarget" value="REMOTE" />
<option name="backtrace" value="SHORT" />
<option name="isRedirectInput" value="false" />
<option name="redirectInputPath" value="" />
<method v="2">
<option name="CARGO.BUILD_TASK_PROVIDER" enabled="true" />
</method>
</configuration>
</component>
<component name="RustProjectSettings">
<option name="toolchainHomeDirectory" value="$USER_HOME$/.cargo/bin" />
</component>
<component name="SpellCheckerSettings" RuntimeDictionaries="0" Folders="0" CustomDictionaries="0" DefaultDictionary="application-level" UseSingleDictionary="true" transferred="true" />
<component name="TaskManager">
<task active="true" id="Default" summary="Default task">
<changelist id="7404a252-decc-46ca-a3ce-8225afa42ca8" name="Changes" comment="" />
<created>1723662281778</created>
<option name="number" value="Default" />
<option name="presentableId" value="Default" />
<updated>1723662281778</updated>
<workItem from="1723662282995" duration="187000" />
<workItem from="1723662981939" duration="4684000" />
<workItem from="1725563638440" duration="7000" />
</task>
<servers />
</component>
<component name="TypeScriptGeneratedFilesManager">
<option name="version" value="3" />
</component>
</project>

View File

@ -1,13 +0,0 @@
use ansi_term::ANSIGenericString;
use ansi_term::Colour::RGB;
use std::env::current_dir;
pub const PATH_COL: ansi_term::Colour = RGB(82, 82, 82); //
pub fn pwd() -> ANSIGenericString<'static, str> {
let path = current_dir().map_or_else(
|_| "~~".to_string(),
|path| path.to_string_lossy().to_string(),
);
PATH_COL.italic().paint(path)
}

33
src/indicators/pwd.rs Normal file
View File

@ -0,0 +1,33 @@
use ansi_term::ANSIGenericString;
use ansi_term::Colour::RGB;
use std::env::current_dir;
pub const UNKNOWN_PATH: &str = "\u{2248}"; // "≈"
pub const PATH_COL: ansi_term::Colour = RGB(82, 82, 82);
fn home_dir() -> String {
std::env::var("HOME").map_or_else(
|_| "".to_string(),
|path| path.to_string(),
)
}
fn full_path() -> String {
current_dir().map_or_else(
|_| UNKNOWN_PATH.to_string(),
|path| path.to_string_lossy().to_string(),
)
}
fn replace_home(path: String) -> String {
let homedir = home_dir();
path.replace(&homedir, "~")
}
pub fn pwd(abbrev_home:bool) -> ANSIGenericString<'static, str> {
let mut path = full_path();
if abbrev_home {
path = replace_home(path);
}
PATH_COL.italic().paint(path)
}

View File

@ -1,6 +1,6 @@
use ansi_term::ANSIGenericString;
use ansi_term::Colour::RGB;
use std::env::var_os;
use std::env::var;
// User indicator symbol
pub const USER_SYMBOL: &str = "\u{276F}"; // ""
@ -9,11 +9,8 @@ pub const NORMIE_COL: ansi_term::Colour = RGB(0, 255, 180); // A kind of green
//Root user indicator
pub fn username() -> String {
var_os("USER")
.expect("UnknownUser")
.to_str()
.expect("UnknownUser")
.to_string()
var("USER")
.unwrap_or_else(|_| "UnknownUser".to_string())
}
pub fn indicator() -> ANSIGenericString<'static, str> {

View File

@ -1,14 +1,14 @@
mod indicators {
pub mod error;
pub mod git;
pub mod path;
pub mod pwd;
pub mod ssh;
pub mod user;
}
use crate::indicators::error;
use crate::indicators::git;
use crate::indicators::path;
use crate::indicators::pwd;
use crate::indicators::ssh;
use crate::indicators::user;
@ -21,9 +21,10 @@ fn main() {
let indicate_err: bool = true;
let indicate_git_branch: bool = true;
let pwd: bool = true;
let abbrev_home:bool = true;
if pwd {
prompt += &path::pwd().to_string();
prompt += &pwd::pwd(abbrev_home).to_string();
}
if indicate_ssh {
prompt += &ssh::indicator().to_string();