Merging files-scripts and helper-scripts
This commit is contained in:
		
							
								
								
									
										50
									
								
								cptemplate.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										50
									
								
								cptemplate.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,50 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | # Copy a file from ~/Templates to a given name | ||||||
|  | # | ||||||
|  | # Dependencies: | ||||||
|  | #   - fd | ||||||
|  | #   - fzf | ||||||
|  |  | ||||||
|  | printHelp() { | ||||||
|  | cat << EOF | ||||||
|  | Usage: cptemplate [-h,--help] [options] [filename] | ||||||
|  |  | ||||||
|  | Options: | ||||||
|  |     -h, --help      print this help page | ||||||
|  | EOF | ||||||
|  | } | ||||||
|  |  | ||||||
|  | while true; do | ||||||
|  |     case "${1}" in | ||||||
|  |         '-h'|'--help') | ||||||
|  |             printHelp | ||||||
|  |             exit | ||||||
|  |             ;; | ||||||
|  |         --) | ||||||
|  |             shift | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |         -*) | ||||||
|  |             printf '%s\n' "Unknown option: ${1}" | ||||||
|  |             exit 1 | ||||||
|  |             ;; | ||||||
|  |         *) | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |     esac | ||||||
|  | done | ||||||
|  |  | ||||||
|  | declare -a find_opts | ||||||
|  | find_opts+=('.') | ||||||
|  | find_opts+=('-mindepth' '0') | ||||||
|  | find_opts+=('-type' 'f') | ||||||
|  | find_opts+=('-print0') | ||||||
|  |  | ||||||
|  | declare -a fd_opts | ||||||
|  | fd_opts+=('--print0') | ||||||
|  | fd_opts+=('--type' 'f') | ||||||
|  |  | ||||||
|  | template_file="$(fd "${fd_opts[@]}" . "${HOME}/Templates" | fzf --read0 --select-1 --exit-0 --no-mouse)" | ||||||
|  | [[ -z "${template_file}" ]] && exit 1 | ||||||
|  |  | ||||||
|  | cp --interactive --verbose "${template_file}" "./${1:-"${template_file}"}" | ||||||
							
								
								
									
										125
									
								
								edit.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										125
									
								
								edit.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,125 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | # edit - fuzzy find a file and edit it | ||||||
