npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

ppend

v0.4.0

Published

Rename files or dirs via append, prepend, or cut (remove) - CLI and async API

Downloads

3

Readme

ppend

Simple CLI to rename files by appending, prepending, or cutting (removing) portions of filenames.

A better alternative to calling mv several times or having to memorize some funky find . -exec syntax.

CLI

Install

$ npm install -g ppend

Usage

$ ppend [options] <text> <file-pattern> [file-pattern2 ... file-patternN]

Append <text> to names of files or directories matching the given <file-pattern>s, preserving file extensions.

Options

-p, --pre

Prepend to file names instead of append. Mutually exclusive with -x.

-x, --cut

Remove from file names instead of append. Mutually exclusive with -p. If both options are given, -x will take precedence. Cuts the first occurrence only.

-v, --verbose

Print all attempted pseudo mv commands to stdout.

-n, --dry-run

Test the command by printing all attempted pseudo mv commands to stdout without actually renaming anything (no-op).

-V, --version

Print current version of ppend instead. If actual arguments are given, this option will be ignored.

Examples

$ echo 'setup some arbitrary files'
$ mkdir files
$ touch file1.txt file2.log file3 files/file4.sh
$ ls -Alh *
-rw-r--r--  1 user  group     0B Jan 16 13:43 file1.txt
-rw-r--r--  1 user  group     0B Jan 16 13:43 file2.log
-rw-r--r--  1 user  group     0B Jan 16 13:43 file3

files:
total 0
-rw-r--r--  1 user  group     0B Jan 16 13:43 file4.sh
$ echo 'append "-OLD" to each file and dir name'
$ ppend -OLD file* **/file*
$
$ ls -Alh *
-rw-r--r--  1 user  group     0B Jan 16 13:43 file1-OLD.txt
-rw-r--r--  1 user  group     0B Jan 16 13:43 file2-OLD.log
-rw-r--r--  1 user  group     0B Jan 16 13:43 file3-OLD

files-OLD:
total 0
-rw-r--r--  1 user  group     0B Jan 16 13:43 file4-OLD.sh
$ echo 'prepend "new-" to dir name'
$ ppend -p new- files-OLD/
$
$ ls -Alh
-rw-r--r--   1 user  group     0B Jan 16 13:43 file1-OLD.txt
-rw-r--r--   1 user  group     0B Jan 16 13:43 file2-OLD.log
-rw-r--r--   1 user  group     0B Jan 16 13:43 file3-OLD
drwxr-xr-x   3 user  group   102B Jan 16 13:52 new-files-OLD
$ echo 'cut "-OLD" from file names'
$ ppend -x -OLD file* **/file*
$
$ ls -Alh *
-rw-r--r--  1 user  group     0B Jan 16 13:43 file1.txt
-rw-r--r--  1 user  group     0B Jan 16 13:43 file2.log
-rw-r--r--  1 user  group     0B Jan 16 13:43 file3

new-files-OLD:
total 0
-rw-r--r--  1 user  group     0B Jan 16 13:43 file4.sh
$ echo 'cut "new-" and "-OLD" from dir name'
$ ppend -x new- new* && ppend -x -OLD *-OLD
$
$ ls -Alh
-rw-r--r--   1 user  group     0B Jan 16 13:43 file1.txt
-rw-r--r--   1 user  group     0B Jan 16 13:43 file2.log
-rw-r--r--   1 user  group     0B Jan 16 13:43 file3
drwxr-xr-x   3 user  group   102B Jan 16 14:04 files
$ echo 'prepend "new-" to files with extensions'
$ ppend -p new- file*.* **/file*.*
$
$ ls -Alh *
-rw-r--r--  1 user  group     0B Jan 16 13:43 file3
-rw-r--r--  1 user  group     0B Jan 16 13:43 new-file1.txt
-rw-r--r--  1 user  group     0B Jan 16 13:43 new-file2.log

files:
total 0
-rw-r--r--  1 user  group     0B Jan 16 13:43 new-file4.sh

Module

Install

$ npm install --save ppend

API

var ppend = require('ppend');

ppend(text, patterns, opts={}, callback);

text: Required - String of text to append/prepend/cut from matched file names.

patterns: Required - String or Array of strings defining globby patterns for files or directories that should be renamed.

opts: Optional - Object containing properties of desired options. See Options below.

callback: Optional - Function to call once all matched files or directories have been renamed. See Callback below.

Options

var opts = {

	pre: true || false, //Prepend to file name instead of append

	cut: true || false, //Cut (remove) from file name instead of append,
	                    //first occurrence only

	verbose: true || false //Print pseudo commands to stdout

    dryRun: true || false //Print pseudo commands without actually
                          //renaming anything (no-op)

};

Callback

var cb = function(err, errs) {
	// An error for each file is possible.
	//
	// err: Error object - the first error to occur.
	// errs: Array of Error objects - all errors that occurred.
	//
	// Both err and errs will be undefined on success.
	// If any error occurred, both args will be populated,
	// and the first element of errs will be err.

	if(err) {
		// at least one failure
	} else {
		// success!
	}
};

Roadmap

0.4.0

  • ~~Add option for "dry run"~~ Done

0.4.x

  • Add tests

1.0.0

  • Tests are stable (100% code coverage)
  • No issues found/reported for 1+ weeks

License

MIT, © 2015 Andrew Goode