Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add CLI option to disable CWD module elipsis. #23

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,12 @@ pub fn build_cli() -> App<'static, 'static> {
.value_name("int")
.default_value("15")
)
.arg(
Arg::with_name("cwd-no-ellipsis")
.long("cwd-no-ellipsis")
.help("Disable ellipsis when path component is too long.")
.takes_value(false)
)
.arg(
Arg::with_name("error")
.help("Exit code of previously executed command")
Expand Down
3 changes: 2 additions & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ fn main() {

let cwd_max_depth = value_t_or_exit!(matches, "cwd-max-depth", u8);
let cwd_max_dir_size = value_t_or_exit!(matches, "cwd-max-dir-size", u8);
let cwd_no_ellipsis = matches.is_present("cwd-no-ellipsis");
let error = value_t_or_exit!(matches, "error", u8);

#[cfg(feature = "flame")]
Expand Down Expand Up @@ -98,7 +99,7 @@ fn main() {

for module in modules {
match module {
Module::Cwd => segments::segment_cwd(&mut p, cwd_max_depth, cwd_max_dir_size),
Module::Cwd => segments::segment_cwd(&mut p, cwd_max_depth, cwd_max_dir_size, cwd_no_ellipsis),
Module::Git => { #[cfg(feature = "git2")] segments::segment_git(&mut p) },
Module::GitStage => { #[cfg(feature = "git2")] segments::segment_gitstage(&mut p) },
Module::Host => segments::segment_host(&mut p),
Expand Down
12 changes: 7 additions & 5 deletions src/segments/segment_cwd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ use std::{
path::PathBuf
};

pub fn segment_cwd(p: &mut Powerline, cwd_max_depth: u8, cwd_max_dir_size: u8) {
pub fn segment_cwd(p: &mut Powerline, cwd_max_depth: u8, cwd_max_dir_size: u8, cwd_no_ellipsis: bool) {
let mut path = env::current_dir().unwrap_or_else(|_| PathBuf::from("error"));
if let Some(home) = dirs::home_dir() {
let mut new_path = None;
Expand All @@ -28,7 +28,7 @@ pub fn segment_cwd(p: &mut Powerline, cwd_max_depth: u8, cwd_max_dir_size: u8) {
if cwd_max_depth != 1 {
if let Some(dir) = dirs.next() {
// Either there's no cwd_max_depth, or it's bigger than 1
segment(p, dir, length == 1, cwd_max_dir_size);
segment(p, dir, length == 1, cwd_max_dir_size, cwd_no_ellipsis);

// It would be sane here to subtract 1 from both length and
// cwd_max_depth, to make it clear that we already tried one and
Expand All @@ -48,10 +48,10 @@ pub fn segment_cwd(p: &mut Powerline, cwd_max_depth: u8, cwd_max_dir_size: u8) {
while let Some(cursor) = next {
next = dirs.next();

segment(p, cursor, next.is_none(), cwd_max_dir_size);
segment(p, cursor, next.is_none(), cwd_max_dir_size, cwd_no_ellipsis);
}
}
pub fn segment(p: &mut Powerline, name: &OsStr, last: bool, cwd_max_dir_size: u8) {
pub fn segment(p: &mut Powerline, name: &OsStr, last: bool, cwd_max_dir_size: u8, cwd_no_ellipsis: bool) {
let mut name = name.to_string_lossy().into_owned();

let cwd_max_dir_size = cwd_max_dir_size as usize;
Expand All @@ -61,7 +61,9 @@ pub fn segment(p: &mut Powerline, name: &OsStr, last: bool, cwd_max_dir_size: u8
start += c.len_utf8();
}
name.drain(start..);
name.push('…');
if !cwd_no_ellipsis {
name.push('…');
}
}

let fg = if last { p.theme.cwd_fg } else { p.theme.path_fg };
Expand Down