|  | # Dependencies | ||||||
|  | #  - fd | ||||||
|  | #  - fzf | ||||||
|  |  | ||||||
|  | printHelp() { | ||||||
|  | cat << EOF | ||||||
|  | Usage: edit [-h|--help] [-b|--boot] [-d|--dir directory] [-e|--etc] [-E|--editor editor]  | ||||||
|  | Options: | ||||||
|  |     -b, --boot      edit a file in /boot/loader | ||||||
|  |     -d, --dir       edit a file in a given directory | ||||||
|  |     -e, --etc       edit a file in /etc | ||||||
|  |     -E, --editor    use a given editor (default: ${EDITOR:-none}) | ||||||
|  |     -h, --help      print this help page | ||||||
|  | EOF | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # Error messages | ||||||
|  | readonly directory_error="Error, enter a directory" | ||||||
|  | readonly noeditor_error="Error, no editor entered" | ||||||
|  |  | ||||||
|  | # Pre-run correctness checks | ||||||
|  | unset fd_opts | ||||||
|  | ans= | ||||||
|  | file= | ||||||
|  | dir= | ||||||
|  | editor= | ||||||
|  |  | ||||||
|  | declare -a fd_opts | ||||||
|  | fd_opts+=('--hidden') | ||||||
|  | fd_opts+=('--type' 'f') | ||||||
|  | fd_opts+=('--print0') | ||||||
|  | fd_opts+=('--no-ignore-vcs') | ||||||
|  |  | ||||||
|  | while true; do | ||||||
|  |     case "${1}" in | ||||||
|  |         '-b'|'--boot') | ||||||
|  |             dir="/boot/loader" | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         '-d'|'--dir') | ||||||
|  |             case "${2}" in | ||||||
|  |                 "") | ||||||
|  |                     printf '%s\n' "${directory_error}" >&2 | ||||||
|  |                     exit 1 | ||||||
|  |                     ;; | ||||||
|  |                 *) | ||||||
|  |                     dir="${2}" | ||||||
|  |                     [[ ! -d "${dir}" ]] && printf '%s\n' "Not a directory: ${dir}" >&2 && exit 1 | ||||||
|  |                     ;; | ||||||
|  |             esac | ||||||
|  |             shift 2 | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         --dir=*) | ||||||
|  |             dir="${1#*=}" | ||||||
|  |             [[ -z "${dir}" ]] && printf '%s\n' "${directory_error}" >&2 && exit 1 | ||||||
|  |             [[ ! -d "${dir}" ]] && printf '%s\n' "Not a directory: ${dir}" >&2 && exit 1 | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         '-e'|'--etc') | ||||||
|  |             dir='/etc' | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         '-E'|'--editor') | ||||||
|  |             editor="${2}" | ||||||
|  |             case "${2}" in | ||||||
|  |                 "") | ||||||
|  |                     printf '%s\n' "${noeditor_error}" >&2 | ||||||
|  |                     exit 1 | ||||||
|  |                     ;; | ||||||
|  |                 -*) | ||||||
|  |                     printf '%s\n' "Not an editor: ${editor}" >&2 | ||||||
|  |                     exit 1 | ||||||
|  |                     ;; | ||||||
|  |             esac | ||||||
|  |             shift 2 | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         --editor=*) | ||||||
|  |             editor="${1#*=}" | ||||||
|  |             [[ -z "${editor}" ]] && printf '%s\n' "${noeditor_error}" >&2 && exit 1 | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         '-h'|'--help') | ||||||
|  |             printHelp | ||||||
|  |             exit | ||||||
|  |             ;; | ||||||
|  |         --) | ||||||
|  |             shift | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |         -*) | ||||||
|  |             printf '%s\n' "Unknown option: ${1}" | ||||||
|  |             exit 1 | ||||||
|  |             ;; | ||||||
|  |         *) | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |     esac | ||||||
|  | done | ||||||
|  |  | ||||||
|  | if [[ -z "${editor:-${EDITOR}}" ]]; then | ||||||
|  |     printf '%s\n' "No editor found" >&2 | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | if [[ "${dir}" ]]; then | ||||||
|  |     file="$(fd "${fd_opts[@]}" . -- "${dir}" | fzf --read0 --select-1 --exit-0 --no-mouse)" | ||||||
|  | else | ||||||
|  |     file="$(fd "${fd_opts[@]}" | fzf --read0 --select-1 --exit-0 --no-mouse)" | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | [[ ! "${file}" ]] && exit 1 | ||||||
|  |  | ||||||
|  | if [[ -w "${file}" ]]; then | ||||||
|  |     "${editor:-${EDITOR}}" -- "${file}" | ||||||
|  | else | ||||||
|  |     sudo --edit -- "${file}" | ||||||
|  | fi | ||||||
							
								
								
									
										76
									
								
								ef.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										76
									
								
								ef.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,76 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | # ef - fuzzy find a file and edit it | ||||||
