diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..48b969caf --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,58 @@ +name: Release + +on: + push: + tags: + - "v[0-9]+.[0-9]+.[0-9]+" + +jobs: + publish: + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: windows-latest + target: x86_64-pc-windows-msvc + - os: macos-latest + target: x86_64-apple-darwin + - os: macos-latest + target: aarch64-apple-darwin + + steps: + - uses: actions/checkout@v3 + + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 + + - name: Build + run: cargo build --release --locked --target ${{ matrix.target }} + + - name: Pack Artifacts [Linux & macOS] + if: matrix.os == 'ubuntu-latest' || matrix.os == 'macos-latest' + env: + RELEASE_NAME: yazi-${{ matrix.target }} + run: | + mkdir $RELEASE_NAME + cp target/${{ matrix.target }}/release/yazi $RELEASE_NAME + cp -r config/completions $RELEASE_NAME + cp README.md LICENSE $RELEASE_NAME + zip -r $RELEASE_NAME.zip $RELEASE_NAME + + - name: Pack Artifacts [Windows] + if: matrix.os == 'windows-latest' + env: + RELEASE_NAME: yazi-${{ matrix.target }} + run: | + New-Item -ItemType Directory -Path ${env:RELEASE_NAME} + Copy-Item -Path "target\${{ matrix.target }}\release\yazi.exe" -Destination ${env:RELEASE_NAME} + Copy-Item -Path "config\completions" -Destination ${env:RELEASE_NAME} -Recurse + Copy-Item -Path "README.md", "LICENSE" -Destination ${env:RELEASE_NAME} + Compress-Archive -Path ${env:RELEASE_NAME} -DestinationPath "${env:RELEASE_NAME}.zip" + + - name: Release + uses: softprops/action-gh-release@v1 + if: startsWith(github.ref, 'refs/tags/') + with: + files: yazi-${{ matrix.target }}.zip diff --git a/.github/workflows/rust.yml b/.github/workflows/test.yml similarity index 83% rename from .github/workflows/rust.yml rename to .github/workflows/test.yml index 617841b2b..5ab1ad3ac 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/test.yml @@ -1,4 +1,4 @@ -name: Rust +name: Test on: push: @@ -19,7 +19,12 @@ jobs: steps: - uses: actions/checkout@v3 + + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 + - name: Build run: cargo build --verbose + - name: Run tests run: cargo test --verbose diff --git a/.gitignore b/.gitignore index fe33324c7..9df5bdcfd 100644 --- a/.gitignore +++ b/.gitignore @@ -1,6 +1,8 @@ target/ +config/completions .DS_Store + result result-* .devenv* diff --git a/Cargo.lock b/Cargo.lock index 92d7620f6..edf46a8e1 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -307,6 +307,35 @@ dependencies = [ "strsim", ] +[[package]] +name = "clap_complete" +version = "4.4.3" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "e3ae8ba90b9d8b007efe66e55e48fb936272f5ca00349b5b0e89877520d35ea7" +dependencies = [ + "clap", +] + +[[package]] +name = "clap_complete_fig" +version = "4.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "29bdbe21a263b628f83fcbeac86a4416a1d588c7669dd41473bc4149e4e7d2f1" +dependencies = [ + "clap", + "clap_complete", +] + +[[package]] +name = "clap_complete_nushell" +version = "4.4.1" +source = "registry+https://github.com/rust-lang/crates.io-index" +checksum = "df47268eb308aaac1ffbfcd8ae43e43820cd094a051b03956d238f2bc60dc3fe" +dependencies = [ + "clap", + "clap_complete", +] + [[package]] name = "clap_derive" version = "4.4.2" @@ -363,6 +392,9 @@ version = "0.1.5" dependencies = [ "anyhow", "clap", + "clap_complete", + "clap_complete_fig", + "clap_complete_nushell", "crossterm", "dirs", "futures", diff --git a/app/Cargo.toml b/app/Cargo.toml index 7fe241171..4e98c40aa 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -15,7 +15,7 @@ ansi-to-tui = "^3" anyhow = "^1" crossterm = { version = "^0", features = [ "event-stream" ] } futures = "^0" -ratatui = "^0" +ratatui = "^0" tokio = { version = "^1", features = [ "parking_lot" ] } unicode-width = "^0" diff --git a/config/Cargo.toml b/config/Cargo.toml index 7f398c977..526db4d57 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -20,3 +20,9 @@ serde = { version = "^1", features = [ "derive" ] } shell-words = "^1" toml = { version = "^0", features = [ "preserve_order" ] } validator = { version = "^0", features = [ "derive" ] } + +[build-dependencies] +clap = { version = "^4", features = [ "derive" ] } +clap_complete = "^4" +clap_complete_nushell = "^4" +clap_complete_fig = "^4" diff --git a/config/build.rs b/config/build.rs new file mode 100644 index 000000000..d34bdbbb9 --- /dev/null +++ b/config/build.rs @@ -0,0 +1,24 @@ +#[path = "src/boot/cli.rs"] +mod cli; + +use std::{fs, io}; + +use clap::CommandFactory; +use clap_complete::{generate_to, Shell}; + +fn main() -> io::Result<()> { + let cmd = &mut cli::Args::command(); + let bin = "yazi"; + let out = "completions"; + + fs::create_dir_all(out)?; + generate_to(Shell::Bash, cmd, bin, out)?; + generate_to(Shell::Fish, cmd, bin, out)?; + generate_to(Shell::Zsh, cmd, bin, out)?; + generate_to(Shell::Elvish, cmd, bin, out)?; + generate_to(Shell::PowerShell, cmd, bin, out)?; + generate_to(clap_complete_nushell::Nushell, cmd, bin, out)?; + generate_to(clap_complete_fig::Fig, cmd, bin, out)?; + + Ok(()) +} diff --git a/config/src/boot/boot.rs b/config/src/boot/boot.rs index df3a207e7..518103b70 100644 --- a/config/src/boot/boot.rs +++ b/config/src/boot/boot.rs @@ -1,8 +1,9 @@ use std::{env, fs, path::PathBuf, process}; -use clap::{command, Parser}; +use clap::Parser; use shared::expand_path; +use super::cli::Args; use crate::{Xdg, PREVIEW}; #[derive(Debug)] @@ -14,25 +15,6 @@ pub struct Boot { pub chooser_file: Option, } -#[derive(Debug, Parser)] -#[command(name = "yazi", version)] -struct Args { - /// Set the current working directory - #[arg(index = 1)] - cwd: Option, - - /// Write the cwd on exit to this file - #[arg(long)] - cwd_file: Option, - /// Write the selected files on open emitted by the chooser mode - #[arg(long)] - chooser_file: Option, - - /// Clear the cache directory - #[arg(long, action)] - clear_cache: bool, -} - impl Default for Boot { fn default() -> Self { let args = Args::parse(); diff --git a/config/src/boot/cli.rs b/config/src/boot/cli.rs new file mode 100644 index 000000000..bd1f3b8e7 --- /dev/null +++ b/config/src/boot/cli.rs @@ -0,0 +1,22 @@ +use std::path::PathBuf; + +use clap::{command, Parser}; + +#[derive(Debug, Parser)] +#[command(name = "yazi", version)] +pub(super) struct Args { + /// Set the current working directory + #[arg(index = 1)] + pub cwd: Option, + + /// Write the cwd on exit to this file + #[arg(long)] + pub cwd_file: Option, + /// Write the selected files on open emitted by the chooser mode + #[arg(long)] + pub chooser_file: Option, + + /// Clear the cache directory + #[arg(long, action)] + pub clear_cache: bool, +} diff --git a/config/src/boot/mod.rs b/config/src/boot/mod.rs index 5922b49a1..865dc405b 100644 --- a/config/src/boot/mod.rs +++ b/config/src/boot/mod.rs @@ -1,3 +1,4 @@ mod boot; +mod cli; pub use boot::*; diff --git a/cspell.json b/cspell.json index a84e8552a..1ca7c89d5 100644 --- a/cspell.json +++ b/cspell.json @@ -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","linemode","setpgid","perror"],"version":"0.2","flagWords":[],"language":"en"} +{"version":"0.2","language":"en","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"],"flagWords":[]} diff --git a/shared/src/mime.rs b/shared/src/mime.rs index 9da7d1072..3d629b2d3 100644 --- a/shared/src/mime.rs +++ b/shared/src/mime.rs @@ -18,7 +18,11 @@ pub enum MimeKind { impl MimeKind { pub fn new(s: &str) -> Self { - if s.starts_with("text/") || s.ends_with("/xml") || s.ends_with("/javascript") || s.ends_with("/x-wine-extension-ini") { + if s.starts_with("text/") + || s.ends_with("/xml") + || s.ends_with("/javascript") + || s.ends_with("/x-wine-extension-ini") + { Self::Text } else if s.starts_with("image/") { Self::Image