diff options
author | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-28 18:51:00 -0400 |
---|---|---|
committer | Jiayi Zhao <jeff.no.zhao@gmail.com> | 2019-06-28 18:51:00 -0400 |
commit | f029183372d70454f092f741dce3c9272b860147 (patch) | |
tree | 4ef933b92bbb0ab33fc6d7f91aa8ffb4520618d9 /src/tab.rs | |
parent | c6a194d9bafd7856c4903e6ad7ba7323f797d2d2 (diff) |
path shortening now uses /home/shana env variable
- fix showing extra '/' in path at root directory
Diffstat (limited to 'src/tab.rs')
-rw-r--r-- | src/tab.rs | 18 |
1 files changed, 14 insertions, 4 deletions
@@ -8,7 +8,7 @@ use crate::ui; use crate::window::{JoshutoPanel, JoshutoView}; use crate::JoshutoConfig; -use crate::{HOSTNAME, USERNAME}; +use crate::{HOME_DIR, HOSTNAME, USERNAME}; use crate::THEME_T; @@ -82,14 +82,24 @@ impl JoshutoTab { ncurses::waddstr(win.win, " "); ncurses::wattron(win.win, ncurses::COLOR_PAIR(THEME_T.directory.colorpair)); + /* shorten $HOME to ~/ */ if tilde_in_titlebar { - let path_str = &path_str.replace(&format!("/home/{}", (*USERNAME).as_str()), "~"); - ncurses::waddstr(win.win, path_str); + if let Some(s) = (*HOME_DIR).as_ref() { + if let Some(s) = s.as_os_str().to_str() { + let path_str = &path_str.replace(s, "~"); + ncurses::waddstr(win.win, path_str); + } + } } else { ncurses::waddstr(win.win, path_str); } - ncurses::waddstr(win.win, "/"); + /* do not print extra '/' if we are at the root directory */ + if let Some(_) = self.curr_path.parent() { + ncurses::waddstr(win.win, "/"); + } + ncurses::wattroff(win.win, ncurses::COLOR_PAIR(THEME_T.directory.colorpair)); + /* print currently selected item */ if let Some(entry) = self.curr_list.get_curr_ref() { ncurses::waddstr(win.win, &entry.file_name()); } |