summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qu3nt1n@gmail.com>2023-01-24 21:47:09 +0100
committerqkzk <qu3nt1n@gmail.com>2023-01-24 21:47:09 +0100
commit5eb19a27798870ea6f28e20aa1a2f372567133bc (patch)
treec5a1cf1c64659abb493b47d0f66d3381e481504b
parentc69d9c01ae61d26e34bb25651804f7a85ed83372 (diff)
add a shortcut to the config folder
-rw-r--r--src/constant_strings_paths.rs2
-rw-r--r--src/shortcut.rs16
2 files changed, 16 insertions, 2 deletions
diff --git a/src/constant_strings_paths.rs b/src/constant_strings_paths.rs
index e7f8876..e5abda6 100644
--- a/src/constant_strings_paths.rs
+++ b/src/constant_strings_paths.rs
@@ -1,5 +1,7 @@
/// Configuration file path
pub static CONFIG_PATH: &str = "~/.config/fm/config.yaml";
+/// Configuration file path
+pub static CONFIG_FOLDER: &str = "~/.config/fm";
/// Default terminal application used when openening a program in shell or starting a new shell
pub static DEFAULT_TERMINAL_APPLICATION: &str = "st";
/// Log file path. Rotating file logs are created in the same directeroy
diff --git a/src/shortcut.rs b/src/shortcut.rs
index 0005fdc..9a78147 100644
--- a/src/shortcut.rs
+++ b/src/shortcut.rs
@@ -2,7 +2,7 @@ use std::borrow::Borrow;
use std::path::{Path, PathBuf};
use std::str::FromStr;
-use crate::constant_strings_paths::HARDCODED_SHORTCUTS;
+use crate::constant_strings_paths::{CONFIG_FOLDER, HARDCODED_SHORTCUTS};
use crate::impl_selectable_content;
/// Holds the hardcoded and mountpoints shortcuts the user can jump to.
@@ -14,6 +14,7 @@ pub struct Shortcut {
pub content: Vec<PathBuf>,
/// The currently selected shortcut
pub index: usize,
+ non_mount_size: usize,
}
impl Default for Shortcut {
@@ -27,9 +28,12 @@ impl Shortcut {
pub fn new() -> Self {
let mut shortcuts = Self::hardcoded_shortcuts();
shortcuts = Self::with_home_path(shortcuts);
+ shortcuts = Self::with_config_folder(shortcuts);
+ let non_mount_size = shortcuts.len();
Self {
content: shortcuts,
index: 0,
+ non_mount_size,
}
}
@@ -48,6 +52,14 @@ impl Shortcut {
shortcuts
}
+ /// Insert a shortcut to config file directory of the current user.
+ pub fn with_config_folder(mut shortcuts: Vec<PathBuf>) -> Vec<PathBuf> {
+ if let Ok(config_folder) = PathBuf::from_str(shellexpand::tilde(CONFIG_FOLDER).borrow()) {
+ shortcuts.push(config_folder);
+ }
+ shortcuts
+ }
+
/// Update the shortcuts with the mount points.
pub fn extend_with_mount_points(&mut self, mount_points: &[&Path]) {
self.content
@@ -57,7 +69,7 @@ impl Shortcut {
/// Refresh the shortcuts. It drops non "hardcoded" shortcuts and
/// extend the vector with the mount points.
pub fn refresh(&mut self, mount_points: &[&Path]) {
- self.content.truncate(HARDCODED_SHORTCUTS.len() + 1);
+ self.content.truncate(self.non_mount_size);
self.extend_with_mount_points(mount_points)
}
}