|  | # | ||||||
|  | # Dependencies | ||||||
|  | #   - fzf | ||||||
|  | #   - mlocate | ||||||
|  |  | ||||||
|  | printHelp() { | ||||||
|  | cat << done | ||||||
|  | Usage: ef [-h|--help] [-E|--editor editor] [patterns] | ||||||
|  |  | ||||||
|  | Options: | ||||||
|  |     -h              print this help page | ||||||
|  |     -E, --editor    use a different editor (default: ${EDITOR:-none}) | ||||||
|  | done | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # Pre-run correctness checks | ||||||
|  | editor= | ||||||
|  | file= | ||||||
|  |  | ||||||
|  | while true; do | ||||||
|  |     case "${1}" in | ||||||
|  |         "-E"|"--editor") | ||||||
|  |             case "${2}" in | ||||||
|  |                 ""|-*) | ||||||
|  |                     printf '%s\n' "Not an editor or none entered" >&2 | ||||||
|  |                     exit 1 | ||||||
|  |                     ;; | ||||||
|  |                 *) | ||||||
|  |                     editor="${2}" | ||||||
|  |                     ;; | ||||||
|  |             esac | ||||||
|  |             shift 2 | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         --editor=*) | ||||||
|  |             editor="${1#*=}" | ||||||
|  |             [[ -z "${editor}" ]] && printf '%s\n' "Editor not entered" >&2 && exit 1 | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         "-h"|"--help") | ||||||
|  |             printHelp | ||||||
|  |             exit | ||||||
|  |             ;; | ||||||
|  |         --) | ||||||
|  |             shift | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |         -?) | ||||||
|  |             printf '%s\n' "Unknown option: ${1}" >&2 | ||||||
|  |             exit 1 | ||||||
|  |             ;; | ||||||
|  |         *) | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |     esac | ||||||
|  | done | ||||||
|  |  | ||||||
|  | if [[ -z "${editor:-${EDITOR}}" ]]; then | ||||||
|  |     printf '%s\n' "No editor found" >&2 | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | file="$(locate --all --ignore-case --null -- "${@}" | fzf --read0 --exit-0 --select-1 --no-mouse)" | ||||||
|  |  | ||||||
|  | if [[ -z "${file}" ]]; then | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | if [[ -w "${file}" ]]; then | ||||||
|  |     "${editor:-${EDITOR}}" -- "${file}" | ||||||
|  | else | ||||||
|  |     sudo --edit -- "${file}" | ||||||
|  | fi | ||||||
							
								
								
									
										86
									
								
								open.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										86
									
								
								open.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,86 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | # open - fuzzy find, select, and open a file using xdg-open | ||||||
|  | # | ||||||
|  | # Dependencies: | ||||||
|  | #   - fd | ||||||
|  | #   - fzf | ||||||
|  | #   - xdg-utils (xdg-open executable) | ||||||
|  |  | ||||||
|  | printHelp() { | ||||||
|  | cat << done | ||||||
|  | Fuzzy find and run xdg-open on a file | ||||||
|  |  | ||||||
|  | Usage: open [-h|--help] [-d|--dir directory] | ||||||
|  |  | ||||||
|  | Options: | ||||||
|  |     -d, --dir   select a directory to search in | ||||||
|  |     -h, --help  show this help page | ||||||
|  | done | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # Error messages | ||||||
|  | readonly nodir_error="Error: no directory given" | ||||||
|  |  | ||||||
|  | # Pre-run correctness checks | ||||||
|  | dir= | ||||||
|  | file= | ||||||
|  |  | ||||||
|  | while true; do | ||||||
|  |     case "${1}" in | ||||||
|  |         "-d"|"--dir") | ||||||
|  |             case "${2}" in | ||||||
|  |                 "") | ||||||
|  |                     printf '%s\n' "${nodir_error}" >&2 && exit 1 | ||||||
|  |                     ;; | ||||||
|  |                 *) | ||||||
|  |                     dir="${2}" | ||||||
|  |                     [[ ! -d "${dir}" ]] && printf '%s\n' "Error, not a directory: ${dir}" >&2 && exit 1 | ||||||
|  |                     ;; | ||||||
|  |             esac | ||||||
|  |             shift 2 | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         --dir=*) | ||||||
|  |             dir="${2#*=}" | ||||||
|  |             case "${dir}" in | ||||||
|  |                 "") | ||||||
|  |                     printf '%s\n' "${nodir_error}" >&2 | ||||||
|  |                     exit 1 | ||||||
|  |                     ;; | ||||||
|  |                 *) | ||||||
|  |                     [[ ! -d "${dir}" ]] && printf '%s\n' "Error, not a directory: ${dir}" >&2 | ||||||
|  |                     exit 1 | ||||||
|  |                     ;; | ||||||
|  |             esac | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         "-h"|"--help") | ||||||
|  |             printHelp | ||||||
|  |             exit | ||||||
|  |             ;; | ||||||
|  |         --) | ||||||
|  |             shift | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |         -*) | ||||||
|  |             printf '%s\n' "Error, unknown option: ${1}" >&2 | ||||||
|  |             exit 1 | ||||||
|  |             ;; | ||||||
|  |         *) | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |     esac | ||||||
|  | done | ||||||
|  |  | ||||||
|  | if [[ -n "${dir}" ]]; then | ||||||
|  |     file="$(fd --hidden --type f --print0 . -- "${dir}" | fzf --read0 --select-1 --exit-0 --no-mouse)" | ||||||
|  | else | ||||||
|  |     file="$(fd --hidden --type f --print0 | fzf --read0 --select-1 --exit-0 --no-mouse)" | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | if [[ -z "${file}" ]]; then | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
|  |  | ||||||
|  | xdg-open "${file}" | ||||||
							
								
								
									
										94
									
								
								quickdel.sh
									
									
									
									
									
										Executable file
									
								
							
							
						
						
									
										94
									
								
								quickdel.sh
									
									
									
									
									
										Executable file
									
								
							| @@ -0,0 +1,94 @@ | |||||||
