Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

v2.13.0 #291

Merged
merged 17 commits into from
Apr 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 13 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,19 @@

## Unreleased

## v2.13.0 (2024-04-07)

### Added
- `ignore_case` option to the do case-insensitie search by `/`.
- Symbolic link destinations are now displayed when the cursor is hovered over them.

### Changed
- Symlink items linked to directory now appears in the directory section, not the file section.
- MSRV is now v1.74.1

### fixed
- `z` command can now receive multiple arguments: `z dot files<CR>` works as in your terminal.

## v2.12.1 (2024-02-04)

### Fixed
Expand Down
10 changes: 10 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 2 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[package]
name = "felix"
version = "2.12.1"
version = "2.13.0"
authors = ["Kyohei Uto <[email protected]>"]
edition = "2021"
description = "tui file manager with vim-like key mapping"
Expand Down Expand Up @@ -35,6 +35,7 @@ lzma-rs = "0.3.0"
zstd = "0.12.4"
unicode-width = "0.1.10"
git2 = {version = "0.18.0", default-features = false }
normpath = "1.2.0"

[dev-dependencies]
bwrap = { version = "1.3.0", features = ["use_std"] }
Expand Down
22 changes: 19 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,22 @@ For more detailed document, visit https://kyoheiu.dev/felix.

## New release

## v2.13.0 (2024-04-07)

### Added

- `ignore_case` option to the do case-insensitie search by `/`.
- Symbolic link destinations are now displayed when the cursor is hovered over them.

### Changed

- Symlink items linked to directory now appears in the directory section, not the file section.
- MSRV is now v1.74.1

### fixed

- `z` command can now receive multiple arguments: `z dot files<CR>` works as in your terminal.

## v2.12.1 (2024-02-04)

### Fixed
Expand Down Expand Up @@ -70,16 +86,16 @@ report any problems._

| package | installation command | notes |
| ---------- | --------------------- | ------------------------------------------------------------------------------------------------------------------------------------------- |
| crates.io | `cargo install felix` | Minimum Supported rustc Version: **1.67.1** |
| crates.io | `cargo install felix` | Minimum Supported rustc Version: **1.74.1** |
| Arch Linux | `pacman -S felix-rs` | The binary name is `felix` if you install via pacman. Alias `fx='felix'` if you want, as this document (and other installations) uses `fx`. |
| NetBSD | `pkgin install felix` | |

### From this repository

- Make sure that `gcc` is installed.
- MSRV(Minimum Supported rustc Version): **1.67.1**
- MSRV(Minimum Supported rustc Version): **1.74.1**

Update Rust if rustc < 1.67.1:
Update Rust if rustc < 1.74.1:

