Commit 9fe600c632
9fe600c63281130d547f1012adc840b6da298f86
parent: 7d66421863
Unregistered key
Ulyssa <git@ulyssa.dev> · 2026-09-19 00:24 UTC
committer: <noreply@github.com>
Update `:open` and `:download` to also expand `~` (#716)
Layout: unified · split
src/base.rs
+2 −2
| @@ -99,7 +99,7 @@ pub enum MessageAction { |
| 99 | 99 | /// |
| 100 | 100 | /// The second argument controls whether to overwrite any already existing file at the |
| 101 | 101 | /// destination path, or to open the attachment after downloading. |
| 102 | | Download(Option<String>, DownloadFlags), |
| 102 | Download(Option<PathBuf>, DownloadFlags), |
| 103 | 103 | |
| 104 | 104 | /// Edit a sent message. |
| 105 | 105 | Edit, |
| @@ -525,7 +525,7 @@ pub enum SendAction { |
| 525 | 525 | /// |
| 526 | 526 | /// The second argument indicates whether to use the messagebar as a caption, don't use it or |
| 527 | 527 | /// ask the user. |
| 528 | | Upload(String, Option<bool>), |
| 528 | Upload(PathBuf, Option<bool>), |
| 529 | 529 | |
| 530 | 530 | /// Upload the image data. |
| 531 | 531 | /// |
src/commands.rs
+4 −7
| @@ -965,17 +965,14 @@ fn iamb_space(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 965 | 965 | } |
| 966 | 966 | |
| 967 | 967 | fn iamb_upload(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 968 | | let mut args = desc.arg.strings()?; |
| 968 | let mut args = desc.arg.paths()?; |
| 969 | 969 | |
| 970 | 970 | if args.len() != 1 { |
| 971 | 971 | return Result::Err(CommandError::InvalidArgument); |
| 972 | 972 | } |
| 973 | 973 | |
| 974 | 974 | let path = args.remove(0); |
| 975 | | let expanded_path = |
| 976 | | shellexpand::full(&path).map_err(|e| CommandError::ParseFailed(e.to_string()))?; |
| 977 | | |
| 978 | | let sact = SendAction::Upload(expanded_path.into_owned(), None); |
| 975 | let sact = SendAction::Upload(path, None); |
| 979 | 976 | let iact = IambAction::from(sact); |
| 980 | 977 | let step = CommandStep::Continue(iact.into(), ctx.context.clone()); |
| 981 | 978 | |
| @@ -983,7 +980,7 @@ fn iamb_upload(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 983 | 980 | } |
| 984 | 981 | |
| 985 | 982 | fn iamb_download(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 986 | | let mut args = desc.arg.strings()?; |
| 983 | let mut args = desc.arg.paths()?; |
| 987 | 984 | |
| 988 | 985 | if args.len() > 1 { |
| 989 | 986 | return Result::Err(CommandError::InvalidArgument); |
| @@ -1001,7 +998,7 @@ fn iamb_download(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult |
| 1001 | 998 | } |
| 1002 | 999 | |
| 1003 | 1000 | fn iamb_open(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
| 1004 | | let mut args = desc.arg.strings()?; |
| 1001 | let mut args = desc.arg.paths()?; |
| 1005 | 1002 | |
| 1006 | 1003 | if args.len() > 1 { |
| 1007 | 1004 | return Result::Err(CommandError::InvalidArgument); |
src/windows/room/chat.rs
+4 −5
| @@ -181,7 +181,7 @@ impl ChatState { |
| 181 | 181 | |
| 182 | 182 | let media = client.media(); |
| 183 | 183 | let mut filename = match (filename, &settings.dirs.downloads) { |
| 184 | | (Some(f), _) => PathBuf::from(f), |
| 184 | (Some(f), _) => f, |
| 185 | 185 | (None, Some(downloads)) => downloads.clone(), |
| 186 | 186 | (None, None) => return Err(IambError::NoDownloadDir.into()), |
| 187 | 187 | }; |
| @@ -684,11 +684,10 @@ impl ChatState { |
| 684 | 684 | return Err(UIError::NeedConfirm(prompt)); |
| 685 | 685 | } |
| 686 | 686 | |
| 687 | | let path = Path::new(file.as_str()); |
| 688 | | let mime = mime_guess::from_path(path).first_or(mime::APPLICATION_OCTET_STREAM); |
| 687 | let mime = mime_guess::from_path(&file).first_or(mime::APPLICATION_OCTET_STREAM); |
| 689 | 688 | |
| 690 | | let bytes = fs::read(path)?; |
| 691 | | let name = path |
| 689 | let bytes = fs::read(&file)?; |
| 690 | let name = file |
| 692 | 691 | .file_name() |
| 693 | 692 | .map(OsStr::to_string_lossy) |
| 694 | 693 | .unwrap_or_else(|| Cow::from("Attachment")); |