#!/usr/bin/env bash # Cleanup set -e trap 'exit 1' SIGINT # Constants VERSION=2.0.0 template_dir="$HOME/Templates" fd_opts=(--type f --threads "$(nproc)") # Helper functions function help() { cat <&2 exit 1 ;; *) break ;; esac done # If no target specified if [[ -z "$1" ]]; then printf '%s\n' 'Please specify target name' exit 1 fi # Check if template directory exists if ! [[ -d "$template_dir" ]]; then printf '%s\n' "Template directory doesn't exist, exiting." exit 2 fi files="$("${fd_opts[@]}" "$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 elif [[ -f "$1" && -n "$FORCE_OVERWRITE" ]]; then cp --verbose --force -- "$selected_file" "$1" else cp --verbose -- "$selected_file" "$1" fi