diff options
author | Canop <cano.petrole@gmail.com> | 2020-01-18 21:49:57 +0100 |
---|---|---|
committer | Canop <cano.petrole@gmail.com> | 2020-01-18 21:49:57 +0100 |
commit | 2c374897f84908f4a4cf724baad441215012b054 (patch) | |
tree | 8ce367ceccfc03e65d0c5ff71ebfee201f60e2de | |
parent | 40046e8f8ba9303cd35724de7b22e9a50c3c03c5 (diff) |
doc & minor changes for :print_relative_path
Fix #169
-rw-r--r-- | CHANGELOG.md | 1 | ||||
-rw-r--r-- | Cargo.lock | 2 | ||||
-rw-r--r-- | src/external.rs | 33 | ||||
-rw-r--r-- | src/help_verbs.rs | 6 | ||||
-rw-r--r-- | website/docs/documentation/configuration.md | 7 |
5 files changed, 15 insertions, 34 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md index dce9b68..0aacda4 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -5,6 +5,7 @@ - consider path `$ZDOTDIR/.zshrc` for zsh shell function sourcing (fix #90) - don't use .gitignore files of parent repositories - change default value of the toggle_trim_root to false (fix #106 but might be reverted) +- `:print_relative_path` verb (fix #169, thanks Roshan George) <a name="v0.11.9"></a> ### v0.11.9 - 2020-01-15 @@ -93,7 +93,7 @@ dependencies = [ [[package]] name = "broot" -version = "0.11.9" +version = "0.12.0" dependencies = [ "chrono 0.4.9 (registry+https://github.com/rust-lang/crates.io-index)", "clap 2.33.0 (registry+https://github.com/rust-lang/crates.io-index)", diff --git a/src/external.rs b/src/external.rs index f0709d4..2af3091 100644 --- a/src/external.rs +++ b/src/external.rs @@ -159,35 +159,16 @@ pub fn print_path(path: &Path, con: &AppContext) -> io::Result<AppStateCmdResult } pub fn print_relative_path(path: &Path, con: &AppContext) -> io::Result<AppStateCmdResult> { - let current_path = match env::current_dir() { - Ok(p) => p, - // Intentionally do not exit since we may want to print the - // absolute path instead, even if we cannot retrieve the cwd - Err(e) => { - return Ok(AppStateCmdResult::DisplayError(format!( - "Cannot determine current working directory: {}", - e.to_string() - ))) - } - }; - - let canonical_path = path.canonicalize()?; - - let relative_path = match pathdiff::diff_paths( - canonical_path.as_path(), - current_path.as_path()) { - None => return Ok(AppStateCmdResult::DisplayError(format!( - "Cannot relativize {} against {}", - canonical_path.to_string_lossy().to_string(), - current_path.to_string_lossy().to_string() - ))), + let relative_path = match pathdiff::diff_paths(path, &con.launch_args.root) { + None => return Ok(AppStateCmdResult::DisplayError( + format!("Cannot relativize {:?}", path) // does this happen ? how ? + )), Some(p) => p, }; - - return if relative_path.to_string_lossy().is_empty() { - print_path(Path::new("."), con) + if relative_path.components().next().is_some() { + print_path(&relative_path, con) } else { - print_path(relative_path.as_path(), con) + print_path(Path::new("."), con) } } diff --git a/src/help_verbs.rs b/src/help_verbs.rs index d5a9b09..b8adad4 100644 --- a/src/help_verbs.rs +++ b/src/help_verbs.rs @@ -70,13 +70,11 @@ impl VerbExecutor for HelpState { AppStateCmdResult::Keep } ":print_path" => external::print_path(&Conf::default_location(), con)?, - ":print_relative_path" => { - external::print_relative_path(&Conf::default_location(), con)? - } + ":print_relative_path" => external::print_relative_path(&Conf::default_location(), con)?, ":quit" => AppStateCmdResult::Quit, ":focus_user_home" | ":focus_root" => AppStateCmdResult::PopStateAndReapply, _ if verb.execution.starts_with(":toggle") => AppStateCmdResult::PopStateAndReapply, - _ if verb.execution.starts_with(':') => AppStateCmdResult::Keep, // other internal verbs do nothing + _ if verb.execution.starts_with(':') => AppStateCmdResult::Keep, _ => verb.to_cmd_result( &Conf::default_location(), &invocation.args, diff --git a/website/docs/documentation/configuration.md b/website/docs/documentation/configuration.md index cff1378..1768630 100644 --- a/website/docs/documentation/configuration.md +++ b/website/docs/documentation/configuration.md @@ -200,12 +200,13 @@ invocation | default key | default shortcut | behavior / details :mkdir {subpath} | - | md | create a directory :mv {newpath} | - | - | move the file or directory to the provided path :open_stay | <kbd>enter</kbd> | - | open the selected file in the default OS opener -:open_leave | <kbd>alt</kbd><kbd>enter</kbd> | - | open the selected file in the default OS opener and leaves broot +:open_leave | <kbd>alt</kbd><kbd>enter</kbd> | - | open the selected file in the default OS opener and leave broot :page_down | <kbd>⇟</kbd> | - | scroll one page down :page_up | <kbd>⇞</kbd> | - | scroll one page up :parent | - | - | focus the parent directory -:print_path | - | pp | print path and leaves broot -:print_tree | - | pt | print tree and leaves broot +:print_path | - | pp | print path and leave broot +:print_relative_path | - | pp | print relative path and leave broot +:print_tree | - | pt | print tree and leave broot :quit | <kbd>ctrl</kbd><kbd>q</kbd> | q | quit broot :refresh | <kbd>F5</kbd> | - | refresh the displayed tree and clears the directory sizes cache :rm | - | - | remove the selected file or directory. To stay safe, don't define a keyboard key for this action |