```
rustup update
Expand Down
3 changes: 3 additions & 0 deletions config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,9 @@
# 'feh -.':
# [jpg, jpeg, png, gif, svg, hdr]

# Whether to do the case-insensitive search by `/`.
# ignore_case: true

# The foreground color of directory, file and symlink.
# Pick one of the following:
# Black // 0
Expand Down
74 changes: 72 additions & 2 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,11 @@ pub struct Config {
pub default: Option<String>,
pub match_vim_exit_behavior: Option<bool>,
pub exec: Option<BTreeMap<String, Vec<String>>>,
pub ignore_case: Option<bool>,
pub color: Option<ConfigColor>,
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, PartialEq)]
pub struct ConfigColor {
pub dir_fg: Colorname,
pub file_fg: Colorname,
Expand All @@ -42,7 +43,7 @@ impl Default for ConfigColor {
}
}

#[derive(Deserialize, Debug, Clone)]
#[derive(Deserialize, Debug, Clone, PartialEq)]
pub enum Colorname {
Black, // 0
Red, // 1
Expand Down Expand Up @@ -70,6 +71,7 @@ impl Default for Config {
default: Default::default(),
match_vim_exit_behavior: Default::default(),
exec: Default::default(),
ignore_case: Some(false),
color: Some(Default::default()),
}
}
Expand Down Expand Up @@ -141,3 +143,71 @@ pub fn read_config_or_default() -> Result<ConfigWithPath, FxError> {
})
}
}

#[cfg(test)]
mod tests {
use super::*;

#[test]
fn test_read_default_config() {
let default_config: Config = serde_yaml::from_str("").unwrap();
assert_eq!(default_config.default, None);
assert_eq!(default_config.match_vim_exit_behavior, None);
assert_eq!(default_config.exec, None);
assert_eq!(default_config.ignore_case, None);
assert_eq!(default_config.color, None);
}

#[test]
fn test_read_full_config() {
let full_config: Config = serde_yaml::from_str(
r#"
default: nvim
match_vim_exit_behavior: true
exec:
zathura:
[pdf]
'feh -.':
[jpg, jpeg, png, gif, svg, hdr]
ignore_case: true
color:
dir_fg: LightCyan
file_fg: LightWhite
symlink_fg: LightYellow
dirty_fg: Red
"#,
)
.unwrap();
assert_eq!(full_config.default, Some("nvim".to_string()));
assert_eq!(full_config.match_vim_exit_behavior, Some(true));
assert_eq!(
full_config.exec.clone().unwrap().get("zathura"),
Some(&vec!["pdf".to_string()])
);
assert_eq!(
full_config.exec.unwrap().get("feh -."),
Some(&vec![
"jpg".to_string(),
"jpeg".to_string(),
"png".to_string(),
"gif".to_string(),
"svg".to_string(),
"hdr".to_string()
])
);
assert_eq!(full_config.ignore_case, Some(true));
assert_eq!(
full_config.color.clone().unwrap().dir_fg,
Colorname::LightCyan
);
assert_eq!(
full_config.color.clone().unwrap().file_fg,
Colorname::LightWhite
);
assert_eq!(
full_config.color.clone().unwrap().symlink_fg,
Colorname::LightYellow
);
assert_eq!(full_config.color.unwrap().dirty_fg, Colorname::Red);
}
}
54 changes: 29 additions & 25 deletions src/run.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ use crossterm::event::{self, Event, KeyCode, KeyEvent, KeyEventKind, KeyModifier
use crossterm::execute;
use crossterm::terminal::{EnterAlternateScreen, LeaveAlternateScreen};
use log::{error, info};
use normpath::PathExt;
use std::env;
use std::io::{stdout, Write};
use std::panic;
Expand Down Expand Up @@ -118,12 +119,14 @@ pub fn run(arg: PathBuf, log: bool) -> Result<(), FxError> {
let mut state = State::new(&session_path)?;
state.trash_dir = trash_dir_path;
state.lwd_file = lwd_file_path;
state.current_dir = if cfg!(not(windows)) {
// If executed this on windows, "//?" will be inserted at the beginning of the path.
arg.canonicalize()?
} else {
arg
};
let normalized_arg = arg.normalize();
if normalized_arg.is_err() {
return Err(FxError::Arg(format!(
"Invalid path: {}\n`fx -h` shows help.",
&arg.display()
)));
}
state.current_dir = normalized_arg.unwrap().into_path_buf();
state.jumplist.add(&state.current_dir);
state.is_ro = match has_write_permission(&state.current_dir) {
Ok(b) => !b,
Expand Down Expand Up @@ -746,15 +749,7 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
let commands = command
.split_whitespace()
.collect::<Vec<&str>>();
if commands.len() > 2 {
//Invalid argument.
print_warning(
"Invalid argument for zoxide.",
state.layout.y,
);
state.move_cursor(state.layout.y);
break 'zoxide;
} else if commands.len() == 1 {
if commands.len() == 1 {
//go to the home directory
let home_dir =
dirs::home_dir().ok_or_else(|| {
Expand All @@ -770,7 +765,8 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
break 'zoxide;
} else if let Ok(output) =
std::process::Command::new("zoxide")
.args(["query", commands[1]])
.arg("query")
.args(&commands[1..])
.output()
{
let output = output.stdout;
Expand Down Expand Up @@ -1520,11 +1516,18 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {

let key = &keyword.iter().collect::<String>();

let target = state
.list
.iter()
.position(|x| x.file_name.contains(key));

let target = match state.ignore_case {
Some(true) => {
state.list.iter().position(|x| {
x.file_name
.to_lowercase()
.contains(&key.to_lowercase())
})
}
_ => state.list.iter().position(|x| {
x.file_name.contains(key)
}),
};
match target {
Some(i) => {
state.layout.nums.skip = i as u16;
Expand Down Expand Up @@ -2241,12 +2244,13 @@ fn _run(mut state: State, session_path: PathBuf) -> Result<(), FxError> {
} else if commands.len() == 2 && command == "cd" {
if let Ok(target) =
std::path::Path::new(commands[1])
.canonicalize()
.normalize()
{
if target.exists() {
if let Err(e) =
state.chdir(&target, Move::Jump)
{
if let Err(e) = state.chdir(
&target.into_path_buf(),
Move::Jump,
) {
print_warning(e, state.layout.y);
}
break 'command;
Expand Down
Loading
Loading