diff --git a/.github/workflows/build.yaml b/.github/workflows/build.yaml deleted file mode 100644 index e8ffb75..0000000 --- a/.github/workflows/build.yaml +++ /dev/null @@ -1,62 +0,0 @@ -name: Build and Test - -on: - push: - branches: [ main ] - pull_request: - branches: [ main ] - -env: - CARGO_TERM_COLOR: always - -jobs: - build: - runs-on: ${{ matrix.os }} - strategy: - matrix: - os: [ubuntu-latest, windows-latest, macos-latest] - rust: [stable] - - steps: - - uses: actions/checkout@v4 - - - name: Install Rust - uses: actions-rs/toolchain@v1 - with: - toolchain: ${{ matrix.rust }} - override: true - components: rustfmt, clippy - - - name: Cache dependencies - uses: actions/cache@v3 - with: - path: | - ~/.cargo/registry - ~/.cargo/git - target - key: ${{ runner.os }}-cargo-${{ hashFiles('**/Cargo.lock') }} - restore-keys: ${{ runner.os }}-cargo- - - - name: Format check - uses: actions-rs/cargo@v1 - with: - command: fmt - args: --all -- --check - - - name: Clippy check - uses: actions-rs/cargo@v1 - with: - command: clippy - args: -- -D warnings - - - name: Build - uses: actions-rs/cargo@v1 - with: - command: build - args: --verbose - - - name: Run tests - uses: actions-rs/cargo@v1 - with: - command: test - args: --verbose diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml new file mode 100644 index 0000000..f824945 --- /dev/null +++ b/.github/workflows/ci.yml @@ -0,0 +1,107 @@ +name: CI + +on: + push: + branches: [ main ] + pull_request: + branches: [ main ] + +env: + CARGO_TERM_COLOR: always + +jobs: + test: + name: Test + runs-on: ubuntu-latest + strategy: + matrix: + rust: + - stable + - beta + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@master + with: + toolchain: ${{ matrix.rust }} + + - name: Cache cargo registry + uses: actions/cache@v4 + with: + path: ~/.cargo/registry + key: ${{ runner.os }}-cargo-registry-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo index + uses: actions/cache@v4 + with: + path: ~/.cargo/git + key: ${{ runner.os }}-cargo-index-${{ hashFiles('**/Cargo.lock') }} + + - name: Cache cargo build + uses: actions/cache@v4 + with: + path: target + key: ${{ runner.os }}-cargo-build-target-${{ hashFiles('**/Cargo.lock') }} + + - name: Run tests + run: cargo test --verbose + + - name: Run tests (release mode) + run: cargo test --release --verbose + + fmt: + name: Rustfmt + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + components: rustfmt + + - name: Check formatting + run: cargo fmt --all -- --check + + clippy: + name: Clippy + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + components: clippy + + - name: Run clippy + run: cargo clippy --all-targets --all-features -- -D warnings + + build: + name: Build + runs-on: ${{ matrix.os }} + strategy: + matrix: + os: [ubuntu-latest, macos-latest] + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + - os: macos-latest + target: x86_64-apple-darwin + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + target: ${{ matrix.target }} + + - name: Build + run: cargo build --release --target ${{ matrix.target }} + + - name: Upload artifact + uses: actions/upload-artifact@v4 + with: + name: ntu-${{ matrix.target }} + path: target/${{ matrix.target }}/release/ntu diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..079c6aa --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,66 @@ +name: Release + +on: + push: + tags: + - 'v*' + +permissions: + contents: write + +jobs: + release: + name: Release + runs-on: ${{ matrix.os }} + strategy: + matrix: + include: + - os: ubuntu-latest + target: x86_64-unknown-linux-gnu + artifact_name: ntu + asset_name: ntu-linux-x86_64 + - os: ubuntu-latest + target: x86_64-unknown-linux-musl + artifact_name: ntu + asset_name: ntu-linux-x86_64-musl + - os: macos-latest + target: x86_64-apple-darwin + artifact_name: ntu + asset_name: ntu-macos-x86_64 + - os: macos-latest + target: aarch64-apple-darwin + artifact_name: ntu + asset_name: ntu-macos-arm64 + + steps: + - uses: actions/checkout@v4 + + - name: Install Rust + uses: dtolnay/rust-toolchain@stable + with: + target: ${{ matrix.target }} + + - name: Install musl-tools (Linux musl only) + if: matrix.target == 'x86_64-unknown-linux-musl' + run: sudo apt-get update && sudo apt-get install -y musl-tools + + - name: Build + run: cargo build --release --target ${{ matrix.target }} + + - name: Strip binary (Linux only) + if: startsWith(matrix.os, 'ubuntu') + run: strip target/${{ matrix.target }}/release/${{ matrix.artifact_name }} + + - name: Compress binary + run: | + cd target/${{ matrix.target }}/release + tar czf ${{ matrix.asset_name }}.tar.gz ${{ matrix.artifact_name }} + mv ${{ matrix.asset_name }}.tar.gz ../../.. + + - name: Upload binary to release + uses: softprops/action-gh-release@v2 + with: + files: ${{ matrix.asset_name }}.tar.gz + body_path: CHANGELOG.md + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/README.md b/README.md index f45cd57..3b36c81 100644 --- a/README.md +++ b/README.md @@ -1,5 +1,11 @@ -# Filename Repair Tool for Linux -# "NameToUnix" +# NameToUnix + +[![CI](https://github.com/jamulix/NameToUnix/workflows/CI/badge.svg)](https://github.com/jamulix/NameToUnix/actions) +[![Release](https://github.com/jamulix/NameToUnix/workflows/Release/badge.svg)](https://github.com/jamulix/NameToUnix/releases) +[![Version](https://img.shields.io/github/v/release/jamulix/NameToUnix)](https://github.com/jamulix/NameToUnix/releases) +[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT) + +**Filename Repair Tool for Linux** · Binary: `ntu` (german and english) @@ -41,6 +47,29 @@ Dies ist mein erstes Programm in Rust. (Bitte seid gnädig.) ## Installation +### Option 1: Pre-built Binary (Recommended) + +Download the latest release for your platform from [GitHub Releases](https://github.com/jamulix/NameToUnix/releases): + +```bash +# Linux x86_64 +wget https://github.com/jamulix/NameToUnix/releases/latest/download/ntu-linux-x86_64.tar.gz +tar xzf ntu-linux-x86_64.tar.gz +sudo mv ntu /usr/local/bin/ + +# macOS Intel +wget https://github.com/jamulix/NameToUnix/releases/latest/download/ntu-macos-x86_64.tar.gz +tar xzf ntu-macos-x86_64.tar.gz +sudo mv ntu /usr/local/bin/ + +# macOS Apple Silicon (M1/M2) +wget https://github.com/jamulix/NameToUnix/releases/latest/download/ntu-macos-arm64.tar.gz +tar xzf ntu-macos-arm64.tar.gz +sudo mv ntu /usr/local/bin/ +``` + +### Option 2: Build from Source + Die ausführbare Datei wird unter `target/release/ntu` erstellt. Du solltest sie mit 'sudo cp target/release/ntu /usr/local/bin/' kopieren. Sie ist dann für alle User verfügbar. Denke daran, die Konfiguationsdatei (s. u.) ebenfalls zu kopieren. Sie kann für jeden User individuell angepasst werden, wenn sie im home-Verzeichnis des Users liegt. The executable file is created under `target/release/ntu`. You should copy it with 'sudo cp target/release/ntu /usr/local/bin/'. It is then available for all users. Remember to copy the configuration file (see below) as well. It can be customized for each user individually if it is located in the user's home directory. @@ -58,6 +87,11 @@ sudo cp .NameToUnix.conf /etc/NameToUnix/config.toml # Copy config file to # Lokale Einstellungen / Local settings mkdir -p ~/.config/NameToUnix/ # Create a personal config directory for NameToUnix cp .NameToUnix.conf ~/.config/NameToUnix/config.toml # Copy config file to this personal directory + +# Bash-Completion (optional) +sudo cp completions/ntu.bash /etc/bash_completion.d/ntu # Bash completion +# Oder für Zsh: +sudo cp completions/_ntu /usr/share/zsh/site-functions/_ntu # Zsh completion ``` ## Usage diff --git a/completions/_ntu b/completions/_ntu new file mode 100644 index 0000000..47fc572 --- /dev/null +++ b/completions/_ntu @@ -0,0 +1,22 @@ +#compdef ntu + +# Zsh completion for ntu (NameToUnix) + +_ntu() { + local curcontext="$curcontext" state line + typeset -A opt_args + + _arguments -C \ + '(-n --dry-run --no-changes)'{-n,--dry-run,--no-changes}'[Only preview changes without renaming]' \ + '(-q --quiet)'{-q,--quiet}'[Suppress output]' \ + '(-f --force)'{-f,--force}'[Overwrite existing files]' \ + '*'{-e,--exclude}'[Exclude pattern]:pattern:' \ + '(-v --verbose)'{-v,--verbose}'[Verbose debug output]' \ + '--modify-root[Also rename root directory]' \ + '--special[Process symlinks and special files]' \ + '(-h --help)'{-h,--help}'[Print help]' \ + '(-V --version)'{-V,--version}'[Print version]' \ + '*:path:_files' +} + +_ntu "$@" diff --git a/completions/ntu.bash b/completions/ntu.bash new file mode 100644 index 0000000..8ee4093 --- /dev/null +++ b/completions/ntu.bash @@ -0,0 +1,35 @@ +# Bash completion for ntu (NameToUnix) + +_ntu_completion() { + local cur prev opts + COMPREPLY=() + cur="${COMP_WORDS[COMP_CWORD]}" + prev="${COMP_WORDS[COMP_CWORD-1]}" + + # All available options + opts="--dry-run --no-changes --quiet --force --exclude --verbose --modify-root --special --help --version -n -q -f -e -v -h -V" + + # Handle options that require arguments + case "${prev}" in + -e|--exclude) + # Suggest glob patterns + COMPREPLY=( $(compgen -W '"*.tmp" "*.log" "*.bak" "*.swp" "*~"' -- ${cur}) ) + return 0 + ;; + *) + ;; + esac + + # If current word starts with -, complete with options + if [[ ${cur} == -* ]] ; then + COMPREPLY=( $(compgen -W "${opts}" -- ${cur}) ) + return 0 + fi + + # Otherwise complete with directories and files + COMPREPLY=( $(compgen -f -- ${cur}) ) + return 0 +} + +# Register completion function +complete -F _ntu_completion ntu