|  | #!/usr/bin/env bash | ||||||
|  | # quickdel - delete any file matching a query | ||||||
|  | # | ||||||
|  | # Dependencies: | ||||||
|  | #   - fd | ||||||
|  |  | ||||||
|  | printHelp() { | ||||||
|  | cat << EOF | ||||||
|  | Fuzzy find and delete files matching patterns | ||||||
|  |  | ||||||
|  | Usage: quickdel [-h] [-i] [-I] [patterns] | ||||||
|  |  | ||||||
|  | Options: | ||||||
|  |     -d, --directories-only  only delete directories | ||||||
|  |     -h, --help              print this help page | ||||||
|  |     -i, --no-ignore         do not ignore .gitignore and .fdignore | ||||||
|  |     -I, --no--ignore-vcs    do not ignore .gitignore | ||||||
|  | EOF | ||||||
|  | } | ||||||
|  |  | ||||||
|  | # Pre-run correctness checks | ||||||
|  | unset files | ||||||
|  | unset fd_opts | ||||||
|  | ans= | ||||||
|  |  | ||||||
|  | declare -a files | ||||||
|  | declare -a fd_opts | ||||||
|  | declare -r blue='\033[0;34m' | ||||||
|  | declare -r nocolor='\033[0;0m' | ||||||
|  |  | ||||||
|  | while true; do | ||||||
|  |     case "${1}" in | ||||||
|  |         '-d'|'--directories-only') | ||||||
|  |             fd_opts+=('--type' 'd') | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         '-h'|'--help') | ||||||
|  |             printHelp | ||||||
|  |             exit | ||||||
|  |             ;; | ||||||
|  |         '-i'|'--no-ignore') | ||||||
|  |             fd_opts+=('--no-ignore') | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         '-I'|'--no-ignore-vcs') | ||||||
|  |             fd_opts+=('--no-ignore-vcs') | ||||||
|  |             shift | ||||||
|  |             continue | ||||||
|  |             ;; | ||||||
|  |         --) | ||||||
|  |             shift | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |         -*) | ||||||
|  |             printf '%s\n' "Unknown option: ${1}" >&2 | ||||||
|  |             exit 1 | ||||||
|  |             ;; | ||||||
|  |         *) | ||||||
|  |             break | ||||||
|  |             ;; | ||||||
|  |     esac | ||||||
|  | done | ||||||
|  |  | ||||||
|  | # Prevent fd from selecting everything | ||||||
|  | [[ -z "${*}" ]] && printf '%s\n' "No queries entered, cancelling" >&2 && exit 1 | ||||||
|  |  | ||||||
|  | for pattern in "${@}"; do | ||||||
|  |     while IFS= read -r -d '' file; do | ||||||
|  |         files+=("${file}") | ||||||
|  |     done < <(fd --hidden --print0 "${fd_opts[@]}" -- "${pattern}") | ||||||
|  | done | ||||||
|  |  | ||||||
|  | [[ -z "${files[*]}" ]] && printf '%s\n' "No results found" >&2 && exit 1 | ||||||
|  |  | ||||||
|  | # List all filenames, pretty print them | ||||||
|  | for filename in "${files[@]}"; do | ||||||
|  |     if [[ -f "${filename}" ]]; then | ||||||
|  |         printf '%s\n' "${filename}"  | ||||||
|  |     elif [[ -d "${filename}" ]]; then | ||||||
|  |         printf '%b%s%b\n' "${blue}" "${filename}" "${nocolor}"  | ||||||
|  |     fi | ||||||
|  | done | ||||||
|  |  | ||||||
|  | printf '%s' "Would you like to delete these files? " | ||||||
|  | read -r -n 1 ans | ||||||
|  |  | ||||||
|  | if [[ "${ans:-n}" =~ (Y|y) ]]; then | ||||||
|  |     rm --recursive --force -- "${files[@]}" | ||||||
|  | else | ||||||
|  |     printf '\n%s\n' "Operation cancelled" >&2 | ||||||
|  |     exit 1 | ||||||
|  | fi | ||||||
							
								
								
									
										12
									
								
								zsh-completions/_cptemplate
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										12
									
								
								zsh-completions/_cptemplate
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,12 @@ | |||||||
|  | #compdef cptemplate | ||||||
|  |  | ||||||
|  | # zsh completions for 'cptemplate' | ||||||
|  | # automatically generated with http://github.com/RobSis/zsh-completion-generator | ||||||
|  | local arguments | ||||||
|  |  | ||||||
|  | arguments=( | ||||||
|  |   {-h,--help}'[print this help page]' | ||||||
|  |   '*:filename:_files' | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | _arguments -s $arguments | ||||||
							
								
								
									
										13
									
								
								zsh-completions/_ddusb
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								zsh-completions/_ddusb
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | #compdef ddusb | ||||||
|  |  | ||||||
|  | # zsh completions for 'ddusb' | ||||||
|  | # automatically generated with http://github.com/RobSis/zsh-completion-generator | ||||||
|  | local arguments | ||||||
|  |  | ||||||
|  | arguments=( | ||||||
|  |   {-h,--help}'[show this help message and exit]' | ||||||
|  |   {-b,--bs}'[block size]' | ||||||
|  |   '*:filename:_files' | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | _arguments -s $arguments | ||||||
							
								
								
									
										13
									
								
								zsh-completions/_ef
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								zsh-completions/_ef
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | #compdef ef | ||||||
|  |  | ||||||
|  | # zsh completions for 'ef' | ||||||
|  | # automatically generated with http://github.com/RobSis/zsh-completion-generator | ||||||
|  | local arguments | ||||||
|  |  | ||||||
|  | arguments=( | ||||||
|  |   '-h[print this help page]' | ||||||
|  |   {-E,--editor}'[use a different editor (default: /usr/bin/nvim)]' | ||||||
|  |   '*:filename:_files' | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | _arguments -s $arguments | ||||||
							
								
								
									
										13
									
								
								zsh-completions/_open
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										13
									
								
								zsh-completions/_open
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,13 @@ | |||||||
|  | #compdef open | ||||||
|  |  | ||||||
|  | # zsh completions for 'open' | ||||||
|  | # automatically generated with http://github.com/RobSis/zsh-completion-generator | ||||||
|  | local arguments | ||||||
|  |  | ||||||
|  | arguments=( | ||||||
|  |   {-d,--dir}'[select a directory to search in]' | ||||||
|  |   {-h,--help}'[show this help page]' | ||||||
|  |   '*:filename:_files' | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | _arguments -s $arguments | ||||||
							
								
								
									
										15
									
								
								zsh-completions/_quickdel
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										15
									
								
								zsh-completions/_quickdel
									
									
									
									
									
										Normal file
									
								
							| @@ -0,0 +1,15 @@ | |||||||
|  | #compdef quickdel | ||||||
|  |  | ||||||
|  | # zsh completions for 'quickdel' | ||||||
|  | # automatically generated with http://github.com/RobSis/zsh-completion-generator | ||||||
|  | local arguments | ||||||
|  |  | ||||||
|  | arguments=( | ||||||
|  |   {-d,--directories-only}'[only delete directories]' | ||||||
|  |   {-h,--help}'[print this help page]' | ||||||
|  |   {-i,--no-ignore}'[do not ignore .gitignore and .fdignore]' | ||||||
|  |   {-I,--no-ignore-vcs}'[do not ignore .gitignore]' | ||||||
|  |   '*:filename:_files' | ||||||
|  | ) | ||||||
|  |  | ||||||
|  | _arguments -s $arguments | ||||||
		Reference in New Issue
	
	Block a user