#!/usr/bin/env bash # Cleanup set -e trap 'exit 1' SIGINT # Constants VERSION=2.0.0 BOOT_DIR='/boot' ETC_DIR='/etc' fd_opts=(--hidden --type file --type symlink --threads "$(nproc)") # Helper functions function help() { cat <&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 files="$(find_files $DIR "${fd_opts[@]}")" selected_file="$(fzf --select-1 --exit-0 <<< "$files")" if [[ -w "${selected_file}" ]]; then "$EDITOR" "$selected_file" else sudo --edit "$selected_file" fi