Finalize minor bug fixes and format for deployment
This commit is contained in:
		
							
								
								
									
										116
									
								
								bin/cptemplate
									
									
									
									
									
								
							
							
						
						
									
										116
									
								
								bin/cptemplate
									
									
									
									
									
								
							@@ -11,7 +11,7 @@ fd_opts=(--type f --threads "$(nproc)")
 | 
			
		||||
 | 
			
		||||
# Helper functions
 | 
			
		||||
function help() {
 | 
			
		||||
	cat <<HELPMESSAGE
 | 
			
		||||
    cat << HELPMESSAGE
 | 
			
		||||
$(basename "$0") $VERSION
 | 
			
		||||
 | 
			
		||||
Usage: $(basename "$0") [-h] [-d DIR] [-f] dest
 | 
			
		||||
@@ -28,77 +28,77 @@ HELPMESSAGE
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
while true; do
 | 
			
		||||
	case "${1}" in
 | 
			
		||||
	'-d' | '--dir')
 | 
			
		||||
		template_dir="${2}"
 | 
			
		||||
		case "${DIR}" in
 | 
			
		||||
		"")
 | 
			
		||||
			exit 1
 | 
			
		||||
			;;
 | 
			
		||||
		-*)
 | 
			
		||||
			exit 1
 | 
			
		||||
			;;
 | 
			
		||||
		esac
 | 
			
		||||
		shift 2
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	--dir=*)
 | 
			
		||||
		template_dir="${1#*=}"
 | 
			
		||||
		case "${DIR}" in
 | 
			
		||||
		"")
 | 
			
		||||
			exit 1
 | 
			
		||||
			;;
 | 
			
		||||
		-*)
 | 
			
		||||
			exit 1
 | 
			
		||||
			;;
 | 
			
		||||
		esac
 | 
			
		||||
		shift
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	'-f' | '--force')
 | 
			
		||||
		FORCE_OVERWRITE='--force'
 | 
			
		||||
		shift
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	'-h' | '--help')
 | 
			
		||||
		help
 | 
			
		||||
		exit
 | 
			
		||||
		;;
 | 
			
		||||
	--)
 | 
			
		||||
		shift
 | 
			
		||||
		break
 | 
			
		||||
		;;
 | 
			
		||||
	-*)
 | 
			
		||||
		printf '%s\n' "Unknown option: ${1}" >&2
 | 
			
		||||
		exit 1
 | 
			
		||||
		;;
 | 
			
		||||
	*)
 | 
			
		||||
		break
 | 
			
		||||
		;;
 | 
			
		||||
	esac
 | 
			
		||||
    case "${1}" in
 | 
			
		||||
        '-d' | '--dir')
 | 
			
		||||
            template_dir="${2}"
 | 
			
		||||
            case "${template_dir}" in
 | 
			
		||||
                "")
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
                -*)
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
            esac
 | 
			
		||||
            shift 2
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        --dir=*)
 | 
			
		||||
            template_dir="${1#*=}"
 | 
			
		||||
            case "${template_dir}" in
 | 
			
		||||
                "")
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
                -*)
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
            esac
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        '-f' | '--force')
 | 
			
		||||
            FORCE_OVERWRITE='--force'
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        '-h' | '--help')
 | 
			
		||||
            help
 | 
			
		||||
            exit
 | 
			
		||||
            ;;
 | 
			
		||||
        --)
 | 
			
		||||
            shift
 | 
			
		||||
            break
 | 
			
		||||
            ;;
 | 
			
		||||
        -*)
 | 
			
		||||
            printf '%s\n' "Unknown option: ${1}" >&2
 | 
			
		||||
            exit 1
 | 
			
		||||
            ;;
 | 
			
		||||
        *)
 | 
			
		||||
            break
 | 
			
		||||
            ;;
 | 
			
		||||
    esac
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# If no target specified
 | 
			
		||||
if [[ -z "$1" ]]; then
 | 
			
		||||
	printf '%s\n' 'Please specify target name'
 | 
			
		||||
	exit 1
 | 
			
		||||
    help
 | 
			
		||||
    exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
# Check if template directory exists
 | 
			
		||||
if ! [[ -d "$template_dir" ]]; then
 | 
			
		||||
	printf '%s\n' "Template directory doesn't exist, exiting."
 | 
			
		||||
	exit 2
 | 
			
		||||
    printf '%s\n' "Template directory doesn't exist, exiting."
 | 
			
		||||
    exit 2
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
files="$("${fd_opts[@]}" "$DIR")"
 | 
			
		||||
files="$(fd "${fd_opts[@]}" -- . "$template_dir")"
 | 
			
		||||
selected_file="$(fzf --select-1 --exit-0 <<< "$files")"
 | 
			
		||||
 | 
			
		||||
# Check if target exists
 | 
			
		||||
if [[ -f "$1" && -z "$FORCE_OVERWRITE" ]]; then
 | 
			
		||||
	printf '%s\n' 'File already exists, exiting'
 | 
			
		||||
	exit 1
 | 
			
		||||
    printf '%s\n' 'File already exists, exiting'
 | 
			
		||||
    exit 1
 | 
			
		||||
