@@ -162,14 +162,19 @@ impl Application {
162 // Unset path to prevent accidentally saving to the original tutor file.
162 // Unset path to prevent accidentally saving to the original tutor file.
163 doc_mut!(editor).set_path(None);
163 doc_mut!(editor).set_path(None);
164 } else if !args.files.is_empty() {
164 } else if !args.files.is_empty() {
165− if args.open_cwd {
165+ let mut files_it = args.files.into_iter().peekable();
166− // NOTE: The working directory is already set to args.files[0] in main()
166+
167− editor.new_file(Action::VerticalSplit);
167+ // If the first file is a directory, skip it and open a picker
168+ if let Some((first, _)) = files_it.next_if(|(p, _)| p.is_dir()) {
168− let picker = ui::file_picker(".".into(), &config.load().editor);
169+ let picker = ui::file_picker(first, &config.load().editor);
169 compositor.push(Box::new(overlaid(picker)));
170 compositor.push(Box::new(overlaid(picker)));
173+ // If there are any more files specified, open them
174+ if files_it.peek().is_some() {
171− let nr_of_files = args.files.len();
175+ let mut nr_of_files = 0;
172− for (i, (file, pos)) in args.files.into_iter().enumerate() {
176+ for (file, pos) in files_it {
173 if file.is_dir() {
178 if file.is_dir() {
174 return Err(anyhow::anyhow!(
179 return Err(anyhow::anyhow!(
175 "expected a path to file, found a directory. (to open a directory pass it as first argument)"
180 "expected a path to file, found a directory. (to open a directory pass it as first argument)"
@@ -181,7 +186,7 @@ impl Application {
181 // option. If neither of those two arguments are passed
186 // option. If neither of those two arguments are passed
182 // in, just load the files normally.
187 // in, just load the files normally.
183 let action = match args.split {
188 let action = match args.split {
184− _ if i == 0 => Action::VerticalSplit,
189+ _ if nr_of_files == 1 => Action::VerticalSplit,
185 Some(Layout::Vertical) => Action::VerticalSplit,
190 Some(Layout::Vertical) => Action::VerticalSplit,
186 Some(Layout::Horizontal) => Action::HorizontalSplit,
191 Some(Layout::Horizontal) => Action::HorizontalSplit,
187 None => Action::Load,
192 None => Action::Load,
@@ -208,6 +213,8 @@ impl Application {
208 // does not affect views without pos since it is at the top
213 // does not affect views without pos since it is at the top
209 let (view, doc) = current!(editor);
214 let (view, doc) = current!(editor);
210 align_view(doc, view, Align::Center);
215 align_view(doc, view, Align::Center);
217+ editor.new_file(Action::VerticalSplit);
212 } else if stdin().is_tty() || cfg!(feature = "integration") {
219 } else if stdin().is_tty() || cfg!(feature = "integration") {
213 editor.new_file(Action::VerticalSplit);
220 editor.new_file(Action::VerticalSplit);