fixred
fixred is a command line utility to fix outdated links in files with redirect URLs.
Installation
fixred is installed via cargo package manager. libcurl is necessary as dependency.
If you don't have Rust toolchain, a Docker image is also available.
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.
Fix files
Most basic usage is fixing files by passing them to command line arguments.
# Fix a file
# Fix all files in a directory (recursively)
# Multiple paths can be passed
Fix stdin
When no argument is given, fixred reads stdin and outputs result to stdout.
|
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
Passing the input via stdin is also possible. The result is output to stdout.
# Fix stdin and output the result to stdout
|
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.
- https://github.com/rhysd/vim-crystal/raw/master/README.md
- https://github.com/vim-crystal/vim-crystal/raw/master/README.md
- 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.
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.
--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.
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
# Or
FIXRED_LOG=info
# Outputs what fixred is doing in detail
FIXRED_LOG=debug
Real-world example
- https://github.com/rhysd/actionlint/commit/0b7375279d2caf63203701eccc39ab091cc83a50
- https://github.com/rhysd/actionlint/commit/a3f270b313affa81cc41709587cbd2588d4ac4ce
Here is an example of usage in actionlint project.
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.
[]
= "1"
Here is a small example code
use CurlResolver;
use Redirector;
License
Distributed under the MIT license.