Skip to content

Enhancement: copy a file into the same folder #60

Description

@desgua

I've made a simple script that can be added to ~/.config/cfiles/scripts/cpself

#!/bin/bash
# version .2 fixed names with spaces
#
folder="$(printf "%s" "$1" | sed 's|\(.*\)/.*|\1|')"
file="$(printf "%s" "$1" | sed 's|.*/||')"

echo "Entering $folder "

cd "$folder"
if [ "$?" != "0" ]; then 
    echo "Failed to enter folder $folder "
    echo "Exiting..."
    read -r leave
    exit 1
fi

NAME () {
    printf "Copy %s -> " "$file"
    read  -r name
}

NAME;
while [ -f "$name" ]; do
    echo "The name \"$name\" already exists in this folder."
    NAME;
done

cp -v "$file" "$name"



Activity

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions