Skip to content

rdupz/prefixer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PREFIXER

The following README is a manual export.


NAME

prefixer −− Renames a file by changing the beginning of its name.

SYNOPSIS

prefixer [−vdh] [−b | [−so | −n]] [−c config] [−r regex] prefix file ...

DESCRIPTION

prefixer provides a convenient way to deal with prefixes in filenames. By defining a set of prefixes, prefixer is able to identify the current prefix(es) in the filename and to change it to prefix. The optional arguments allow to filter the input files and/or to choose how the prefix(es) are processed.

The first mandatory argument prefix is the one to applied on the filenames. The other mandatory argument file is the file to be renamed. Several files can be specified. Directories and links are processed like any other files.

CONFIGURATION

In order to define the set of prefixes to be used, you can fill at least one configuration file. The default configuration files are located (or may be created) at /etc/prefixer/prefixer.conf (system-wide) and $HOME/.prefixer.conf (per-user). The per-user configuration file overrides the system-wide configuration file. A random file can be used as the configuration file with the --config option: the specified file then overrides all the other configuration files.

In a configuration file, the content of one line is interpreted as one prefix. To define a set of prefixes on a single line, you can use a Perl regex: the syntax is /regex/. For example a line matching a word ending with - would contains : "/\w+-/". Lines containing only whitespaces are ignored. Prefixes containing forward slashes will raise an error. There are no other limitations.

To define a one-shot set of prefixes the --regex option should be used. It overrides all other configurations.

OPTIONS

The following options are available:
−b, −−blind

Blind mode set the prefix regardless the filename. Keep all existing prefixes and add prefix before them.

−n, −−no−update

Do not set prefix if other prefixes already exist.

−o, −−update−only

Rename file only if at least one prefix already exists.

−s, −−squash

Replace all prefixes with the single new one.

−c, −−config=config

Explicitly defines the configuration file.

−r, −−regex=regex

Override allowed prefixes with regex.

−d, −−dry−run

Perform a dry-run. Enable verbose mode.

−v, −−verbose

Verbose mode.

−h, −−help

Show this help.

EXIT STATUS

The prefixer utility exits 0 on success, and >0 if an error occurs.

EXAMPLES

Here is the best part.
In these examples the configuration defines 3 prefixes: A-, B-, C-.
$ prefixer A- foo-bar

Renames foo in A-foo-bar.

$ prefixer A- B-C-foo-bar

Renames B-C-foo in A-C-foo-bar.

$ prefixer --dry-run --squash --update-only A- B-C-foo-bar foobar

Shows that prefixer would rename B-C-foo in A-foo-bar and ignore foobar.

$ prefixer --blind A- B-C-foo-bar

Renames B-C-foo in A-B-C-foo-bar.

$ prefixer --regex ’X-Y-Z-’ --no-update Z- X-foo-bar

Does not update X-foo-bar because "X-" is a prefix matching the regex. A-, B- and C- are no longer prefixes.

SEE_ALSO

rename(1), mv(1)

BUGS

No known bugs.

Note however that prefixer is still in development, and may not work as expected. If you have any problems with it, please feel free to email me and let me know.

AUTHOR

Romain Duperré (romainduperre@gmail.com)


About

Prefix filenames with ease.

Resources

License

Stars

Watchers

Forks

Packages

No packages published