From 652315267cb83923f2b366eda29172e22778d0a3 Mon Sep 17 00:00:00 2001 From: Eric Torres Date: Wed, 28 Sep 2022 21:27:04 -0700 Subject: [PATCH] Delete misc folder --- misc/bin/cptemplate.sh | 113 ----------------------------- misc/bin/fedit.sh | 131 --------------------------------- misc/bin/quickdel.sh | 161 ----------------------------------------- misc/fzf.sh | 7 -- misc/search.sh | 16 ---- misc/version.sh | 3 - 6 files changed, 431 deletions(-) delete mode 100755 misc/bin/cptemplate.sh delete mode 100755 misc/bin/fedit.sh delete mode 100755 misc/bin/quickdel.sh delete mode 100644 misc/fzf.sh delete mode 100644 misc/search.sh delete mode 100644 misc/version.sh diff --git a/misc/bin/cptemplate.sh b/misc/bin/cptemplate.sh deleted file mode 100755 index 88458e4..0000000 --- a/misc/bin/cptemplate.sh +++ /dev/null @@ -1,113 +0,0 @@ -#!/usr/bin/env bash - -# Cleanup -set -e -trap 'exit 1' SIGINT - -# Source library -LIBDIR="/usr/share/file-scripts/" - -for f in "$LIBDIR"/*.sh; do - source "${f}" -done - -DEFAULT_TEMPLATE_DIR="$HOME/Templates" - -# Helper functions -function help() { -cat << HELPMESSAGE -$(basename "$0") $MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION - -Usage: $(basename "$0") [-h] [-d DIR] [-f] dest - -Positional arguments: - dest - -options: - -h, --help show this help message and exit - -d DIR, --template-dir DIR - choose a template directory (default: ~/Templates) - -f, --force overwrite dest if it exists -HELPMESSAGE -} - -while true; do - case "${1}" in - '-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 - ;; - '-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 directory wasn't overridden -if [[ -z "$DIR" ]]; then - DIR="$DEFAULT_TEMPLATE_DIR" -fi - -# If no target specified -if [[ -z "$1" ]]; then - printf '%s\n' 'Please specify target name' - exit 1 -fi - -# Check if default template directory exists -if ! [[ -d "$DIR" ]]; then - printf '%s\n' "Template directory doesn't exist, exiting." - exit 2 -fi - -files="$(find_files "$DIR")" -selected_file="$(run_fzf "$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 diff --git a/misc/bin/fedit.sh b/misc/bin/fedit.sh deleted file mode 100755 index 4e50ac3..0000000 --- a/misc/bin/fedit.sh +++ /dev/null @@ -1,131 +0,0 @@ -#!/usr/bin/env bash - -# Cleanup -set -e -trap 'exit 1' SIGINT - -# Source library -#LIBDIR="/usr/share/file-scripts/" -LIBDIR="$HOME/Projects/file-scripts/misc/" - -for f in "$LIBDIR"/*.sh; do - source "${f}" -done - -BOOT_DIR='/boot' -ETC_DIR='/etc' - -# Helper functions -function help() { -cat << HELPMESSAGE -$(basename "$0") $MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION - -Usage: $(basename "$0") [-h|--help] [options] [patterns] - -Options - -h, --help show this help message and exit - -b, --boot edit a file in /boot - -d DIR, --dir DIR edit a file in a given directory - -E, --etc edit a file in /etc - -I, --no-ignore do not respect .(git|fd)ignore files - -i, --no-ignore-vcs do not respect .gitignore files - -Note that this script uses EDITOR to select an editor -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') - NO_IGNORE_VCS=1 - shift - continue - ;; - '-I'|'--no-ignore') - NO_IGNORE=1 - 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" -elif [[ -z $EDIT_BOOT && -n $EDIT_ETC ]]; then - DIR="$ETC_DIR" -elif [[ -n $EDIT_BOOT && -n $EDIT_ETC ]]; then - printf '%s\n' 'Select either --boot or --etc, not both' - exit 1 -elif [[ -z $DIR ]]; then - DIR='.' -fi - -# Handle extra options -declare -a extra_opts - -if [[ -n $NO_IGNORE ]]; then - extra_opts+=('--no-ignore') -elif [[ -n $NO_IGNORE_VCS ]]; then - extra_opts+=('--no-ignore-vcs') -fi - -files="$(find_files $DIR "${extra_opts[@]}")" -selected_file="$(run_fzf "$files")" - -if [[ -w "${selected_file}" ]]; then - "$EDITOR" "$selected_file" -else - sudo --edit "$selected_file" -fi diff --git a/misc/bin/quickdel.sh b/misc/bin/quickdel.sh deleted file mode 100755 index 1e99bb0..0000000 --- a/misc/bin/quickdel.sh +++ /dev/null @@ -1,161 +0,0 @@ -#!/usr/bin/env bash - -# Cleanup -set -e -trap 'exit 1' SIGINT - -# ========== Source library ========== -#LIBDIR="/usr/share/file-scripts/" -LIBDIR="$HOME/Projects/file-scripts/misc" - -for f in "$LIBDIR"/*.sh; do - source "${f}" -done - -# ========== Constants ========== -RED=$'\e[1;31m' -GREEN=$'\e[1;32m' -BLUE=$'\e[1;34m' -YELLOW=$'\e[1;33m' - -# ========== Helper functions ========== -function help() { -cat << HELPMESSAGE -$(basename "$0") $MAJOR_VERSION.$MINOR_VERSION.$PATCH_VERSION - -Usage: $(basename "$0") [-h] [-d] [-e] [-E ext] [-f] [-F] [-I] [-i] [-l] patterns [patterns ...] - -positional arguments: - patterns file matching patterns - -options: - -h, --help show this help message and exit - -d, --directories-only - filter results to directories - -e, --empty-only filter results to empty files and directories - -E ext, --extension ext - file extension - -f, --files-only filter results to files - -F, --force-directory-delete - do not ignore non-empty directories, delete anyways - -I, --no-ignore-vcs do not ignore .gitignore - -i, --no-ignore do not ignore .gitignore and .fdignore - -l, --links-only filter results to symlinks -HELPMESSAGE -} - -# $1 is the output string, $2 is the color -function color_output() { - case "$2" in - 'red') - printf "$RED%s\n" "$1" - ;; - 'green') - printf "$GREEN%s\n" "$1" - ;; - 'blue') - printf "$BLUE%s\n" "$1" - ;; - 'yellow') - printf "$YELLOW%s\n" "$1" - ;; - esac -} - -# Color files blue and directories green -function color_path() { - if [[ -f "$1" ]]; then - color_output "$1" 'blue' - elif [[ -f "$1" ]]; then - color_output "$1" 'green' - fi -} - -while true; do - case "${1}" in - '-d'|'--directories-only') - DIRECTORIES_ONLY=1 - shift - continue - ;; - '-e'|'--empty-only') - EMPTY_ONLY=1 - shift - continue - ;; - '-e'|'--extension') - EXT="${2}" - case "${EXT}" in - "") - exit 1 - ;; - -*) - exit 1 - ;; - esac - shift 2 - continue - ;; - --extension=*) - EXT="${1#*=}" - case "${EXT}" in - "") - exit 1 - ;; - -*) - exit 1 - ;; - esac - shift - continue - ;; - '-f'|'--files-only') - FILES_ONLY=1 - shift - continue - ;; - '-F'|'--force-directory-delete') - FORCE_DIR_DELETE=1 - shift - continue - ;; - '-i'|'--no-ignore-vcs') - NO_IGNORE_VCS=1 - shift - continue - ;; - '-I'|'--no-ignore') - NO_IGNORE=1 - shift - continue - ;; - '-l'|'--links-only') - FILTER_SYMLINKS=1 - shift - continue - ;; - '-h'|'--help') - help - exit - ;; - --) - shift - break - ;; - -*) - printf '%s\n' "Unknown option: ${1}" >&2 - exit 1 - ;; - *) - break - ;; - esac -done - -echo 'Script not implemented' -exit 1 - -#for pattern in "$@"; do -# files+= -# exit -#done diff --git a/misc/fzf.sh b/misc/fzf.sh deleted file mode 100644 index e7df94e..0000000 --- a/misc/fzf.sh +++ /dev/null @@ -1,7 +0,0 @@ -## FZF helpers - -FZF_OPTS=('--select-1' '--exit-0') - -run_fzf() { - fzf "${FZF_OPTS[@]}" -- <<< "$@" || return 2 -} diff --git a/misc/search.sh b/misc/search.sh deleted file mode 100644 index 93d5379..0000000 --- a/misc/search.sh +++ /dev/null @@ -1,16 +0,0 @@ -# Utility functions and helpers for searching -DEFAULT_FD_OPTS=('--hidden' '--type' 'f' '--type' 'l' '--threads' "$(nproc)") - -# Search and return a string with filenames delimited by \n -# Parameters: -# $1: directory -# $2-n: extra arguments -find_files() { - if [[ -d "$1" ]]; then - local directory="$1" - shift - fd "${DEFAULT_FD_OPTS[@]}" "$@" -- . "$directory" - else - fd "${DEFAULT_FD_OPTS[@]}" "$@" - fi -} diff --git a/misc/version.sh b/misc/version.sh deleted file mode 100644 index bb3e779..0000000 --- a/misc/version.sh +++ /dev/null @@ -1,3 +0,0 @@ -MAJOR_VERSION=1 -MINOR_VERSION=1 -PATCH_VERSION=3