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 | /// The second argument controls whether to overwrite any already existing file at the |
100 | /// The second argument controls whether to overwrite any already existing file at the |
| 101 | /// destination path, or to open the attachment after downloading. |
101 | /// destination path, or to open the attachment after downloading. |
| 102 | Download(Option<String>, DownloadFlags), |
102 | Download(Option<PathBuf>, DownloadFlags), |
| 103 | |
103 | |
| 104 | /// Edit a sent message. |
104 | /// Edit a sent message. |
| 105 | Edit, |
105 | Edit, |
| @@ -525,7 +525,7 @@ pub enum SendAction { |
| 525 | /// |
525 | /// |
| 526 | /// The second argument indicates whether to use the messagebar as a caption, don't use it or |
526 | /// The second argument indicates whether to use the messagebar as a caption, don't use it or |
| 527 | /// ask the user. |
527 | /// ask the user. |
| 528 | Upload(String, Option<bool>), |
528 | Upload(PathBuf, Option<bool>), |
| 529 | |
529 | |
| 530 | /// Upload the image data. |
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 | fn iamb_upload(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
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 | if args.len() != 1 { |
970 | if args.len() != 1 { |
| 971 | return Result::Err(CommandError::InvalidArgument); |
971 | return Result::Err(CommandError::InvalidArgument); |
| 972 | } |
972 | } |
| 973 | |
973 | |
| 974 | let path = args.remove(0); |
974 | let path = args.remove(0); |
| 975 | let expanded_path = |
975 | let sact = SendAction::Upload(path, None); |
| 976 | shellexpand::full(&path).map_err(|e| CommandError::ParseFailed(e.to_string()))?; |
| |
| 977 | |
| |
| 978 | let sact = SendAction::Upload(expanded_path.into_owned(), None); |
| |
| 979 | let iact = IambAction::from(sact); |
976 | let iact = IambAction::from(sact); |
| 980 | let step = CommandStep::Continue(iact.into(), ctx.context.clone()); |
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 | fn iamb_download(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
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 | if args.len() > 1 { |
985 | if args.len() > 1 { |
| 989 | return Result::Err(CommandError::InvalidArgument); |
986 | return Result::Err(CommandError::InvalidArgument); |
| @@ -1001,7 +998,7 @@ fn iamb_download(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult |
| 1001 | } |
998 | } |
| 1002 | |
999 | |
| 1003 | fn iamb_open(desc: CommandDescription, ctx: &mut ProgContext) -> ProgResult { |
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 | if args.len() > 1 { |
1003 | if args.len() > 1 { |
| 1007 | return Result::Err(CommandError::InvalidArgument); |
1004 | return Result::Err(CommandError::InvalidArgument); |
src/windows/room/chat.rs
+4 −5
| @@ -181,7 +181,7 @@ impl ChatState { |
| 181 | |
181 | |
| 182 | let media = client.media(); |
182 | let media = client.media(); |
| 183 | let mut filename = match (filename, &settings.dirs.downloads) { |
183 | let mut filename = match (filename, &settings.dirs.downloads) { |
| 184 | (Some(f), _) => PathBuf::from(f), |
184 | (Some(f), _) => f, |
| 185 | (None, Some(downloads)) => downloads.clone(), |
185 | (None, Some(downloads)) => downloads.clone(), |
| 186 | (None, None) => return Err(IambError::NoDownloadDir.into()), |
186 | (None, None) => return Err(IambError::NoDownloadDir.into()), |
| 187 | }; |
187 | }; |
| @@ -684,11 +684,10 @@ impl ChatState { |
| 684 | return Err(UIError::NeedConfirm(prompt)); |
684 | return Err(UIError::NeedConfirm(prompt)); |
| 685 | } |
685 | } |
| 686 | |
686 | |
| 687 | let path = Path::new(file.as_str()); |
687 | let mime = mime_guess::from_path(&file).first_or(mime::APPLICATION_OCTET_STREAM); |
| 688 | let mime = mime_guess::from_path(path).first_or(mime::APPLICATION_OCTET_STREAM); |
| |
| 689 | |
688 | |
| 690 | let bytes = fs::read(path)?; |
689 | let bytes = fs::read(&file)?; |
| 691 | let name = path |
690 | let name = file |
| 692 | .file_name() |
691 | .file_name() |
| 693 | .map(OsStr::to_string_lossy) |
692 | .map(OsStr::to_string_lossy) |
| 694 | .unwrap_or_else(|| Cow::from("Attachment")); |
693 | .unwrap_or_else(|| Cow::from("Attachment")); |