2021-04-28 13:19:04 +00:00
|
|
|
<div align="center">
|
|
|
|
|
2021-04-28 13:26:44 +00:00
|
|
|
# fif
|
|
|
|
|
2021-04-28 13:19:04 +00:00
|
|
|
![A screenshot demonstrating fif's ability to detect the correct file extensions for a few files.
|
2021-04-28 13:23:22 +00:00
|
|
|
](https://gitlab.com/Lynnesbian/fif/-/raw/master/doc/screenshot.png)
|
2021-04-28 13:19:04 +00:00
|
|
|
|
2021-04-21 06:09:55 +00:00
|
|
|
[![Version](https://img.shields.io/crates/v/fif.svg?logo=rust&style=flat-square)
|
|
|
|
](https://crates.io/crates/fif)
|
2021-04-21 07:29:13 +00:00
|
|
|
[![Minimum Supported Rust Version](https://img.shields.io/badge/msrv-1.43.0-orange?logo=rust&style=flat-square)
|
2021-08-25 05:25:22 +00:00
|
|
|
](https://gitlab.com/Lynnesbian/fif/-/blob/master/README.md#version-policy)
|
2021-04-21 06:09:55 +00:00
|
|
|
[![License](https://img.shields.io/crates/l/fif.svg?style=flat-square)
|
2021-04-21 07:29:13 +00:00
|
|
|
](https://gitlab.com/Lynnesbian/fif/-/blob/master/LICENSE)
|
2021-05-06 16:53:25 +00:00
|
|
|
[![Build status](https://img.shields.io/gitlab/pipeline/Lynnesbian/fif/master?logo=gitlab&style=flat-square)
|
2021-04-26 10:52:14 +00:00
|
|
|
](https://gitlab.com/Lynnesbian/fif/-/pipelines/latest)
|
2021-04-21 06:09:55 +00:00
|
|
|
[![Unsafe forbidden](https://img.shields.io/badge/unsafe-forbidden-success.svg?style=flat-square)
|
|
|
|
](https://github.com/rust-secure-code/safety-dance/)
|
2021-08-03 05:29:52 +00:00
|
|
|
[![Dependency versions](https://deps.rs/repo/gitlab/lynnesbian/fif/status.svg)
|
|
|
|
](https://deps.rs/repo/gitlab/lynnesbian/fif)
|
2021-02-21 16:15:35 +00:00
|
|
|
|
2021-04-28 13:19:04 +00:00
|
|
|
*A command-line tool for detecting and optionally correcting files with incorrect extensions.*
|
|
|
|
</div>
|
2021-02-21 15:55:27 +00:00
|
|
|
|
2021-04-06 15:47:12 +00:00
|
|
|
fif recursively scans the given directory and outputs a shell script to fix the name of any files with incorrect
|
|
|
|
extensions. By default, fif will scan all non-hidden files in the given directory, and will ignore symlinks.
|
|
|
|
|
|
|
|
As fif prints a shell script to stdout rather than acting on the files directly, you may wish to redirect its output to
|
|
|
|
a file, e.g. `fif ~/Documents > output.sh`. You can also pipe the output directly into your shell, e.g.
|
|
|
|
`fif ~/Documents | bash`, although this is not recommended - you should look over fif's output and verify for yourself
|
2021-07-06 14:24:02 +00:00
|
|
|
that it won't do anything that will give you a headache before running it.
|
2021-04-06 15:47:12 +00:00
|
|
|
|
2021-05-09 23:44:39 +00:00
|
|
|
## Features
|
|
|
|
- :white_check_mark: Cross platform
|
|
|
|
- :white_check_mark: Multi-threaded
|
|
|
|
- :white_check_mark: Configurable
|
|
|
|
|
|
|
|
## Building
|
|
|
|
fif can be built, installed, and tested with [Cargo], as with most rust programs:
|
|
|
|
```bash
|
|
|
|
git clone https://gitlab.com/Lynnesbian/fif/
|
|
|
|
cd fif
|
|
|
|
# run tests (optional)
|
|
|
|
cargo test --locked
|
|
|
|
# build fif with its default feature set
|
|
|
|
cargo build --locked --release
|
|
|
|
```
|
|
|
|
The `--locked` flag ensures that Cargo uses the dependency versions specified in [the lock
|
|
|
|
file](https://gitlab.com/Lynnesbian/fif/-/blob/master/Cargo.lock), and the `--release` flag builds fif with release
|
|
|
|
optimisations enabled -- this takes longer, but produces a much faster binary.
|
|
|
|
|
|
|
|
### Installing
|
2021-02-21 15:55:27 +00:00
|
|
|
```bash
|
2021-05-09 23:44:39 +00:00
|
|
|
# install the fif crate (to ~/.cargo/bin or %USERPROFILE%\.cargo\bin by default)
|
2021-02-21 15:55:27 +00:00
|
|
|
cargo install --locked fif
|
|
|
|
```
|
|
|
|
|
2021-05-09 23:44:39 +00:00
|
|
|
To update, simply re-run the `install` command, or use a tool like [cargo-update
|
|
|
|
](https://github.com/nabijaczleweli/cargo-update), which can update crates installed via `cargo install`.
|
2021-04-06 15:47:12 +00:00
|
|
|
|
2021-06-28 12:04:10 +00:00
|
|
|
On macOS, `fif` can now be installed using [MacPorts](https://www.macports.org), via the following steps:
|
|
|
|
```bash
|
|
|
|
$ sudo port selfupdate
|
|
|
|
$ sudo port install fif
|
|
|
|
```
|
|
|
|
|
2021-05-09 23:44:39 +00:00
|
|
|
### Cargo Features
|
|
|
|
fif supports using [`infer`] or [`xdg-mime`] as its backend for looking up file types. By default, xdg-mime will be
|
|
|
|
used on [*nix systems](https://en.wikipedia.org/wiki/Unix-like) (Linux, macOS, *BSD, etc.), and infer on all other
|
|
|
|
systems.
|
2021-02-27 02:43:15 +00:00
|
|
|
|
2021-05-09 23:44:39 +00:00
|
|
|
`xdg-mime` should work on any *nix system with the [Shared MIME Info] library installed (consult your package
|
|
|
|
manager), although I've only tested it on Linux and FreeBSD. `infer` should work on any system.
|
2021-02-27 02:43:15 +00:00
|
|
|
|
|
|
|
You can override the default backend for your system at compile time like so:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
# xdg-mime
|
2021-05-09 23:44:39 +00:00
|
|
|
cargo install fif --locked --features=xdg-mime-backend
|
2021-02-27 02:43:15 +00:00
|
|
|
# infer
|
2021-05-09 23:44:39 +00:00
|
|
|
cargo install fif --locked --features=infer-backend
|
2021-04-06 15:47:12 +00:00
|
|
|
```
|
|
|
|
|
2021-05-09 23:44:39 +00:00
|
|
|
It is also possible to get a more minimal build by installing without default features:
|
2021-04-06 15:47:12 +00:00
|
|
|
```bash
|
2021-05-09 23:44:39 +00:00
|
|
|
cargo install fif --locked --no-default-features
|
2021-02-27 02:43:15 +00:00
|
|
|
```
|
2021-05-09 23:44:39 +00:00
|
|
|
This will disable some non-essential but nice to have features, like multi-threading support.
|
|
|
|
|
|
|
|
For more info on fif's compile-time features, see [the wiki](https://gitlab.com/Lynnesbian/fif/-/wikis/Cargo-Features).
|
2021-02-27 02:43:15 +00:00
|
|
|
|
2021-02-21 15:55:27 +00:00
|
|
|
## Usage
|
2021-02-21 16:08:08 +00:00
|
|
|
See `fif --help` for more.
|
|
|
|
|
|
|
|
### The basics
|
|
|
|
The simplest way to use fif looks like this:
|
2021-04-06 15:47:12 +00:00
|
|
|
|
2021-02-21 16:08:08 +00:00
|
|
|
```bash
|
2021-04-06 15:47:12 +00:00
|
|
|
fif ~/Downloads
|
2021-02-21 16:08:08 +00:00
|
|
|
```
|
|
|
|
|
2021-04-06 15:47:12 +00:00
|
|
|
This command will scan all non-hidden files in your `~/Downloads` directory.
|
2021-02-21 16:08:08 +00:00
|
|
|
|
2021-05-09 23:44:39 +00:00
|
|
|
The `-e` and `-E` flags can be used to specify individual extensions and sets of extensions to scan, respectively:
|
2021-02-21 16:08:08 +00:00
|
|
|
|
2021-02-21 15:55:27 +00:00
|
|
|
```bash
|
2021-05-09 23:44:39 +00:00
|
|
|
# only scan files with the extensions .jpeg, .jpg, .zip, and .docx
|
2021-02-21 16:08:08 +00:00
|
|
|
fif -e jpeg,jpg,zip,docx ~/Documents
|
2021-05-09 23:44:39 +00:00
|
|
|
# only scan files with "image extensions" - .jpg, .png, .gif, .webp...
|
|
|
|
fif -E images ~/Pictures
|
|
|
|
# scan .zip files, videos, and audio
|
|
|
|
fif -e zip -E videos,audio ~/Downloads
|
2021-02-21 16:08:08 +00:00
|
|
|
```
|
|
|
|
|
2021-05-09 23:44:39 +00:00
|
|
|
Both `-e` and `-E` have equivalent `-x` and `-X` flags that exclude the given extensions rather than including them:
|
2021-04-06 15:47:12 +00:00
|
|
|
```bash
|
2021-05-09 23:44:39 +00:00
|
|
|
# scan everything except filenames ending in .zip
|
|
|
|
fif -x zip ~/Downloads
|
|
|
|
# scan all files with image extensions, but not .jpg and .jpeg files
|
|
|
|
fif -x jpg,jpeg -E images ~/Pictures
|
|
|
|
# scan everything except text and system files
|
|
|
|
fif -X text,system ~/.local/share
|
2021-04-06 15:47:12 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
### Output
|
|
|
|
By default, fif will output a bash script (or PowerShell script on Windows) that can be used to fix all the files it
|
|
|
|
found with incorrect file extensions.
|
|
|
|
|
2021-02-21 16:08:08 +00:00
|
|
|
You might find it useful to output this script to a file (rather than to stdout):
|
|
|
|
|
|
|
|
```bash
|
2021-05-09 23:44:39 +00:00
|
|
|
fif ~/Documents > output.sh
|
2021-02-21 16:08:08 +00:00
|
|
|
```
|
2021-02-27 02:43:15 +00:00
|
|
|
|
2021-04-06 15:47:12 +00:00
|
|
|
You can also manually specify an output format to use:
|
|
|
|
|
|
|
|
```bash
|
|
|
|
fif -O powershell ~/Documents > output.ps1
|
|
|
|
```
|
2021-04-26 12:15:14 +00:00
|
|
|
|
|
|
|
### Logging
|
2021-04-28 12:20:10 +00:00
|
|
|
By default, fif will log any info, warnings, and errors encountered during execution. This can be changed with the `-v`
|
2021-04-26 12:15:14 +00:00
|
|
|
flag:
|
|
|
|
```bash
|
2021-04-28 12:20:10 +00:00
|
|
|
# also log debug info
|
2021-04-26 12:15:14 +00:00
|
|
|
fif -v ~/Downloads
|
2021-04-28 12:20:10 +00:00
|
|
|
# ...and trace info
|
2021-04-26 12:15:14 +00:00
|
|
|
fif -vv ~/Downloads
|
|
|
|
```
|
2021-04-28 12:20:10 +00:00
|
|
|
|
|
|
|
You can also reduce the level of logging with the `-q` flag:
|
|
|
|
```bash
|
|
|
|
# don't show info
|
|
|
|
fif -q ~/Downloads
|
|
|
|
# ...or warnings
|
|
|
|
fif -qq ~/Downloads
|
|
|
|
# ...or even errors!
|
|
|
|
fif -qqq ~/Downloads
|
|
|
|
```
|
|
|
|
|
2021-07-01 08:52:53 +00:00
|
|
|
The verbosity of the logging can also be modified by setting the environment variable `FIF_LOG` or `RUST_LOG` to `off`,
|
|
|
|
`trace`, `debug`, `info`, `warn`, or `error`. Values set by `FIF_LOG` override `RUST_LOG`, and both override the `-v`
|
|
|
|
and `-q` flags.
|
2021-04-26 12:15:14 +00:00
|
|
|
|
|
|
|
For example:
|
|
|
|
|
|
|
|
```bash
|
2021-04-28 12:20:10 +00:00
|
|
|
# show all levels except trace
|
2021-07-01 08:52:53 +00:00
|
|
|
FIF_LOG=debug fif ~/Downloads
|
2021-04-28 12:20:10 +00:00
|
|
|
# only show errors
|
2021-07-01 08:52:53 +00:00
|
|
|
FIF_LOG=error fif ~/Downloads
|
2021-04-26 12:15:14 +00:00
|
|
|
```
|
|
|
|
|
|
|
|
The five logging levels are used as follows:
|
|
|
|
| Level | Description | Example |
|
|
|
|
|-|-|-|
|
|
|
|
| error | Errors that cause fif to stop running | fif was unable to open the provided directory |
|
|
|
|
| warn | Warnings that don't cause fif to stop running | fif was unable to determine the mime type of a given file |
|
|
|
|
| info | Information pertaining to fif's status | The provided directory was scanned without issue, and no files are in need of renaming |
|
|
|
|
| debug | Debug information - usually not important to end users | The list of extensions fif will consider |
|
|
|
|
| trace | Trace info - usually not important to end users | "Found 15 items to check", "Scan successful", etc. |
|
2021-05-09 23:44:39 +00:00
|
|
|
|
|
|
|
For a more comprehensive explanation of all of fif's parameters and how to use them, run `fif --help` (or `fif -h` for
|
|
|
|
a more concise overview).
|
|
|
|
|
|
|
|
<!-- links -->
|
|
|
|
[Cargo]: https://doc.rust-lang.org/cargo/
|
|
|
|
[`xdg-mime`]: https://crates.io/crates/xdg-mime
|
|
|
|
[`infer`]: https://crates.io/crates/infer
|
2021-06-28 12:04:10 +00:00
|
|
|
[Shared MIME Info]: https://gitlab.freedesktop.org/xdg/shared-mime-info/
|
2021-08-25 05:25:22 +00:00
|
|
|
|
|
|
|
|
|
|
|
## Version policy
|
|
|
|
fif adheres to the [semantic versioning](https://semver.org/) principles. While fif remains at version 0.x, the version
|
|
|
|
number will be updated as follows:
|
|
|
|
- The MAJOR version will be bumped to 1 when I believe fif to be "feature complete".
|
|
|
|
- The MINOR version will be bumped whenever I add a fairly important feature to fif (in the past, this has been bumped
|
|
|
|
when adding the ability to exclude extensions, and when fif gained the ability to output a bash script rather than a
|
|
|
|
list of invalid filenames). The MINOR version will also be bumped when increasing the MSRV.
|
|
|
|
- The PATCH version will be bumped in all other cases, including minor feature additions (in the past, this has occurred
|
|
|
|
when adding features such as more output formats and the ignore flag).
|
|
|
|
|
|
|
|
If/when fif hits version 1.0, these rules will likely remain the same as they are now.
|
|
|
|
|
|
|
|
## License
|
|
|
|
Copyright (C) 2021 Lynnesbian
|
|
|
|
|
|
|
|
This program is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with this program. If not, see <https://www.gnu.org/licenses/>.
|