diff options
author | qkzk <qu3nt1n@gmail.com> | 2022-09-29 21:25:36 +0200 |
---|---|---|
committer | qkzk <qu3nt1n@gmail.com> | 2022-09-29 21:25:36 +0200 |
commit | fa0632d64dd8b701a7f9faa5375ce0f430ff68bb (patch) | |
tree | cef7af1654ea94662d2c67111ff909680b3f26e9 | |
parent | 2fd9bda24ffe78b27501b353c0be946ff4a32f51 (diff) |
nvim file pickernvim-file-picker
-rw-r--r-- | readme.md | 2 | ||||
-rw-r--r-- | src/args.rs | 63 | ||||
-rw-r--r-- | src/args_better.rs | 18 | ||||
-rw-r--r-- | src/lib.rs | 2 | ||||
-rw-r--r-- | src/main.rs | 104 |
5 files changed, 73 insertions, 116 deletions
@@ -60,6 +60,8 @@ ## TODO - [ ] remote control + - [x] filepicker + requires the nvim-remote rust crate installed - [ ] listen to stdin (rcv etc.) - [ ] follow change directory - [ ] when called from a file buffer in nvim, open with this file selected diff --git a/src/args.rs b/src/args.rs deleted file mode 100644 index a715d582..00000000 --- a/src/args.rs +++ /dev/null @@ -1,63 +0,0 @@ -// use std::collections::HashMap; -// use std::env; -// -// #[derive(Debug)] -// pub struct Args { -// pub hidden: bool, // "-a" -// pub path: String, // "/usr/bin" -// pub help: bool, -// } -// impl Default for Args { -// fn default() -> Self { -// Args { -// hidden: false, -// path: String::from("."), -// help: false, -// } -// } -// } -// -// impl Args { -// pub fn new(args: env::Args) -> Result<Args, &'static str> { -// match args.len() { -// 1 => Ok(Args { -// ..Default::default() -// }), -// _ => { -// let (path, map_options) = parse_args(args); -// Ok(Args { -// path, -// hidden: map_options[&String::from("a")], -// help: map_options[&String::from("h")], -// }) -// } -// } -// } -// } -// -// pub fn default_map_options() -> ([String; 2], HashMap<String, bool>) { -// let arr_options: [String; 2] = [String::from("a"), String::from("h")]; -// let mut map_options = HashMap::new(); -// for opt in arr_options.iter() { -// map_options.insert(String::from(opt), false); -// } -// (arr_options, map_options) -// } -// -// pub fn parse_args(mut args: env::Args) -> (String, HashMap<String, bool>) { -// let mut path = String::from("."); -// let (arr_options, mut map_options) = default_map_options(); -// args.next(); -// for arg in args { -// if arg.starts_with('-') { -// for opt in &arr_options { -// if arg.contains(opt) { -// map_options.insert(String::from(opt), true); -// } -// } -// } else { -// path = arg; -// } -// } -// (path, map_options) -// } diff --git a/src/args_better.rs b/src/args_better.rs deleted file mode 100644 index 00b7364a..00000000 --- a/src/args_better.rs +++ /dev/null @@ -1,18 +0,0 @@ -#![allow(unused)] - -use clap::Parser; - -/// Search for a pattern in a file and display the lines that contain it. -#[derive(Parser)] -pub struct Args { - /// The path to the file to read - pub path: std::path::PathBuf, - /// hidden - pub hidden: bool, - pub help: bool, - pub server: Option<String>, -} - -fn main() { - let args = Args::parse(); -} @@ -1,4 +1,2 @@ -pub mod args; -// pub mod args_better; pub mod config; pub mod fileinfo; diff --git a/src/main.rs b/src/main.rs index f11f4298..dfd10443 100644 --- a/src/main.rs +++ b/src/main.rs @@ -6,8 +6,8 @@ use std::collections::HashSet; use std::fmt; use std::fs; use std::os::unix::fs::PermissionsExt; +use std::path; use std::process::Command; -use std::{env, path, process}; use regex::Regex; use tuikit::attr::*; @@ -21,24 +21,51 @@ use fm::fileinfo::{FileInfo, FileKind, PathContent}; pub mod fileinfo; -// use clap::Parser; -// -// /// Search for a pattern in a file and display the lines that contain it. -// #[derive(Parser, Debug)] -// pub struct Args { -// /// The path to the file to read -// pub path: std::path::PathBuf, -// /// hidden -// pub hidden: bool, -// pub help: bool, -// pub server: Option<String>, -// } - use clap::Parser; -/// FM : dired like file manager #[derive(Parser, Debug)] -#[command(author, version, about, long_about = None)] +#[clap(author, version, about)] +/// FM : dired like file manager{n} +/// Default key bindings:{n} +///{n} +/// q: quit{n} +/// h: help{n} +///{n} +/// - Navigation -{n} +/// ←: cd to parent directory{n} +/// →: cd to child directory{n} +/// ↑: one line up {n} +/// ↓: one line down{n} +/// Home: go to first line{n} +/// End: go to last line{n} +/// PgUp: 10 lines up{n} +/// PgDown: 10 lines down{n} +///{n} +/// a: toggle hidden{n} +/// s: shell in current directory{n} +/// o: xdg-open this file{n} +/// i: open with current NVIM session{n} +///{n} +/// - Action on flagged files -{n} +/// space: toggle flag on a file{n} +/// *: flag all{n} +/// u: clear flags{n} +/// v: reverse flags{n} +/// c: copy to current dir{n} +/// p: move to current dir{n} +/// x: delete flagged files{n} +///{n} +/// - MODES -{n} +/// m: CHMOD{n} +/// e: EXEC{n} +/// d: NEWDIR{n} +/// n: NEWFILE{n} +/// r: RENAME{n} +/// g: GOTO{n} +/// w: REGEXMATCH{n} +/// j: JUMP{n} +/// Enter: Execute mode then NORMAL{n} +/// Esc: NORMAL{n} struct Args { /// Starting path #[arg(short, long, default_value_t = String::from("."))] @@ -59,19 +86,19 @@ const EDIT_BOX_OFFSET: usize = 10; const MAX_PERMISSIONS: u32 = 0o777; static CONFIG_PATH: &str = "~/.config/fm/config.yaml"; -static USAGE: &str = " -FM: dired inspired File Manager - -dired [flags] [path] -flags: --a display hidden files --h show help and exit -"; +// static USAGE: &str = " +// FM: dired inspired File Manager +// +// dired [flags] [path] +// flags: +// -a display hidden files +// -h show help and exit +// "; static HELP_LINES: &str = " Default key bindings: q: quit -?: help +h: help - Navigation - ←: cd to parent directory @@ -276,10 +303,10 @@ fn execute_in_child(exe: &str, args: &Vec<&str>) -> std::process::Child { Command::new(exe).args(args).spawn().unwrap() } -fn help() { - print!("{}", USAGE); - print!("{}", HELP_LINES); -} +// fn help() { +// print!("{}", USAGE); +// print!("{}", HELP_LINES); +// } #[derive(Debug)] enum LastEdition { @@ -575,7 +602,7 @@ impl Status { } else if c == self.config.keybindings.jump { self.event_jump(); } else if c == self.config.keybindings.nvim { - self.event_nvim(); + self.event_nvim_filepicker(); } } Mode::Help => { @@ -775,15 +802,26 @@ impl Status { } } - fn event_nvim(&mut self) { + 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()); + if server.is_empty() { + return; + } execute_in_child( "nvim-send", &vec![ "--remote-send", - "<esc>:bn readme.md<cr>", + &format!( + "<esc>:e {}<cr><esc>:close<cr>", + self.path_content.files[self.file_index] + .path + .clone() + .to_str() + .unwrap() + ), "--servername", - "/run/user/1000/nvim.22399.0", + &server, ], ); } |