mirror of
https://github.com/sxyazi/yazi.git
synced 2024-11-24 09:53:12 +03:00
feat: shell completions & auto releasing (#282)
This commit is contained in:
parent
e6fb999d1b
commit
3313f17954
58
.github/workflows/release.yml
vendored
Normal file
58
.github/workflows/release.yml
vendored
Normal file
@ -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
|
@ -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
|
2
.gitignore
vendored
2
.gitignore
vendored
@ -1,6 +1,8 @@
|
||||
target/
|
||||
config/completions
|
||||
|
||||
.DS_Store
|
||||
|
||||
result
|
||||
result-*
|
||||
.devenv*
|
||||
|
32
Cargo.lock
generated
32
Cargo.lock
generated
@ -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",
|
||||
|
@ -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"
|
||||
|
||||
|
@ -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"
|
||||
|
24
config/build.rs
Normal file
24
config/build.rs
Normal file
@ -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(())
|
||||
}
|
@ -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<PathBuf>,
|
||||
}
|
||||
|
||||
#[derive(Debug, Parser)]
|
||||
#[command(name = "yazi", version)]
|
||||
struct Args {
|
||||
/// Set the current working directory
|
||||
#[arg(index = 1)]
|
||||
cwd: Option<PathBuf>,
|
||||
|
||||
/// Write the cwd on exit to this file
|
||||
#[arg(long)]
|
||||
cwd_file: Option<PathBuf>,
|
||||
/// Write the selected files on open emitted by the chooser mode
|
||||
#[arg(long)]
|
||||
chooser_file: Option<PathBuf>,
|
||||
|
||||
/// Clear the cache directory
|
||||
#[arg(long, action)]
|
||||
clear_cache: bool,
|
||||
}
|
||||
|
||||
impl Default for Boot {
|
||||
fn default() -> Self {
|
||||
let args = Args::parse();
|
||||
|
22
config/src/boot/cli.rs
Normal file
22
config/src/boot/cli.rs
Normal file
@ -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<PathBuf>,
|
||||
|
||||
/// Write the cwd on exit to this file
|
||||
#[arg(long)]
|
||||
pub cwd_file: Option<PathBuf>,
|
||||
/// Write the selected files on open emitted by the chooser mode
|
||||
#[arg(long)]
|
||||
pub chooser_file: Option<PathBuf>,
|
||||
|
||||
/// Clear the cache directory
|
||||
#[arg(long, action)]
|
||||
pub clear_cache: bool,
|
||||
}
|
@ -1,3 +1,4 @@
|
||||
mod boot;
|
||||
mod cli;
|
||||
|
||||
pub use boot::*;
|
||||
|
@ -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":[]}
|
||||
|
@ -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
|
||||
|
Loading…
Reference in New Issue
Block a user