Skip to content

Instantly share code, notes, and snippets.

@thevillagehacker
Created August 24, 2024 16:19
Show Gist options
  • Save thevillagehacker/223c0301395fe8012793376b1bc7f647 to your computer and use it in GitHub Desktop.
Save thevillagehacker/223c0301395fe8012793376b1bc7f647 to your computer and use it in GitHub Desktop.

To integrate this progress bar feature directly into the system's core commands (cp, mv), you can create wrapper scripts around the existing commands and place them in a directory that is prioritized in the system's PATH. Here's how you can do it:

Step 1: Create Wrapper Scripts

Create scripts that wrap around the existing cp, mv commands and add the progress bar functionality.

1. Wrapper Script for cp:

#!/bin/bash

# cp wrapper with progress
rsync -ah --info=progress2 "$@"

2. Wrapper Script for mv:

#!/bin/bash

# mv wrapper with progress
rsync -ah --info=progress2 --remove-source-files "$@"

Step 2: Place Scripts in a Directory

  1. Create a Directory for the Wrappers:

    Create a directory where you will place these wrapper scripts:

    mkdir -p ~/.local/bin
  2. Save the Wrapper Scripts:

    Save the above scripts as cp, mv in ~/.local/bin/.

    Example:

    nano ~/.local/bin/cp

    (Paste the cp wrapper script and save it)

    nano ~/.local/bin/mv

    (Paste the mv wrapper script and save it)

  3. Make the Scripts Executable:

    Make sure the scripts are executable:

    chmod +x ~/.local/bin/cp
    chmod +x ~/.local/bin/mv

Step 3: Update the PATH

  1. Add ~/.local/bin to the PATH:

    Add the directory to your PATH by editing your shell configuration file (e.g., .bashrc or .zshrc):

    echo 'export PATH="$HOME/.local/bin:$PATH"' >> ~/.bashrc

    Then, reload your shell:

    source ~/.bashrc

Step 4: Test the Commands

Now, when you use cp, mv, the wrapper scripts will be executed, providing progress bars.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment