summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorqkzk <qkzk@users.noreply.github.com>2022-10-04 21:18:44 +0200
committerGitHub <noreply@github.com>2022-10-04 21:18:44 +0200
commit5892f31ba4d6ff2014c6f46e0f0b33518b23bf9f (patch)
tree8fa3354562215a3179a3db1edd49640fb22084c3
parent1abc200489cefcdda7ebfb6e8e9ba532b783643b (diff)
parent09f345b791c58421257670e23a2780003c670f3c (diff)
Merge pull request #19 from qkzk/symlink
Symlink
-rw-r--r--config.yaml1
-rw-r--r--readme.md1
-rw-r--r--src/actioner.rs1
-rw-r--r--src/config.rs11
-rw-r--r--src/event_char.rs2
-rw-r--r--src/help.rs1
-rw-r--r--src/status.rs15
7 files changed, 30 insertions, 2 deletions
diff --git a/config.yaml b/config.yaml
index a8d8ccf1..bc9c61ea 100644
--- a/config.yaml
+++ b/config.yaml
@@ -39,3 +39,4 @@ keybindings:
jump: j
nvim: i
sort_by: O
+ symlink: S
diff --git a/readme.md b/readme.md
index 0a19b89e..e1ba5cdb 100644
--- a/readme.md
+++ b/readme.md
@@ -64,6 +64,7 @@
- [x] association with match and clear code
- [x] dissociate keybinding from status update
- [x] fix: cursor is hidden before leaving the application
+- [x] create a symlink to flagged files
## TODO
diff --git a/src/actioner.rs b/src/actioner.rs
index f41be0e2..490c07fe 100644
--- a/src/actioner.rs
+++ b/src/actioner.rs
@@ -42,6 +42,7 @@ impl Actioner {
(keybindings.jump, EventChar::Jump),
(keybindings.nvim, EventChar::NvimFilepicker),
(keybindings.sort_by, EventChar::Sort),
+ (keybindings.symlink, EventChar::Symlink),
]);
Self { binds }
}
diff --git a/src/config.rs b/src/config.rs
index 1d7a6b26..9bc9ff84 100644
--- a/src/config.rs
+++ b/src/config.rs
@@ -30,6 +30,7 @@ use tuikit::attr::Color;
/// copy_paste: c
/// cut_paste: p
/// delete: x
+/// symlink: S
/// chmod: m
/// exec: e
/// newdir: d
@@ -197,6 +198,8 @@ pub struct Keybindings {
pub nvim: char,
/// Change file sorting.
pub sort_by: char,
+ /// Creates asymlink
+ pub symlink: char,
}
impl Keybindings {
@@ -269,8 +272,11 @@ impl Keybindings {
if let Some(nvim) = yaml["nvim"].as_str().map(|s| s.to_string()) {
self.nvim = nvim.chars().next().unwrap_or('i');
}
- if let Some(nvim) = yaml["sort_by"].as_str().map(|s| s.to_string()) {
- self.nvim = nvim.chars().next().unwrap_or('O');
+ if let Some(sort_by) = yaml["sort_by"].as_str().map(|s| s.to_string()) {
+ self.sort_by = sort_by.chars().next().unwrap_or('O');
+ }
+ if let Some(symlink) = yaml["symblink"].as_str().map(|s| s.to_string()) {
+ self.symlink = symlink.chars().next().unwrap_or('S');
}
}
@@ -300,6 +306,7 @@ impl Keybindings {
jump: 'j',
nvim: 'i',
sort_by: 'O',
+ symlink: 'S',
}
}
}
diff --git a/src/event_char.rs b/src/event_char.rs
index ed8a53a5..7f48d5cf 100644
--- a/src/event_char.rs
+++ b/src/event_char.rs
@@ -24,6 +24,7 @@ pub enum EventChar {
Jump,
NvimFilepicker,
Sort,
+ Symlink,
}
impl EventChar {
@@ -52,6 +53,7 @@ impl EventChar {
EventChar::Jump => status.event_jump(),
EventChar::NvimFilepicker => status.event_nvim_filepicker(),
EventChar::Sort => status.event_sort(),
+ EventChar::Symlink => status.event_symlink(),
}
}
}
diff --git a/src/help.rs b/src/help.rs
index 10492337..c03b086e 100644
--- a/src/help.rs
+++ b/src/help.rs
@@ -28,6 +28,7 @@ o: xdg-open this file
c: copy to current dir
p: move to current dir
x: delete flagged files
+ S: symlink flagged files
- MODES -
m: CHMOD
diff --git a/src/status.rs b/src/status.rs
index f9296c88..f4000276 100644
--- a/src/status.rs
+++ b/src/status.rs
@@ -393,6 +393,21 @@ impl Status {
self.input.replace(self.completion.current_proposition())
}
+ /// Creates a symlink of every flagged file to the current directory.
+ pub fn event_symlink(&mut self) {
+ self.flagged.iter().for_each(|oldpath| {
+ let newpath = self
+ .path_content
+ .path
+ .clone()
+ .join(oldpath.as_path().file_name().unwrap());
+ std::os::unix::fs::symlink(oldpath, newpath).unwrap_or(());
+ });
+ self.flagged.clear();
+ self.path_content.reset_files();
+ self.window.reset(self.path_content.files.len());
+ }
+
pub fn event_nvim_filepicker(&mut self) {
// "nvim-send --remote-send '<esc>:e readme.md<cr>' --servername 127.0.0.1:8888"
let server = std::env::var("NVIM_LISTEN_ADDRESS").unwrap_or_else(|_| "".to_owned());