Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: start with multiple tabs with different paths #1443

Merged
merged 2 commits into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cspell.json
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek"],"version":"0.2","language":"en","flagWords":[]}
{"language":"en","flagWords":[],"words":["Punct","KEYMAP","splitn","crossterm","YAZI","unar","peekable","ratatui","syntect","pbpaste","pbcopy","ffmpegthumbnailer","oneshot","Posix","Lsar","XADDOS","zoxide","cands","Deque","precache","imageops","IFBLK","IFCHR","IFDIR","IFIFO","IFLNK","IFMT","IFSOCK","IRGRP","IROTH","IRUSR","ISGID","ISUID","ISVTX","IWGRP","IWOTH","IWUSR","IXGRP","IXOTH","IXUSR","libc","winsize","TIOCGWINSZ","xpixel","ypixel","ioerr","appender","Catppuccin","macchiato","gitmodules","Dotfiles","bashprofile","vimrc","flac","webp","exiftool","mediainfo","ripgrep","nvim","indexmap","indexmap","unwatch","canonicalize","serde","fsevent","Ueberzug","iterm","wezterm","sixel","chafa","ueberzugpp","️ Überzug","️ Überzug","Konsole","Alacritty","Überzug","pkgs","paru","unarchiver","pdftoppm","poppler","prebuild","singlefile","jpegopt","EXIF","rustfmt","mktemp","nanos","xclip","xsel","natord","Mintty","nixos","nixpkgs","SIGTSTP","SIGCONT","SIGCONT","mlua","nonstatic","userdata","metatable","natsort","backstack","luajit","Succ","Succ","cand","fileencoding","foldmethod","lightgreen","darkgray","lightred","lightyellow","lightcyan","nushell","msvc","aarch","linemode","sxyazi","rsplit","ZELLIJ","bitflags","bitflags","USERPROFILE","Neovim","vergen","gitcl","Renderable","preloaders","prec","imagesize","Upserting","prio","Ghostty","Catmull","Lanczos","cmds","unyank","scrolloff","headsup","unsub","uzers","scopeguard","SPDLOG","globset","filetime","magick","magick","prefetcher","Prework","prefetchers","PREWORKERS","conds","translit","rxvt","Urxvt","realpath","realname","REPARSE","hardlink","hardlinking","nlink","nlink","linemodes","SIGSTOP","sevenzip","rsplitn","replacen","DECSET","DECRQM","repeek","cwds"],"version":"0.2"}
4 changes: 2 additions & 2 deletions yazi-boot/src/args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ use clap::{command, Parser};
#[command(name = "yazi")]
pub struct Args {
/// Set the current working entry
#[arg(index = 1)]
pub entry: Option<PathBuf>,
#[arg(index = 1, num_args = 1..=9)]
pub entries: Vec<PathBuf>,
coolkiid marked this conversation as resolved.
Show resolved Hide resolved

/// Write the cwd on exit to this file
#[arg(long)]
Expand Down
36 changes: 21 additions & 15 deletions yazi-boot/src/boot.rs
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
use std::{collections::HashSet, ffi::OsString, path::{Path, PathBuf}};
use std::{collections::HashSet, ffi::OsString, path::PathBuf};

use serde::Serialize;
use yazi_shared::{fs::{current_cwd, expand_path}, Xdg};

#[derive(Debug, Default, Serialize)]
pub struct Boot {
pub cwd: PathBuf,
pub file: Option<OsString>,
pub cwds: Vec<PathBuf>,
pub files: Vec<OsString>,

pub local_events: HashSet<String>,
pub remote_events: HashSet<String>,
Expand All @@ -18,25 +18,31 @@ pub struct Boot {
}

impl Boot {
fn parse_entry(entry: Option<&Path>) -> (PathBuf, Option<OsString>) {
let entry = match entry {
Some(p) => expand_path(p),
None => return (current_cwd().unwrap(), None),
};
fn parse_entries(entries: &[PathBuf]) -> (Vec<PathBuf>, Vec<OsString>) {
if entries.is_empty() {
return (vec![current_cwd().unwrap()], vec![OsString::new()]);
}

let parent = entry.parent();
if parent.is_none() || entry.is_dir() {
return (entry, None);
let mut cwds = Vec::with_capacity(entries.len());
let mut files = Vec::with_capacity(entries.len());
for entry in entries.iter().map(expand_path) {
if let Some(p) = entry.parent().filter(|_| !entry.is_dir()) {
cwds.push(p.to_owned());
files.push(entry.file_name().unwrap().to_owned());
} else {
cwds.push(entry);
files.push(OsString::new());
}
}

(parent.unwrap().to_owned(), Some(entry.file_name().unwrap().to_owned()))
(cwds, files)
}
}

impl From<&crate::Args> for Boot {
fn from(args: &crate::Args) -> Self {
let config_dir = Xdg::config_dir();
let (cwd, file) = Self::parse_entry(args.entry.as_deref());
let (cwds, files) = Self::parse_entries(&args.entries);

let local_events = args
.local_events
Expand All @@ -50,8 +56,8 @@ impl From<&crate::Args> for Boot {
.unwrap_or_default();

Self {
cwd,
file,
cwds,
files,

local_events,
remote_events,
Expand Down
5 changes: 4 additions & 1 deletion yazi-core/src/manager/commands/tab_create.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,10 @@ impl From<Cmd> for Opt {
Self { url: Default::default(), current: true }
} else {
Self {
url: c.take_first().and_then(Data::into_url).unwrap_or_else(|| Url::from(&BOOT.cwd)),
url: c
.take_first()
.and_then(Data::into_url)
.unwrap_or_else(|| Url::from(&BOOT.cwds[0])),
current: false,
}
}
Expand Down
17 changes: 11 additions & 6 deletions yazi-core/src/manager/tabs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,18 @@ pub struct Tabs {

impl Tabs {
pub fn make() -> Self {
let mut tabs = Self { cursor: 0, items: vec![Tab::default()] };
if let Some(file) = &BOOT.file {
tabs.items[0].reveal(Url::from(BOOT.cwd.join(file)));
} else {
tabs.items[0].cd(Url::from(&BOOT.cwd));
let mut tabs =
Self { cursor: 0, items: (0..BOOT.cwds.len()).map(|_| Tab::default()).collect() };
tabs.reorder();

for (i, tab) in tabs.iter_mut().enumerate() {
let file = &BOOT.files[i];
if file.is_empty() {
tab.cd(Url::from(&BOOT.cwds[i]));
} else {
tab.reveal(Url::from(BOOT.cwds[i].join(file)));
}
}

tabs
}

Expand Down