implemented option to show home directory as '~'
This commit is contained in:
+12
-2
@@ -6,7 +6,7 @@ use std::fs::File;
|
||||
use std::io::{Error, Result};
|
||||
use std::path::PathBuf;
|
||||
use std::str::FromStr;
|
||||
use dirs::config_dir;
|
||||
use dirs::{config_dir, home_dir};
|
||||
|
||||
use super::{config::*, util::to_rooted};
|
||||
use config_parser::{apply_format, make_padding_string, RESET_SEQ};
|
||||
@@ -116,6 +116,16 @@ impl Bookmarks {
|
||||
);
|
||||
|
||||
let mut path = apply_format(path.to_str().unwrap(), &config.styles.bookmarks_path_style);
|
||||
if config.format.book_home_as_tilde {
|
||||
let home = match home_dir() {
|
||||
Some(value) => match value.into_os_string().into_string() {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(Error::other(format!("-- failed to conver home directory to string: {}", error.to_str().unwrap()))),
|
||||
},
|
||||
None => return Err(Error::other("-- `stack_home_as_tilde` = true, but home directory can't be determined")),
|
||||
};
|
||||
path = path.replace(&home, "~");
|
||||
}
|
||||
path = path.replace('/', &format!("{}{}/{}{}", RESET_SEQ, config.styles.bookmarks_punct_style, RESET_SEQ, &config.styles.bookmarks_path_style));
|
||||
|
||||
if config.format.align_separators {
|
||||
@@ -130,7 +140,7 @@ impl Bookmarks {
|
||||
|
||||
/// get bookmarknames as space separated values in one string (for shell completions)
|
||||
pub fn get_bookmarknames(&self) -> String {
|
||||
let mut names: Vec<String> = self.bookmarks.keys().cloned().collect();
|
||||
let names: Vec<String> = self.bookmarks.keys().cloned().collect();
|
||||
names.join(" ")
|
||||
}
|
||||
|
||||
|
||||
@@ -7,6 +7,7 @@ use std::path::{Path, PathBuf};
|
||||
use std::str::FromStr;
|
||||
use config_parser::RESET_SEQ;
|
||||
use sysinfo::{Pid, System};
|
||||
use dirs::home_dir;
|
||||
|
||||
use crate::make_padding_string;
|
||||
use super::{apply_format, config::*, util::to_rooted};
|
||||
@@ -49,6 +50,16 @@ impl Stack {
|
||||
&config.styles.stack_separator_style,
|
||||
);
|
||||
let mut path = apply_format(item.to_str().unwrap(), &config.styles.stack_path_style);
|
||||
if config.format.stack_home_as_tilde {
|
||||
let home = match home_dir() {
|
||||
Some(value) => match value.into_os_string().into_string() {
|
||||
Ok(value) => value,
|
||||
Err(error) => return Err(Error::other(format!("-- failed to conver home directory to string: {}", error.to_str().unwrap()))),
|
||||
},
|
||||
None => return Err(Error::other("-- `stack_home_as_tilde` = true, but home directory can't be determined")),
|
||||
};
|
||||
path = path.replace(&home, "~");
|
||||
}
|
||||
path = path.replace('/', &format!("{}{}/{}{}", RESET_SEQ, config.styles.stack_punct_style, RESET_SEQ, config.styles.stack_path_style));
|
||||
if config.format.align_separators {
|
||||
buffer.push_str(&format!("{}{}{}{}\n", number, padding, separator, path));
|
||||
|
||||
@@ -16,5 +16,7 @@
|
||||
- [x] bookmarks
|
||||
- [x] do not resolve links in bookmarks
|
||||
- [ ] push <number> to push path in stack
|
||||
- [/] write documentation
|
||||
- [x] write documentation
|
||||
- [x] change config file extension to `.toml`
|
||||
- [x] add bash completions
|
||||
- [x] option to show home directory as '~'
|
||||
|
||||
Reference in New Issue
Block a user