Skip to content

Commit

Permalink
Merge pull request #10 from Araxeus/fix_unix
Browse files Browse the repository at this point in the history
Unix Fix
  • Loading branch information
Araxeus authored May 21, 2022
2 parents 53c39ad + 75ed70c commit 50e4cca
Show file tree
Hide file tree
Showing 5 changed files with 34 additions and 12 deletions.
2 changes: 1 addition & 1 deletion Cargo.lock

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

11 changes: 9 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@

🌟 Browse folders using <kbd>Enter</kbd>

🌟 Open folder in terminal (cd to folder) using <kbd>Shift</kbd> + <kbd>Enter</kbd>
🌟 Open folder in terminal (cd to folder) using [<kbd>Shift</kbd> + <kbd>Enter</kbd>] or [<kbd>Alt</kbd> + <kbd>Enter</kbd>]

🌟 Open folder in file manager using <kbd>Ctrl</kbd> + <kbd>Enter</kbd>

Expand All @@ -33,12 +33,19 @@

🌟 Type anything to filter current folder content using fuzzy search

> on Linux/Mac <kbd>Shift</kbd> + <kbd>Enter</kbd> or <kbd>Ctrl</kbd> + <kbd>Enter</kbd> might not work
>
> see https://github.com/crossterm-rs/crossterm/issues/669
## 🛠 Installation

1. Download zip package from [releases page](https://github.com/Araxeus/ls-interactive/releases)
2. extract its content into a folder in PATH ([guide](https://gist.github.com/nex3/c395b2f8fd4b02068be37c961301caa7))

Installation from package managers is Coming Soon™
#### Linux/Mac
Copy the function in [lsi.sh](https://github.com/Araxeus/ls-interactive/blob/master/scripts/lsi.sh) into to `/home/user/.bashrc`

(You need only the ls-interactive file in your PATH, since lsi is defined in your bash startup file)

## 💻 How to run it

Expand Down
10 changes: 7 additions & 3 deletions scripts/lsi.sh
Original file line number Diff line number Diff line change
@@ -1,4 +1,8 @@
#!/bin/bash
#add the following function to /home/user/.bashrc

output=$("$(dirname "$0")/ls-interactive")
[ -n "$output" ] && cd "$(output)"
lsi() {
local output
if output=$(ls-interactive "$@") && [[ $output ]] ; then
cd "$output"
fi
}
11 changes: 7 additions & 4 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ mod utils;
use std::{env, fs, path::Path};

use structs::{Entry, Filetype, Icons};
use utils::{display_choices, err, resolve_lnk, KeyModifiers};
use utils::{display_choices, err, pretty_path, resolve_lnk, KeyModifiers};

fn main() {
human_panic::setup_panic!();
Expand Down Expand Up @@ -35,7 +35,10 @@ fn main_loop(initial_path: String) {
// quit if file was opened
Ok(_) => break,
// else display error and open as directory
Err(_) => err(format!("Failed to open file \"{}\"", &entry.path[4..])),
Err(_) => err(format!(
"Failed to open file \"{}\"",
pretty_path(&entry.path)
)),
}
}
// browse directory by continuing loop with new path
Expand All @@ -45,8 +48,8 @@ fn main_loop(initial_path: String) {
entry.path.to_string()
};

if modifier == KeyModifiers::SHIFT {
print!("{}", &path[4..]);
if modifier == KeyModifiers::SHIFT || modifier == KeyModifiers::ALT {
print!("{}", pretty_path(&path));
break;
}
}
Expand Down
12 changes: 10 additions & 2 deletions src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ pub fn resolve_lnk(path: &String) -> String {
mem::drop(panic::take_hook());

if link.is_err() {
err(format!("Failed to read shortcut \"{}\"", &path[4..]));
err(format!("Failed to read shortcut \"{}\"", pretty_path(path)));
return path.to_string();
}

Expand All @@ -40,7 +40,7 @@ pub fn resolve_lnk(path: &String) -> String {
// returns the index of the selected choice
pub fn display_choices(items: &[Entry], path: &str) -> (usize, KeyModifiers) {
match FuzzySelect::with_theme(&ColorfulTheme::default())
.with_prompt(&path[4..])
.with_prompt(pretty_path(path))
.report(false)
.items(items)
.default(0)
Expand All @@ -52,3 +52,11 @@ pub fn display_choices(items: &[Entry], path: &str) -> (usize, KeyModifiers) {
None => process::exit(0),
}
}

pub fn pretty_path(path: &str) -> &str {
if cfg!(windows) {
&path[4..]
} else {
path
}
}

0 comments on commit 50e4cca

Please sign in to comment.