#!/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 BOOT_DIR='/boot' ETC_DIR='/etc' # 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 # 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