Skip to content

Replacement for file coreutils mv, cp, rm, touch for mere humans

Notifications You must be signed in to change notification settings

xixixao/human-utils

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Human Utils

These programs replace the standard UNIX commands for working with files: touch, mkdir, mv, cp, rm. The new utils are designed for interactive use and to prevent frustration and loss of data.

The new utils are new to create files and directories, move, copy and delete.

See Three letters are too long for shorter names and replacing the standard UNIX commands.

Comparison

Scenario:

📂 root // <- current working directory
 📂 dogs
 📂 cats
 📂 plants
  📜 daisy // text: 🌼
 📜 rugby // text: 🏉
 📜 tennis // text: 🎾
coreutils human-utils outcome
touch hockey new hockey N hockey
mkdir rocks
touch rocks/ruby
new rocks/ruby N rocks/ruby
mkdir rocks
echo 💎 > rocks/ruby
new rocks/ruby -- 💎 N rocks/ruby
  text: 💎
mkdir rocks new rocks/ N rocks/
mkdir rocks
cd rocks
c rocks* N rocks/
  current working directory
mv rugby dogs mov rugby dogs/ M rugby -> dogs/rugby
mv rugby tennis mov rugby tennis
... [y/N]? Enter
D tennis
M rugby -> tennis
rm -r dogs
mv cats dogs
mov cats dogs
... [y/N]? Enter
D dogs
M cats -> dogs
mv rugby tennis dogs mov rugby tennis dogs/ M rugby -> dogs/rugby
M tennis -> dogs/tennis
mkdir sports
mv rugby tennis sports
mov rugby tennis sports/ R rugby -> sports/rugby
R tennis -> sports/tennis
rm plants del plants
... [y/N]? Enter
D plants

Principles

By default ask for confirmation before any irreversible action

Irreversible actions include:

  • deleting a file or a directory
  • overwriting a file with different contents
  • overwriting a directory with different files contents

Do not change behavior based on the current state of the file tree

The UNIX mv a b command performs a very different operation based on whether b does not exist or is a directory or a file (a move or a rename with a possible overwrite). In human-utils you instead choose which operation to perform (either via the path separator suffix or via explicit options).

The only change in behavior based on the state of the file tree in human-utils is whether you will be asked to proceed or not.

Create directories on demand

If a directory is needed to perform any command, but it doesn't exist, it will be created. This applies to multiple nested directories as well. The behavior is similar to running the UNIX command mkdir -p with the appropriate argument before every operation.

Commands

new

Creates one or more files or directories.

Basic file creation
new F creates a file at the relative path F.
new --file F creates a file at the relative path F.
new --file F/ errors out. File names cannot end in path separators.
Basic directory creation
new D/ creates a directory at the relative path D.
new --directory D/ creates a directory at the relative path D.
new --directory D creates a directory at the relative path D.
-d is a shortcut for --directory
Creating multiple files/directories
new F1 F2 D1/ D2/ creates files at F1 and F2 and directories at D1 and D2.
new --file F --directory D creates a file at F and a directory at D.
new F -d D creates a file at F and a directory at D.
new --directory D1 --directory D2 creates directories at D1 and D2.
new D/{F1,F2,F3} creates files at D/F1, D/F2 and D/F3.
Initializing files with text
new F -- hello world creates a file at the relative path F with the UTF-8 string hello world\n.
new F1 F2 -- hello creates files at F1 and F2 with the UTF-8 string hello\n.
new F -- '' asks for a confirmation if a non-empty file exists at F and erases it.
Creating parent directories
new D1/D2/D3/ creates directories at D1, D1/D2 and D1/D2/D3.
new D1/D2/F creates directories at D1, D1/D2 and a file at D1/D2/F.

Three letters are too long

You can make aliases to these utils and even shadow existing UNIX commands. To avoid unexpected behavior in existing scripts, create the aliases only in interactive sessions.

In Fish shell this can be accomplished by amending the fish_greeting function:

function fish_greeting
    alias ne new
    alias mv mov
    alias re mov
    alias cp cop
    alias rm del # or `alias de del`
    # alias mkdir "new -d"
    # alias touch "new -f"
end

Change directory integration

It's convenient to both create a directory and navigate to it. You can set this up in your shell. The examples below use the command alias c.

Fish:

function c -d "quickly cd and create directory if needed" -w cd
  new -d $argv
  and cd $argv
end

About

Replacement for file coreutils mv, cp, rm, touch for mere humans

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages