mananapr/cfiles

Enhancement: copy a file into the same folder

desgua opened this issue · 0 comments

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"