fix: file list expansion arguments ($@, $*) of shell command under opener rules are out of order (#890)

This commit is contained in:
三咲雅 · Misaki Masa 2024-04-10 08:31:03 +08:00 committed by GitHub
parent 884de41b66
commit e7dc971416
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
8 changed files with 28 additions and 24 deletions

View File

@ -15,7 +15,7 @@ impl Manager {
}; };
let cwd = self.cwd().clone(); let cwd = self.cwd().clone();
let old: Vec<_> = self.selected_or_hovered(true); let old: Vec<_> = self.selected_or_hovered(true).collect();
let root = max_common_root(&old); let root = max_common_root(&old);
let old: Vec<_> = old.into_iter().map(|p| p.strip_prefix(&root).unwrap().to_owned()).collect(); let old: Vec<_> = old.into_iter().map(|p| p.strip_prefix(&root).unwrap().to_owned()).collect();

View File

@ -33,7 +33,9 @@ impl Manager {
}; };
let opt = opt.into() as Opt; let opt = opt.into() as Opt;
let selected = if opt.hovered { vec![&hovered] } else { self.selected_or_hovered(false) }; let selected =
if opt.hovered { vec![&hovered] } else { self.selected_or_hovered(true).collect() };
if Self::quit_with_selected(&selected) { if Self::quit_with_selected(&selected) {
return; return;
} }

View File

@ -27,7 +27,7 @@ impl Manager {
} }
let mut opt = opt.into() as Opt; let mut opt = opt.into() as Opt;
opt.targets = self.selected_or_hovered(false).into_iter().cloned().collect(); opt.targets = self.selected_or_hovered(false).cloned().collect();
if opt.force { if opt.force {
return self.remove_do(opt, tasks); return self.remove_do(opt, tasks);

View File

@ -17,10 +17,8 @@ impl Manager {
return; return;
} }
self.yanked = Yanked { self.yanked =
cut: opt.into().cut, Yanked { cut: opt.into().cut, urls: self.selected_or_hovered(false).cloned().collect() };
urls: self.selected_or_hovered(false).into_iter().cloned().collect(),
};
self.active_mut().escape_select(); self.active_mut().escape_select();
Pubsub::pub_from_yank(self.yanked.cut, &self.yanked.urls); Pubsub::pub_from_yank(self.yanked.cut, &self.yanked.urls);

View File

@ -53,10 +53,12 @@ impl Manager {
pub fn hovered_folder(&self) -> Option<&Folder> { self.tabs.active().hovered_folder() } pub fn hovered_folder(&self) -> Option<&Folder> { self.tabs.active().hovered_folder() }
#[inline] #[inline]
pub fn selected_or_hovered(&self, sorted: bool) -> Vec<&Url> { pub fn selected_or_hovered(&self, reorder: bool) -> Box<dyn Iterator<Item = &Url> + '_> {
self.tabs.active().selected_or_hovered(sorted) self.tabs.active().selected_or_hovered(reorder)
} }
#[inline] #[inline]
pub fn hovered_and_selected(&self) -> Vec<&Url> { self.tabs.active().hovered_and_selected() } pub fn hovered_and_selected(&self, reorder: bool) -> Box<dyn Iterator<Item = &Url> + '_> {
self.tabs.active().hovered_and_selected(reorder)
}
} }

View File

@ -20,7 +20,7 @@ impl Tab {
} }
let mut s = OsString::new(); let mut s = OsString::new();
let mut it = self.selected_or_hovered(true).into_iter().peekable(); let mut it = self.selected_or_hovered(true).peekable();
while let Some(u) = it.next() { while let Some(u) = it.next() {
s.push(match opt.type_.as_str() { s.push(match opt.type_.as_str() {
"path" => u.as_os_str(), "path" => u.as_os_str(),

View File

@ -31,7 +31,7 @@ impl Tab {
} }
let mut opt = opt.into() as Opt; let mut opt = opt.into() as Opt;
let selected = self.hovered_and_selected().into_iter().cloned().collect(); let selected = self.hovered_and_selected(true).cloned().collect();
tokio::spawn(async move { tokio::spawn(async move {
if !opt.confirm || opt.run.is_empty() { if !opt.confirm || opt.run.is_empty() {

View File

@ -1,4 +1,4 @@
use std::collections::HashMap; use std::{collections::HashMap, iter};
use anyhow::Result; use anyhow::Result;
use tokio::task::JoinHandle; use tokio::task::JoinHandle;
@ -34,27 +34,29 @@ impl Tab {
impl Tab { impl Tab {
// --- Current // --- Current
pub fn selected_or_hovered(&self, sorted: bool) -> Vec<&Url> { pub fn selected_or_hovered(&self, reorder: bool) -> Box<dyn Iterator<Item = &Url> + '_> {
if self.selected.is_empty() { if self.selected.is_empty() {
self.current.hovered().map(|h| vec![&h.url]).unwrap_or_default() Box::new(self.current.hovered().map(|h| vec![&h.url]).unwrap_or_default().into_iter())
} else if !sorted { } else if !reorder {
self.selected.keys().collect() Box::new(self.selected.keys())
} else { } else {
let mut vec: Vec<_> = self.selected.iter().collect(); let mut vec: Vec<_> = self.selected.iter().collect();
vec.sort_unstable_by(|a, b| a.1.cmp(b.1)); vec.sort_unstable_by(|a, b| a.1.cmp(b.1));
vec.into_iter().map(|(k, _)| k).collect() Box::new(vec.into_iter().map(|(k, _)| k))
} }
} }
pub fn hovered_and_selected(&self) -> Vec<&Url> { pub fn hovered_and_selected(&self, reorder: bool) -> Box<dyn Iterator<Item = &Url> + '_> {
let Some(h) = self.current.hovered() else { let Some(h) = self.current.hovered() else { return Box::new(iter::empty()) };
return vec![];
};
if self.selected.is_empty() { if self.selected.is_empty() {
vec![&h.url, &h.url] Box::new([&h.url, &h.url].into_iter())
} else if !reorder {
Box::new([&h.url].into_iter().chain(self.selected.keys()))
} else { } else {
[&h.url].into_iter().chain(self.selected.keys()).collect() let mut vec: Vec<_> = self.selected.iter().collect();
vec.sort_unstable_by(|a, b| a.1.cmp(b.1));
Box::new([&h.url].into_iter().chain(vec.into_iter().map(|(k, _)| k)))
} }
} }