elif [[ -f "$1" && -n "$FORCE_OVERWRITE" ]]; then
 | 
			
		||||
	cp --verbose --force -- "$selected_file" "$1"
 | 
			
		||||
    cp --verbose --force -- "$selected_file" "$1"
 | 
			
		||||
else
 | 
			
		||||
	cp --verbose -- "$selected_file" "$1"
 | 
			
		||||
    cp --verbose -- "$selected_file" "$1"
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										144
									
								
								bin/fedit
									
									
									
									
									
								
							
							
						
						
									
										144
									
								
								bin/fedit
									
									
									
									
									
								
							@@ -13,7 +13,7 @@ fd_opts=(--hidden --type file --type symlink --threads "$(nproc)")
 | 
			
		||||
 | 
			
		||||
# Helper functions
 | 
			
		||||
function help() {
 | 
			
		||||
	cat <<HELPMESSAGE
 | 
			
		||||
    cat << HELPMESSAGE
 | 
			
		||||
$(basename "$0") $VERSION
 | 
			
		||||
 | 
			
		||||
Usage: $(basename "$0") [-h|--help] [options] [patterns]
 | 
			
		||||
@@ -31,88 +31,88 @@ HELPMESSAGE
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
while true; do
 | 
			
		||||
	case "${1}" in
 | 
			
		||||
	'-b' | '--boot')
 | 
			
		||||
		EDIT_BOOT=1
 | 
			
		||||
		shift
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	'-d' | '--dir')
 | 
			
		||||
		DIR="${2}"
 | 
			
		||||
		case "${DIR}" in
 | 
			
		||||
		"")
 | 
			
		||||
			exit 1
 | 
			
		||||
			;;
 | 
			
		||||
		-*)
 | 
			
		||||
			exit 1
 | 
			
		||||
			;;
 | 
			
		||||
		esac
 | 
			
		||||
		shift 2
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	--dir=*)
 | 
			
		||||
		DIR="${1#*=}"
 | 
			
		||||
		case "${DIR}" in
 | 
			
		||||
		"")
 | 
			
		||||
			exit 1
 | 
			
		||||
			;;
 | 
			
		||||
		-*)
 | 
			
		||||
			exit 1
 | 
			
		||||
			;;
 | 
			
		||||
		esac
 | 
			
		||||
		shift
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	'-E' | '--etc')
 | 
			
		||||
		EDIT_ETC=1
 | 
			
		||||
		shift
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	'-i' | '--no-ignore-vcs')
 | 
			
		||||
        fd_opts+=(--no-ignore-vcs)
 | 
			
		||||
		shift
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	'-I' | '--no-ignore')
 | 
			
		||||
        fd_opts+=(--no-ignore)
 | 
			
		||||
		shift
 | 
			
		||||
		continue
 | 
			
		||||
		;;
 | 
			
		||||
	'-h' | '--help')
 | 
			
		||||
		help
 | 
			
		||||
		exit
 | 
			
		||||
		;;
 | 
			
		||||
	--)
 | 
			
		||||
		shift
 | 
			
		||||
		break
 | 
			
		||||
		;;
 | 
			
		||||
	-*)
 | 
			
		||||
		printf '%s\n' "Unknown option: ${1}" >&2
 | 
			
		||||
		exit 1
 | 
			
		||||
		;;
 | 
			
		||||
	*)
 | 
			
		||||
		break
 | 
			
		||||
		;;
 | 
			
		||||
	esac
 | 
			
		||||
    case "${1}" in
 | 
			
		||||
        '-b' | '--boot')
 | 
			
		||||
            EDIT_BOOT=1
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        '-d' | '--dir')
 | 
			
		||||
            DIR="${2}"
 | 
			
		||||
            case "${DIR}" in
 | 
			
		||||
                "")
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
                -*)
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
            esac
 | 
			
		||||
            shift 2
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        --dir=*)
 | 
			
		||||
            DIR="${1#*=}"
 | 
			
		||||
            case "${DIR}" in
 | 
			
		||||
                "")
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
                -*)
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
            esac
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        '-E' | '--etc')
 | 
			
		||||
            EDIT_ETC=1
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        '-i' | '--no-ignore-vcs')
 | 
			
		||||
            fd_opts+=(--no-ignore-vcs)
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        '-I' | '--no-ignore')
 | 
			
		||||
            fd_opts+=(--no-ignore)
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        '-h' | '--help')
 | 
			
		||||
            help
 | 
			
		||||
            exit
 | 
			
		||||
            ;;
 | 
			
		||||
        --)
 | 
			
		||||
            shift
 | 
			
		||||
            break
 | 
			
		||||
            ;;
 | 
			
		||||
        -*)
 | 
			
		||||
            printf '%s\n' "Unknown option: ${1}" >&2
 | 
			
		||||
            exit 1
 | 
			
		||||
            ;;
 | 
			
		||||
        *)
 | 
			
		||||
            break
 | 
			
		||||
            ;;
 | 
			
		||||
    esac
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# Handle -b and -E, they are mutually exclusive
 | 
			
		||||
