fixred is a command line utility to fix outdated links in files with redirect URLs.

Overview

fixred

crate CI

fixred is a command line utility to fix outdated links in files with redirect URLs.

demo

Installation

fixred is installed via cargo package manager. libcurl is necessary as dependency.

cargo install fixred
fixred --help

If you don't have Rust toolchain, a Docker image is also available.

docker run -it --rm rhysd/fixred:latest --help

Usage

fixred checks redirects of URLs in text files. When a URL is redirected, fixred replaces it with the redirected one. fixred ignores invalid URLs or broken links (e.g. 404) to avoid false positives in extracted URLs.

See the help output for each flags, options, and arguments.

fixred --help

Fix files

Most basic usage is fixing files by passing them to command line arguments.

# Fix a file
fixred ./docs/usage.md

# Fix all files in a directory (recursively)
fixred ./docs

# Multiple paths can be passed
fixred ./README.md ./CONTRIBUTING.md ./docs

Note that fixred only handles UTF8 files. Non-UTF8 files are ignored. To know which files were ignored, try --verbose flag.

Fix stdin

When no argument is given, fixred reads stdin and outputs result to stdout.

cat ./docs/usage.md | fixred

Run via Docker container

Mount local directories with -v and pass an environment variable (if necessary) with -e. Running the Docker image executes fixred executable by default.

# Fix all files in ./docs
docker run -it --rm -v $(pwd):/app -e FIXRED_LOG=info rhysd/fixred:latest /app/docs

Passing the input via stdin is also possible. The result is output to stdout.

# Fix stdin and output the result to stdout
cat ./docs/usage.md | docker run -i --rm rhysd/fixred:latest

Redirect only once

By default, fixred follows redirects repeatedly and uses the last URL to replace. However, sometimes redirecting only once would be more useful. --shallow flag is available for it.

For example, link to raw README file in rhysd/vim-crystal repository (moved to vim-crystal/vim-crystal later) is redirected as follows.

  1. https://github.com/rhysd/vim-crystal/raw/master/README.md
  2. https://github.com/vim-crystal/vim-crystal/raw/master/README.md
  3. https://raw.githubusercontent.com/vim-crystal/vim-crystal/master/README.md

When you want to fix 1. to 2. but don't want to fix 1. to 3., --shallow is useful.

fixred --shallow ./README.md

Filtering URLs

When you want to fix only specific links in a file, filtering URLs with regular expressions is available. The following example fixes URLs which starts with https://github.com/ using --extract option.

fixred --extract '^https://github\.com/' ./docs

--ignore option is an invert version of --extract. URLs matched to the pattern are ignored. The following example avoids to resolve URLs which contain hashes.

fixred --ignore '#' ./docs

Verbose logs

By default, fixred outputs nothing when it runs successfully. For verbose log outputs, --verbose flag or $FIXRED_LOGi environment variable is available.

# Outputs which file is being processed
fixred --verbose
# Or
FIXRED_LOG=info fixred ./docs

# Outputs what fixred is doing in detail
FIXRED_LOG=debug fixred ./docs

Real-world examples

Use this tool as Rust library

Please see the API document. And for the real world example, please see src directory.

To install as dependency, add fixred to your Cargo.toml file. Ensure to disable default features. It removes all unnecessary dependencies for using this tool as library.

[dependencies]
fixred = { version = "1", default-features = false, features = [] }

Here is a small example code

use fixred::resolve::CurlResolver;
use fixred::redirect::Redirector;

fn main() {
    let red = Redirector::<CurlResolver>::default();
    let fixed = red.fix(std::io::stdin(), std::io::stdout()).unwrap();
    eprintln!("Fixed {} link(s)", fixed);
}

License

Distributed under the MIT license.

You might also like...
A CLI tool for getting screenshots of URLs using headless chrome

rustywitness đŸĻ€ 🌐 📸 Web screenshot utility A CLI tool for getting screenshots of URLs using headless chrome Built with ❤ī¸Ž by swanandx and contributo

CLI tool that extracts a regex pattern from a list of urls ( Rust )

rextract CLI tool that extracts a regex pattern from a list of urls. The tool is written in Rust and supports PCRE. Installation Step 1: Visit https:/

Generate Nix packages from URLs
Generate Nix packages from URLs

Generate Nix packages from URLs with hash prefetching, dependency inference, license detection, and more

Rust command line utility to quickly display useful secrets in a Kubernetes namespace
Rust command line utility to quickly display useful secrets in a Kubernetes namespace

kube-secrets This is a command line utility for quickly looking at secrets in a Kubernetes namespace that are typically looked at by humans. It specif

 A command-line utility that creates project structure.
A command-line utility that creates project structure.

petridish A command-line utility that creates project structure. If you have heard of the cookiecutter project, petridish is a rust implementation of

Command line utility for controlling LIFX smart lights

lifxc is a command line utility for controlling LIFX smart lights. Currently, communication over the LIFX LAN protocol is supported.

Gecko's trusty package manager and command-line utility.
Gecko's trusty package manager and command-line utility.

