Skip to content

Commit

Permalink
basename flag added
Browse files Browse the repository at this point in the history
show files basename or relative also path outside of running directory with the -b flag
  • Loading branch information
feddynventor committed Jan 15, 2024
1 parent aa4f1c9 commit 810855c
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 11 deletions.
19 changes: 8 additions & 11 deletions src/list_view.rs
Original file line number Diff line number Diff line change
Expand Up @@ -148,20 +148,17 @@ fn setup_factory(factory: &SignalListItemFactory, list: &MultiSelection) {

// show either relative or absolute path
// This is safe because the file needs to exist
let str = if file_object
let str = if ARGS.get().unwrap().basename || file_object
.file()
.has_parent(Some(CURRENT_DIRECTORY.get().unwrap()))
{
CURRENT_DIRECTORY
.get()
.unwrap()
.relative_path(&file_object.file())
.expect("Can't make a relative path")
.to_str()
.expect("Couldn't read file name")
.has_parent(Some(CURRENT_DIRECTORY.get().unwrap())
) {
file_object.file()
.basename().unwrap()
.to_str().unwrap()
.to_string()
} else {
file_object.file().parse_name().to_string()
file_object.file()
.parse_name().to_string()
};

let label = Label::builder()
Expand Down
4 changes: 4 additions & 0 deletions src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,10 @@ struct Cli {
/// Paths to the files you want to drag
#[arg(value_name = "PATH")]
paths: Vec<PathBuf>,

/// Always show basename of each file
#[arg(short = 'b', long)]
basename: bool,
}

// switch to Lazy Cell when it is stable.
Expand Down

0 comments on commit 810855c

Please sign in to comment.