Skip to content

Commit

Permalink
feat: shell completions & auto releasing (#282)
Browse files Browse the repository at this point in the history
  • Loading branch information
TD-Sky authored Oct 21, 2023
1 parent e6fb999 commit 3313f17
Show file tree
Hide file tree
Showing 12 changed files with 160 additions and 24 deletions.
58 changes: 58 additions & 0 deletions .github/workflows/release.yml
Original file line number Diff line number Diff line change
@@ -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
7 changes: 6 additions & 1 deletion .github/workflows/rust.yml → .github/workflows/test.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
name: Rust
name: Test

on:
push:
Expand All @@ -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 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
target/
config/completions

.DS_Store

result
result-*
.devenv*
32 changes: 32 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion app/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"

Expand Down
6 changes: 6 additions & 0 deletions config/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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 changes: 24 additions & 0 deletions config/build.rs
Original file line number Diff line number Diff line change
@@ -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(())
}
22 changes: 2 additions & 20 deletions config/src/boot/boot.rs
Original file line number Diff line number Diff line change
@@ -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)]
Expand All @@ -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();
Expand Down
22 changes: 22 additions & 0 deletions config/src/boot/cli.rs
Original file line number Diff line number Diff line change
@@ -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 change: 1 addition & 0 deletions config/src/boot/mod.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
mod boot;
mod cli;

pub use boot::*;
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","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":[]}
6 changes: 5 additions & 1 deletion shared/src/mime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down

0 comments on commit 3313f17

Please sign in to comment.