From fb10da6857a79b53ba5220db12e987e699f40af3 Mon Sep 17 00:00:00 2001 From: TD-Sky Date: Mon, 16 Oct 2023 20:42:11 +0800 Subject: [PATCH 1/6] feat(completions): generate shell completion scripts --- config/completions/_yazi | 39 ++++++++++++++++++++++++++++++ config/completions/_yazi.ps1 | 37 +++++++++++++++++++++++++++++ config/completions/yazi.bash | 46 ++++++++++++++++++++++++++++++++++++ config/completions/yazi.elv | 31 ++++++++++++++++++++++++ config/completions/yazi.fish | 5 ++++ config/completions/yazi.nu | 14 +++++++++++ config/completions/yazi.ts | 45 +++++++++++++++++++++++++++++++++++ 7 files changed, 217 insertions(+) create mode 100644 config/completions/_yazi create mode 100644 config/completions/_yazi.ps1 create mode 100644 config/completions/yazi.bash create mode 100644 config/completions/yazi.elv create mode 100644 config/completions/yazi.fish create mode 100644 config/completions/yazi.nu create mode 100644 config/completions/yazi.ts diff --git a/config/completions/_yazi b/config/completions/_yazi new file mode 100644 index 000000000..52ccf2e05 --- /dev/null +++ b/config/completions/_yazi @@ -0,0 +1,39 @@ +#compdef yazi + +autoload -U is-at-least + +_yazi() { + typeset -A opt_args + typeset -a _arguments_options + local ret=1 + + if is-at-least 5.2; then + _arguments_options=(-s -S -C) + else + _arguments_options=(-s -C) + fi + + local context curcontext="$curcontext" state line + _arguments "${_arguments_options[@]}" \ +'--cwd-file=[Write the cwd on exit to this file]:CWD_FILE:_files' \ +'--chooser-file=[Write the selected files on open emitted by the chooser mode]:CHOOSER_FILE:_files' \ +'--clear-cache[Clear the cache directory]' \ +'-h[Print help]' \ +'--help[Print help]' \ +'-V[Print version]' \ +'--version[Print version]' \ +'::cwd -- Set the current working directory:_files' \ +&& ret=0 +} + +(( $+functions[_yazi_commands] )) || +_yazi_commands() { + local commands; commands=() + _describe -t commands 'yazi commands' commands "$@" +} + +if [ "$funcstack[1]" = "_yazi" ]; then + _yazi "$@" +else + compdef _yazi yazi +fi diff --git a/config/completions/_yazi.ps1 b/config/completions/_yazi.ps1 new file mode 100644 index 000000000..22d198b22 --- /dev/null +++ b/config/completions/_yazi.ps1 @@ -0,0 +1,37 @@ + +using namespace System.Management.Automation +using namespace System.Management.Automation.Language + +Register-ArgumentCompleter -Native -CommandName 'yazi' -ScriptBlock { + param($wordToComplete, $commandAst, $cursorPosition) + + $commandElements = $commandAst.CommandElements + $command = @( + 'yazi' + for ($i = 1; $i -lt $commandElements.Count; $i++) { + $element = $commandElements[$i] + if ($element -isnot [StringConstantExpressionAst] -or + $element.StringConstantType -ne [StringConstantType]::BareWord -or + $element.Value.StartsWith('-') -or + $element.Value -eq $wordToComplete) { + break + } + $element.Value + }) -join ';' + + $completions = @(switch ($command) { + 'yazi' { + [CompletionResult]::new('--cwd-file', 'cwd-file', [CompletionResultType]::ParameterName, 'Write the cwd on exit to this file') + [CompletionResult]::new('--chooser-file', 'chooser-file', [CompletionResultType]::ParameterName, 'Write the selected files on open emitted by the chooser mode') + [CompletionResult]::new('--clear-cache', 'clear-cache', [CompletionResultType]::ParameterName, 'Clear the cache directory') + [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') + [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') + [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') + break + } + }) + + $completions.Where{ $_.CompletionText -like "$wordToComplete*" } | + Sort-Object -Property ListItemText +} diff --git a/config/completions/yazi.bash b/config/completions/yazi.bash new file mode 100644 index 000000000..f137efef0 --- /dev/null +++ b/config/completions/yazi.bash @@ -0,0 +1,46 @@ +_yazi() { + local i cur prev opts cmd + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + cmd="" + opts="" + + for i in ${COMP_WORDS[@]} + do + case "${cmd},${i}" in + ",$1") + cmd="yazi" + ;; + *) + ;; + esac + done + + case "${cmd}" in + yazi) + opts="-h -V --cwd-file --chooser-file --clear-cache --help --version [CWD]" + if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + fi + case "${prev}" in + --cwd-file) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + --chooser-file) + COMPREPLY=($(compgen -f "${cur}")) + return 0 + ;; + *) + COMPREPLY=() + ;; + esac + COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) + return 0 + ;; + esac +} + +complete -F _yazi -o nosort -o bashdefault -o default yazi diff --git a/config/completions/yazi.elv b/config/completions/yazi.elv new file mode 100644 index 000000000..637939c24 --- /dev/null +++ b/config/completions/yazi.elv @@ -0,0 +1,31 @@ + +use builtin; +use str; + +set edit:completion:arg-completer[yazi] = {|@words| + fn spaces {|n| + builtin:repeat $n ' ' | str:join '' + } + fn cand {|text desc| + edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc + } + var command = 'yazi' + for word $words[1..-1] { + if (str:has-prefix $word '-') { + break + } + set command = $command';'$word + } + var completions = [ + &'yazi'= { + cand --cwd-file 'Write the cwd on exit to this file' + cand --chooser-file 'Write the selected files on open emitted by the chooser mode' + cand --clear-cache 'Clear the cache directory' + cand -h 'Print help' + cand --help 'Print help' + cand -V 'Print version' + cand --version 'Print version' + } + ] + $completions[$command] +} diff --git a/config/completions/yazi.fish b/config/completions/yazi.fish new file mode 100644 index 000000000..badbc5347 --- /dev/null +++ b/config/completions/yazi.fish @@ -0,0 +1,5 @@ +complete -c yazi -l cwd-file -d 'Write the cwd on exit to this file' -r -F +complete -c yazi -l chooser-file -d 'Write the selected files on open emitted by the chooser mode' -r -F +complete -c yazi -l clear-cache -d 'Clear the cache directory' +complete -c yazi -s h -l help -d 'Print help' +complete -c yazi -s V -l version -d 'Print version' diff --git a/config/completions/yazi.nu b/config/completions/yazi.nu new file mode 100644 index 000000000..4a0649a49 --- /dev/null +++ b/config/completions/yazi.nu @@ -0,0 +1,14 @@ +module completions { + + export extern yazi [ + cwd?: string # Set the current working directory + --cwd-file: string # Write the cwd on exit to this file + --chooser-file: string # Write the selected files on open emitted by the chooser mode + --clear-cache # Clear the cache directory + --help(-h) # Print help + --version(-V) # Print version + ] + +} + +export use completions * diff --git a/config/completions/yazi.ts b/config/completions/yazi.ts new file mode 100644 index 000000000..f2915eddb --- /dev/null +++ b/config/completions/yazi.ts @@ -0,0 +1,45 @@ +const completion: Fig.Spec = { + name: "yazi", + description: "", + options: [ + { + name: "--cwd-file", + description: "Write the cwd on exit to this file", + isRepeatable: true, + args: { + name: "cwd_file", + isOptional: true, + template: "filepaths", + }, + }, + { + name: "--chooser-file", + description: "Write the selected files on open emitted by the chooser mode", + isRepeatable: true, + args: { + name: "chooser_file", + isOptional: true, + template: "filepaths", + }, + }, + { + name: "--clear-cache", + description: "Clear the cache directory", + }, + { + name: ["-h", "--help"], + description: "Print help", + }, + { + name: ["-V", "--version"], + description: "Print version", + }, + ], + args: { + name: "cwd", + isOptional: true, + template: "filepaths", + }, +}; + +export default completion; From 82cd486efa4e900f3edac2264086e56777db0105 Mon Sep 17 00:00:00 2001 From: TD-Sky Date: Mon, 16 Oct 2023 20:42:11 +0800 Subject: [PATCH 2/6] feat(completions): generate shell completion scripts --- Cargo.lock | 32 ++++++++++++++++++++++++++++++++ app/Cargo.toml | 30 +++++++++++++++--------------- config/Cargo.toml | 6 ++++++ config/build.rs | 29 +++++++++++++++++++++++++++++ config/src/boot/boot.rs | 22 ++-------------------- config/src/boot/cli.rs | 22 ++++++++++++++++++++++ config/src/boot/mod.rs | 1 + 7 files changed, 107 insertions(+), 35 deletions(-) create mode 100644 config/build.rs create mode 100644 config/src/boot/cli.rs 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..891b00f02 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -1,32 +1,32 @@ [package] -name = "app" +name = "app" version = "0.1.5" edition = "2021" [dependencies] adaptor = { path = "../adaptor" } -config = { path = "../config" } -core = { path = "../core" } -plugin = { path = "../plugin" } -shared = { path = "../shared" } +config = { path = "../config" } +core = { path = "../core" } +plugin = { path = "../plugin" } +shared = { path = "../shared" } # External dependencies -ansi-to-tui = "^3" -anyhow = "^1" -crossterm = { version = "^0", features = [ "event-stream" ] } -futures = "^0" -ratatui = "^0" -tokio = { version = "^1", features = [ "parking_lot" ] } +ansi-to-tui = "^3" +anyhow = "^1" +crossterm = { version = "^0", features = ["event-stream"] } +futures = "^0" +ratatui = "^0" +tokio = { version = "^1", features = ["parking_lot"] } unicode-width = "^0" # Logging -tracing = "^0" -tracing-appender = "^0" +tracing = "^0" +tracing-appender = "^0" tracing-subscriber = "^0" [target."cfg(unix)".dependencies] -libc = "^0" -signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] } +libc = "^0" +signal-hook-tokio = { version = "^0", features = ["futures-v0_3"] } [[bin]] name = "yazi" diff --git a/config/Cargo.toml b/config/Cargo.toml index 7f398c977..725f16a42 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..340c88a59 --- /dev/null +++ b/config/build.rs @@ -0,0 +1,29 @@ +#[path = "src/boot/cli.rs"] +mod cli; + +use std::{fs, io}; + +use clap::CommandFactory; +use clap_complete::{generate_to, Shell::*}; +use clap_complete_fig::Fig; +use clap_complete_nushell::Nushell; + +use self::cli::Args; + +fn main() -> io::Result<()> { + let cmd = &mut Args::command(); + let name = "yazi"; + let dir = "completions"; + + fs::create_dir_all(dir)?; + + generate_to(Bash, cmd, name, dir)?; + generate_to(Fish, cmd, name, dir)?; + generate_to(Zsh, cmd, name, dir)?; + generate_to(Elvish, cmd, name, dir)?; + generate_to(PowerShell, cmd, name, dir)?; + generate_to(Nushell, cmd, name, dir)?; + generate_to(Fig, cmd, name, dir)?; + + 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::*; From 5e804a0b21a59bfaed3a2072eaa6c15d5f66718d Mon Sep 17 00:00:00 2001 From: TD-Sky Date: Mon, 16 Oct 2023 20:43:07 +0800 Subject: [PATCH 3/6] chore(ci): publish assets automatically --- .github/workflows/release.yml | 76 +++++++++++++++++++++++++++++++++++ 1 file changed, 76 insertions(+) create mode 100644 .github/workflows/release.yml diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 000000000..3c066bddf --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,76 @@ +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: + - name: Checkout + uses: actions/checkout@v3 + + - name: Bootstrap + uses: actions-rs/toolchain@v1 + with: + toolchain: stable + target: ${{ matrix.target }} + + - name: Cache Dependencies + uses: Swatinem/rust-cache@v2 + + - name: Build + run: cargo build --release --locked --target ${{ matrix.target }} + + - name: Pack Artifacts [Linux] + if: matrix.os == 'ubuntu-latest' + env: + RELEASE_NAME: yazi-${{ matrix.target }} + run: | + mkdir $RELEASE_NAME + cp target/${{ matrix.target }}/release/yazi -t $RELEASE_NAME + cp -r config/completions -t $RELEASE_NAME + cp README.md LICENSE -t $RELEASE_NAME + zip -r $RELEASE_NAME.zip $RELEASE_NAME + + - name: Pack Artifacts [macOS] + if: 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 From 1e3835a2fb87e68a5fb9bb71c19136bdca673189 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 21 Oct 2023 11:26:00 +0800 Subject: [PATCH 4/6] format --- app/Cargo.toml | 30 +++++++++++------------ config/completions/_yazi | 39 ------------------------------ config/completions/_yazi.ps1 | 37 ----------------------------- config/completions/yazi.bash | 46 ------------------------------------ config/completions/yazi.elv | 31 ------------------------ config/completions/yazi.fish | 5 ---- config/completions/yazi.nu | 14 ----------- config/completions/yazi.ts | 45 ----------------------------------- shared/src/mime.rs | 6 ++++- 9 files changed, 20 insertions(+), 233 deletions(-) delete mode 100644 config/completions/_yazi delete mode 100644 config/completions/_yazi.ps1 delete mode 100644 config/completions/yazi.bash delete mode 100644 config/completions/yazi.elv delete mode 100644 config/completions/yazi.fish delete mode 100644 config/completions/yazi.nu delete mode 100644 config/completions/yazi.ts diff --git a/app/Cargo.toml b/app/Cargo.toml index 891b00f02..4e98c40aa 100644 --- a/app/Cargo.toml +++ b/app/Cargo.toml @@ -1,32 +1,32 @@ [package] -name = "app" +name = "app" version = "0.1.5" edition = "2021" [dependencies] adaptor = { path = "../adaptor" } -config = { path = "../config" } -core = { path = "../core" } -plugin = { path = "../plugin" } -shared = { path = "../shared" } +config = { path = "../config" } +core = { path = "../core" } +plugin = { path = "../plugin" } +shared = { path = "../shared" } # External dependencies -ansi-to-tui = "^3" -anyhow = "^1" -crossterm = { version = "^0", features = ["event-stream"] } -futures = "^0" -ratatui = "^0" -tokio = { version = "^1", features = ["parking_lot"] } +ansi-to-tui = "^3" +anyhow = "^1" +crossterm = { version = "^0", features = [ "event-stream" ] } +futures = "^0" +ratatui = "^0" +tokio = { version = "^1", features = [ "parking_lot" ] } unicode-width = "^0" # Logging -tracing = "^0" -tracing-appender = "^0" +tracing = "^0" +tracing-appender = "^0" tracing-subscriber = "^0" [target."cfg(unix)".dependencies] -libc = "^0" -signal-hook-tokio = { version = "^0", features = ["futures-v0_3"] } +libc = "^0" +signal-hook-tokio = { version = "^0", features = [ "futures-v0_3" ] } [[bin]] name = "yazi" diff --git a/config/completions/_yazi b/config/completions/_yazi deleted file mode 100644 index 52ccf2e05..000000000 --- a/config/completions/_yazi +++ /dev/null @@ -1,39 +0,0 @@ -#compdef yazi - -autoload -U is-at-least - -_yazi() { - typeset -A opt_args - typeset -a _arguments_options - local ret=1 - - if is-at-least 5.2; then - _arguments_options=(-s -S -C) - else - _arguments_options=(-s -C) - fi - - local context curcontext="$curcontext" state line - _arguments "${_arguments_options[@]}" \ -'--cwd-file=[Write the cwd on exit to this file]:CWD_FILE:_files' \ -'--chooser-file=[Write the selected files on open emitted by the chooser mode]:CHOOSER_FILE:_files' \ -'--clear-cache[Clear the cache directory]' \ -'-h[Print help]' \ -'--help[Print help]' \ -'-V[Print version]' \ -'--version[Print version]' \ -'::cwd -- Set the current working directory:_files' \ -&& ret=0 -} - -(( $+functions[_yazi_commands] )) || -_yazi_commands() { - local commands; commands=() - _describe -t commands 'yazi commands' commands "$@" -} - -if [ "$funcstack[1]" = "_yazi" ]; then - _yazi "$@" -else - compdef _yazi yazi -fi diff --git a/config/completions/_yazi.ps1 b/config/completions/_yazi.ps1 deleted file mode 100644 index 22d198b22..000000000 --- a/config/completions/_yazi.ps1 +++ /dev/null @@ -1,37 +0,0 @@ - -using namespace System.Management.Automation -using namespace System.Management.Automation.Language - -Register-ArgumentCompleter -Native -CommandName 'yazi' -ScriptBlock { - param($wordToComplete, $commandAst, $cursorPosition) - - $commandElements = $commandAst.CommandElements - $command = @( - 'yazi' - for ($i = 1; $i -lt $commandElements.Count; $i++) { - $element = $commandElements[$i] - if ($element -isnot [StringConstantExpressionAst] -or - $element.StringConstantType -ne [StringConstantType]::BareWord -or - $element.Value.StartsWith('-') -or - $element.Value -eq $wordToComplete) { - break - } - $element.Value - }) -join ';' - - $completions = @(switch ($command) { - 'yazi' { - [CompletionResult]::new('--cwd-file', 'cwd-file', [CompletionResultType]::ParameterName, 'Write the cwd on exit to this file') - [CompletionResult]::new('--chooser-file', 'chooser-file', [CompletionResultType]::ParameterName, 'Write the selected files on open emitted by the chooser mode') - [CompletionResult]::new('--clear-cache', 'clear-cache', [CompletionResultType]::ParameterName, 'Clear the cache directory') - [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') - [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') - [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') - break - } - }) - - $completions.Where{ $_.CompletionText -like "$wordToComplete*" } | - Sort-Object -Property ListItemText -} diff --git a/config/completions/yazi.bash b/config/completions/yazi.bash deleted file mode 100644 index f137efef0..000000000 --- a/config/completions/yazi.bash +++ /dev/null @@ -1,46 +0,0 @@ -_yazi() { - local i cur prev opts cmd - COMPREPLY=() - cur="${COMP_WORDS[COMP_CWORD]}" - prev="${COMP_WORDS[COMP_CWORD-1]}" - cmd="" - opts="" - - for i in ${COMP_WORDS[@]} - do - case "${cmd},${i}" in - ",$1") - cmd="yazi" - ;; - *) - ;; - esac - done - - case "${cmd}" in - yazi) - opts="-h -V --cwd-file --chooser-file --clear-cache --help --version [CWD]" - if [[ ${cur} == -* || ${COMP_CWORD} -eq 1 ]] ; then - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - fi - case "${prev}" in - --cwd-file) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; - --chooser-file) - COMPREPLY=($(compgen -f "${cur}")) - return 0 - ;; - *) - COMPREPLY=() - ;; - esac - COMPREPLY=( $(compgen -W "${opts}" -- "${cur}") ) - return 0 - ;; - esac -} - -complete -F _yazi -o nosort -o bashdefault -o default yazi diff --git a/config/completions/yazi.elv b/config/completions/yazi.elv deleted file mode 100644 index 637939c24..000000000 --- a/config/completions/yazi.elv +++ /dev/null @@ -1,31 +0,0 @@ - -use builtin; -use str; - -set edit:completion:arg-completer[yazi] = {|@words| - fn spaces {|n| - builtin:repeat $n ' ' | str:join '' - } - fn cand {|text desc| - edit:complex-candidate $text &display=$text' '(spaces (- 14 (wcswidth $text)))$desc - } - var command = 'yazi' - for word $words[1..-1] { - if (str:has-prefix $word '-') { - break - } - set command = $command';'$word - } - var completions = [ - &'yazi'= { - cand --cwd-file 'Write the cwd on exit to this file' - cand --chooser-file 'Write the selected files on open emitted by the chooser mode' - cand --clear-cache 'Clear the cache directory' - cand -h 'Print help' - cand --help 'Print help' - cand -V 'Print version' - cand --version 'Print version' - } - ] - $completions[$command] -} diff --git a/config/completions/yazi.fish b/config/completions/yazi.fish deleted file mode 100644 index badbc5347..000000000 --- a/config/completions/yazi.fish +++ /dev/null @@ -1,5 +0,0 @@ -complete -c yazi -l cwd-file -d 'Write the cwd on exit to this file' -r -F -complete -c yazi -l chooser-file -d 'Write the selected files on open emitted by the chooser mode' -r -F -complete -c yazi -l clear-cache -d 'Clear the cache directory' -complete -c yazi -s h -l help -d 'Print help' -complete -c yazi -s V -l version -d 'Print version' diff --git a/config/completions/yazi.nu b/config/completions/yazi.nu deleted file mode 100644 index 4a0649a49..000000000 --- a/config/completions/yazi.nu +++ /dev/null @@ -1,14 +0,0 @@ -module completions { - - export extern yazi [ - cwd?: string # Set the current working directory - --cwd-file: string # Write the cwd on exit to this file - --chooser-file: string # Write the selected files on open emitted by the chooser mode - --clear-cache # Clear the cache directory - --help(-h) # Print help - --version(-V) # Print version - ] - -} - -export use completions * diff --git a/config/completions/yazi.ts b/config/completions/yazi.ts deleted file mode 100644 index f2915eddb..000000000 --- a/config/completions/yazi.ts +++ /dev/null @@ -1,45 +0,0 @@ -const completion: Fig.Spec = { - name: "yazi", - description: "", - options: [ - { - name: "--cwd-file", - description: "Write the cwd on exit to this file", - isRepeatable: true, - args: { - name: "cwd_file", - isOptional: true, - template: "filepaths", - }, - }, - { - name: "--chooser-file", - description: "Write the selected files on open emitted by the chooser mode", - isRepeatable: true, - args: { - name: "chooser_file", - isOptional: true, - template: "filepaths", - }, - }, - { - name: "--clear-cache", - description: "Clear the cache directory", - }, - { - name: ["-h", "--help"], - description: "Print help", - }, - { - name: ["-V", "--version"], - description: "Print version", - }, - ], - args: { - name: "cwd", - isOptional: true, - template: "filepaths", - }, -}; - -export default completion; 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 From 04ad67e4271f89deed9f201d4ceb56e615980b33 Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 21 Oct 2023 12:01:49 +0800 Subject: [PATCH 5/6] Simplify actions --- .github/workflows/release.yml | 26 ++++----------------- .github/workflows/{rust.yml => test.yml} | 7 +++++- .gitignore | 2 ++ config/Cargo.toml | 8 +++---- config/build.rs | 29 ++++++++++-------------- 5 files changed, 28 insertions(+), 44 deletions(-) rename .github/workflows/{rust.yml => test.yml} (83%) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 3c066bddf..48b969caf 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -21,14 +21,7 @@ jobs: target: aarch64-apple-darwin steps: - - name: Checkout - uses: actions/checkout@v3 - - - name: Bootstrap - uses: actions-rs/toolchain@v1 - with: - toolchain: stable - target: ${{ matrix.target }} + - uses: actions/checkout@v3 - name: Cache Dependencies uses: Swatinem/rust-cache@v2 @@ -36,25 +29,14 @@ jobs: - name: Build run: cargo build --release --locked --target ${{ matrix.target }} - - name: Pack Artifacts [Linux] - if: matrix.os == 'ubuntu-latest' - env: - RELEASE_NAME: yazi-${{ matrix.target }} - run: | - mkdir $RELEASE_NAME - cp target/${{ matrix.target }}/release/yazi -t $RELEASE_NAME - cp -r config/completions -t $RELEASE_NAME - cp README.md LICENSE -t $RELEASE_NAME - zip -r $RELEASE_NAME.zip $RELEASE_NAME - - - name: Pack Artifacts [macOS] - if: matrix.os == 'macos-latest' + - 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 -r config/completions $RELEASE_NAME cp README.md LICENSE $RELEASE_NAME zip -r $RELEASE_NAME.zip $RELEASE_NAME 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/config/Cargo.toml b/config/Cargo.toml index 725f16a42..526db4d57 100644 --- a/config/Cargo.toml +++ b/config/Cargo.toml @@ -22,7 +22,7 @@ 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" +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 index 340c88a59..d34bdbbb9 100644 --- a/config/build.rs +++ b/config/build.rs @@ -4,26 +4,21 @@ mod cli; use std::{fs, io}; use clap::CommandFactory; -use clap_complete::{generate_to, Shell::*}; -use clap_complete_fig::Fig; -use clap_complete_nushell::Nushell; - -use self::cli::Args; +use clap_complete::{generate_to, Shell}; fn main() -> io::Result<()> { - let cmd = &mut Args::command(); - let name = "yazi"; - let dir = "completions"; - - fs::create_dir_all(dir)?; + let cmd = &mut cli::Args::command(); + let bin = "yazi"; + let out = "completions"; - generate_to(Bash, cmd, name, dir)?; - generate_to(Fish, cmd, name, dir)?; - generate_to(Zsh, cmd, name, dir)?; - generate_to(Elvish, cmd, name, dir)?; - generate_to(PowerShell, cmd, name, dir)?; - generate_to(Nushell, cmd, name, dir)?; - generate_to(Fig, cmd, name, dir)?; + 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(()) } From 61db95c61141ce4e27b16cf2448c0ee20da0cdbe Mon Sep 17 00:00:00 2001 From: sxyazi Date: Sat, 21 Oct 2023 12:04:19 +0800 Subject: [PATCH 6/6] .. --- cspell.json | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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":[]}