if [[ -n $EDIT_BOOT && -z $EDIT_ETC ]]; then
 | 
			
		||||
	DIR="$BOOT_DIR"
 | 
			
		||||
    DIR="$BOOT_DIR"
 | 
			
		||||
elif [[ -z $EDIT_BOOT && -n $EDIT_ETC ]]; then
 | 
			
		||||
	DIR="$ETC_DIR"
 | 
			
		||||
    DIR="$ETC_DIR"
 | 
			
		||||
elif [[ -n $EDIT_BOOT && -n $EDIT_ETC ]]; then
 | 
			
		||||
	printf '%s\n' 'Select either --boot or --etc, not both'
 | 
			
		||||
	exit 1
 | 
			
		||||
    printf '%s\n' 'Select either --boot or --etc, not both'
 | 
			
		||||
    exit 1
 | 
			
		||||
elif [[ -z $DIR ]]; then
 | 
			
		||||
	DIR='.'
 | 
			
		||||
    DIR='.'
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
files="$(find_files $DIR "${fd_opts[@]}")"
 | 
			
		||||
files="$(fd "${fd_opts[@]}" -- . $DIR)"
 | 
			
		||||
selected_file="$(fzf --select-1 --exit-0 <<< "$files")"
 | 
			
		||||
 | 
			
		||||
if [[ -w "${selected_file}" ]]; then
 | 
			
		||||
	"$EDITOR" "$selected_file"
 | 
			
		||||
    "$EDITOR" "$selected_file"
 | 
			
		||||
else
 | 
			
		||||
	sudo --edit "$selected_file"
 | 
			
		||||
    sudo --edit "$selected_file"
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
							
								
								
									
										17
									
								
								bin/quickdel
									
									
									
									
									
								
							
							
						
						
									
										17
									
								
								bin/quickdel
									
									
									
									
									
								
							@@ -14,6 +14,7 @@ WHITE_BOLD=$'\e[1;37m'
 | 
			
		||||
RESET=$'\e[0;0m'
 | 
			
		||||
 | 
			
		||||
fd_opts=(--hidden --threads "$(nproc)")
 | 
			
		||||
rm_opts=(--verbose)
 | 
			
		||||
declare -a typeopts
 | 
			
		||||
 | 
			
		||||
# Helper functions
 | 
			
		||||
@@ -105,7 +106,7 @@ while true; do
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
            esac
 | 
			
		||||
            fd_opts+=('--extension' "$EXT")
 | 
			
		||||
            fd_opts+=(--extension "$EXT")
 | 
			
		||||
            shift 2
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
@@ -119,7 +120,7 @@ while true; do
 | 
			
		||||
                    exit 1
 | 
			
		||||
                    ;;
 | 
			
		||||
            esac
 | 
			
		||||
            fd_opts+=('--extension' "$EXT")
 | 
			
		||||
            fd_opts+=(--extension "$EXT")
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
@@ -129,7 +130,7 @@ while true; do
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
        '-F' | '--force-directory-delete')
 | 
			
		||||
            rm_force='--force'
 | 
			
		||||
            rm_opts+=(--recursive --force)
 | 
			
		||||
            shift
 | 
			
		||||
            continue
 | 
			
		||||
            ;;
 | 
			
		||||
@@ -167,8 +168,10 @@ while true; do
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# Interpret options
 | 
			
		||||
# If nothing was entered
 | 
			
		||||
if [[ -z "$*" ]]; then
 | 
			
		||||
    help
 | 
			
		||||
    exit 1
 | 
			
		||||
fi
 | 
			
		||||
 | 
			
		||||
declare -a files pattern_results
 | 
			
		||||
@@ -195,7 +198,7 @@ for p in "${paths[@]}"; do
 | 
			
		||||
done
 | 
			
		||||
 | 
			
		||||
# Padding between files and prompt
 | 
			
		||||
#color_output '' reset
 | 
			
		||||
color_output '' reset
 | 
			
		||||
 | 
			
		||||
read -r -n 1 -p 'Would you like to delete these files? [y/N]: ' user_response
 | 
			
		||||
# Padding between prompt and output
 | 
			
		||||
@@ -203,10 +206,6 @@ echo ''
 | 
			
		||||
 | 
			
		||||
if [[ "$user_response" =~ (y|Y) ]]; then
 | 
			
		||||
    for p in "${paths[@]}"; do
 | 
			
		||||
        if [[ -d "$p" ]]; then
 | 
			
		||||
            rm --recursive "$rm_force" --verbose -- "$p" || printf '%s %s\n' "$(color_output "Unable to remove path:" 'red')" "$(color_path "$p")"
 | 
			
		||||
        else
 | 
			
		||||
            rm "$rm_force" --verbose -- "$p" || printf '%s %s\n' "$(color_output "Unable to remove path:" 'red')" "$(color_path "$p")"
 | 
			
		||||
        fi
 | 
			
		||||
        rm "${rm_opts[@]}" -- "$p" || printf '%s %s\n' "$(color_output "Unable to remove path:" 'red')" "$(color_path "$p")"
 | 
			
		||||
    done
 | 
			
		||||
fi
 | 
			
		||||
 
 | 
			
		||||
		Reference in New Issue
	
	Block a user