Geckos have super-powers, ya'know? Grip is Gecko's trusty package manager and command-line utility. USAGE: grip [FLAGS] [file] [SUBCOMMAND] FLAGS

A simplified recreation of the command-line utility grep written in Rust.

smolgrep A simplified recreation of the command-line utility grep written in Rust. Download and run Download Rust On Mac/Linux Open a terminal and ent

A utility for managing cargo dependencies from the command line.

cargo edit This tool extends Cargo to allow you to add, remove, and upgrade dependencies by modifying your Cargo.toml file from the command line. Curr

Comments
  • Bump regex from 1.5.4 to 1.5.5

    Bump regex from 1.5.4 to 1.5.5

    Bumps regex from 1.5.4 to 1.5.5.

    Changelog

    Sourced from regex's changelog.

    1.5.5 (2022-03-08)

    This releases fixes a security bug in the regex compiler. This bug permits a vector for a denial-of-service attack in cases where the regex being compiled is untrusted. There are no known problems where the regex is itself trusted, including in cases of untrusted haystacks.

    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Bump crossbeam-utils from 0.8.5 to 0.8.8

    Bump crossbeam-utils from 0.8.5 to 0.8.8

    Bumps crossbeam-utils from 0.8.5 to 0.8.8.

    Release notes

    Sourced from crossbeam-utils's releases.

    crossbeam-utils 0.8.8

    • Fix a bug when unstable loom support is enabled. (#787)

    crossbeam-utils 0.8.7

    • Add AtomicCell<{i*,u*}>::{fetch_max,fetch_min}. (#785)
    • Add AtomicCell<{i*,u*,bool}>::fetch_nand. (#785)
    • Fix unsoundness of AtomicCell<{i,u}64> arithmetics on 32-bit targets that support Atomic{I,U}64 (#781)

    crossbeam-utils 0.8.6

    • Re-add AtomicCell<{i,u}64>::{fetch_add,fetch_sub,fetch_and,fetch_or,fetch_xor} that were accidentally removed in 0.8.0 0.7.1 on targets that do not support Atomic{I,U}64. (#767)
    • Re-add AtomicCell<{i,u}128>::{fetch_add,fetch_sub,fetch_and,fetch_or,fetch_xor} that were accidentally removed in 0.8.0 0.7.1. (#767)
    Commits

    Dependabot compatibility score

    Dependabot will resolve any conflicts with this PR as long as you don't alter it yourself. You can also trigger a rebase manually by commenting @dependabot rebase.


    Dependabot commands and options

    You can trigger Dependabot actions by commenting on this PR:

    • @dependabot rebase will rebase this PR
    • @dependabot recreate will recreate this PR, overwriting any edits that have been made to it
    • @dependabot merge will merge this PR after your CI passes on it
    • @dependabot squash and merge will squash and merge this PR after your CI passes on it
    • @dependabot cancel merge will cancel a previously requested merge and block automerging
    • @dependabot reopen will reopen this PR if it is closed
    • @dependabot close will close this PR and stop Dependabot recreating it. You can achieve the same result by closing it manually
    • @dependabot ignore this major version will close this PR and stop Dependabot creating any more for this major version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this minor version will close this PR and stop Dependabot creating any more for this minor version (unless you reopen the PR or upgrade to it yourself)
    • @dependabot ignore this dependency will close this PR and stop Dependabot creating any more for this dependency (unless you reopen the PR or upgrade to it yourself)
    • @dependabot use these labels will set the current labels as the default for future PRs for this repo and language
    • @dependabot use these reviewers will set the current reviewers as the default for future PRs for this repo and language
    • @dependabot use these assignees will set the current assignees as the default for future PRs for this repo and language
    • @dependabot use this milestone will set the current milestone as the default for future PRs for this repo and language

    You can disable automated security fix PRs for this repo from the Security Alerts page.

    dependencies 
    opened by dependabot[bot] 0
  • Errors trying to build with Rust 1.59.0

    Errors trying to build with Rust 1.59.0

    Hello, I am trying to build the latest release from source using the latest Rust compiler but I am getting errors:

    /tmp/fixred-1.1.4 $ rustc --version
    rustc 1.59.0 (9d1b2106e 2022-02-23)
    
    /tmp/fixred-1.1.4 $ cargo build
       Compiling fixred v1.1.4 (/tmp/fixred-1.1.4)
    warning: use of deprecated struct `clap::App`: Replaced with `Command`
     --> src/main.rs:2:12
      |
    2 | use clap::{App, Arg};
      |            ^^^
      |
      = note: `#[warn(deprecated)]` on by default
    
    warning: use of deprecated struct `clap::App`: Replaced with `Command`
      --> src/main.rs:20:19
       |
    20 |     let matches = App::new("fixred")
       |                   ^^^
    
    error[E0599]: no method named `about` found for struct `Arg` in the current scope
      --> src/main.rs:39:18
       |
    39 |                 .about("Redirect only once when resolving a URL redirect")
       |                  ^^^^^ method not found in `Arg<'_>`
    
    error[E0599]: no method named `about` found for struct `Arg` in the current scope
      --> src/main.rs:47:18
       |
    47 |                 .about("Fix URLs which are matched to this pattern"),
       |                  ^^^^^ method not found in `Arg<'_>`
    
    error[E0599]: no method named `about` found for struct `Arg` in the current scope
      --> src/main.rs:55:18
       |
    55 |                 .about("Fix URLs which are NOT matched to this pattern"),
       |                  ^^^^^ method not found in `Arg<'_>`
    
    error[E0599]: no method named `about` found for struct `Arg` in the current scope
      --> src/main.rs:59:18
       |
    59 |                 .about(
       |                  ^^^^^ method not found in `Arg<'_>`
    
    error[E0599]: no method named `about` found for struct `Arg` in the current scope
      --> src/main.rs:70:18
       |
    70 |                 .about("Output verbose log. This is the same as setting \"info\" to $FIXRED_LOG environment variable")
       |                  ^^^^^ method not found in `Arg<'_>`
    
    For more information about this error, try `rustc --explain E0599`.
    warning: `fixred` (bin "fixred") generated 2 warnings
    error: could not compile `fixred` due to 5 previous errors; 2 warnings emitted
    
    opened by nomirose 0
Releases(v1.1.4)
  • v1.1.4(Oct 21, 2021)

  • v1.1.3(Sep 30, 2021)

    • Ignore non-UTF8 files. This is useful when you specify some directories to update files recursively. Now fixred fixes only UTF-8 files in directories recursively. Previously fixred stopped when finding a non-UTF8 file. To know which files were ignored, try --verbose flag.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.2(Sep 29, 2021)

    • Dependencies necessary only for building fixred executable are now optional. By removing executable feature, they can be omit on installing this tool as Rust library for less dependencies.
      [dependencies]
      fixred = { version = "1", default-features = false, features = [] }
      
    • Add an introduction dedicated for the API document. Previously README.md file at root of this repository was used but it is basically for fixred executable.
    Source code(tar.gz)
    Source code(zip)
  • v1.1.1(Sep 29, 2021)

  • v1.1.0(Sep 28, 2021)

  • v1.0.2(Sep 28, 2021)

  • v1.0.1(Sep 27, 2021)

  • v1.0.0(Sep 27, 2021)

Owner
Linda_pp
A dog enjoying software development (with bugs)
Linda_pp
Automatically replace Discord CDN links with local file links, by downloading the images to the public folder

Auto Undiscord Did you hear that Discord will be blocking external websites from using images hosted on their servers? Did you host every image on you

Dot32 5 Nov 17, 2023
Decode URLs in your files!

urldecoder English | įŽ€äŊ“中文 A tool to batch decode URLs in your files. A toy project written in Rust. Decoding URLs shortens the string length and incre

Absolutex 3 Feb 18, 2024
A tool to convert old and outdated "characters" into the superior Rustcii-Encoding.

rustcii A tool to convert old and outdated "characters" into the superior Rustcii-Encoding. Speak your mind. Blazingly ( ?? ) fast ( ?? ). Github | cr

null 8 Nov 16, 2022
Eslint - Find and fix problems in your JavaScript code.

ESLint Website | Configuring | Rules | Contributing | Reporting Bugs | Code of Conduct | Twitter | Mailing List | Chat Room ESLint is a tool for ident

ESLint 22k Jan 9, 2023
Fix the simple rust script as shown in README.md

Rust Fix Me Steps Create a Github account. (If you already have one no issues) Star this repository. Fork this repository to your Github account. Clon

Ganesh Chandrasekaran 48 Dec 9, 2022
đŸ”Ŗ nerdfix helps you to find/fix obsolete Nerd Font icons in your project.

?? nerdfix nerdfix helps you to find/fix obsolete Nerd Font icons in your project. ?? Why Nerd Fonts is used in many projects for a beautiful UI. It p

Loi Chyan 80 Apr 8, 2023
Fix broken crates instantly 🏃đŸŊ‍♀ī¸đŸ’¨

Patch-Crate patch-crate lets rust app developer instantly make and keep fixes to rust crate dependencies. It's a vital band-aid for those of us living

YiiSh 9 Nov 23, 2023
SA-MP client server list fix but written in Rust

Server List Fix This is a samp client server list fix, which reroutes the client's request to list.sa-mp.com to sam.markski.ar. The idea is originally

__SyS__ 4 Feb 4, 2024
Incredible.dev is an AI Coding Co-worker which can code, fix, document, deploy, test your APIs. One agent to rule everything API.

Incredible.dev Early Github preview, documentation and instruction to run coming soon in a week! Here are some highlights: AI agents that can code, fi

Incredible 27 Jun 27, 2024
Small command-line tool to switch monitor inputs from command line

swmon Small command-line tool to switch monitor inputs from command line Installation git clone https://github.com/cr1901/swmon cargo install --path .

William D. Jones 5 Aug 20, 2022