Convert config.sh to use blacklist instead of whilelist
This commit is contained in:
+59
-10
@@ -2,25 +2,74 @@
|
|||||||
|
|
||||||
# Script that searches config files and scripts
|
# Script that searches config files and scripts
|
||||||
|
|
||||||
# Define editor to open file in
|
# User-config---------------------------
|
||||||
EDITOR="$EDITOR"
|
|
||||||
|
# Define editor to open file in and if it should fork
|
||||||
|
EDITOR="emacsclient"
|
||||||
|
BACKGROUND="&"
|
||||||
|
|
||||||
|
# List of directories to exclude
|
||||||
|
EXCLUDES="
|
||||||
|
Code
|
||||||
|
Documents
|
||||||
|
dotfiles
|
||||||
|
Downloads
|
||||||
|
pictures
|
||||||
|
.cache
|
||||||
|
.clangd
|
||||||
|
.config/chromium
|
||||||
|
.config/ElectronChrome
|
||||||
|
.config/vim/pack/plugins
|
||||||
|
.electron-gyp
|
||||||
|
.emacs.d/elpa
|
||||||
|
.gradle
|
||||||
|
.jd
|
||||||
|
.local/share
|
||||||
|
.mozilla/firefox/rick.profile/storage
|
||||||
|
.node-gyp
|
||||||
|
.npm
|
||||||
|
.nvm
|
||||||
|
.wine
|
||||||
|
"
|
||||||
|
|
||||||
|
# List of files to include
|
||||||
|
INCLUDES="
|
||||||
|
dotfiles/dotfiles.sh
|
||||||
|
"
|
||||||
|
|
||||||
|
# --------------------------------------
|
||||||
|
|
||||||
|
# Execute relative to $HOME
|
||||||
|
cd "$HOME" || exit 1
|
||||||
|
|
||||||
|
# Generate exclude string to use with find
|
||||||
|
for EXCLUDE in $EXCLUDES; do
|
||||||
|
EXCLUDE_STRING="$EXCLUDE_STRING -path ./$EXCLUDE -o"
|
||||||
|
done
|
||||||
|
EXCLUDE_STRING=${EXCLUDE_STRING%???}
|
||||||
|
|
||||||
# List of locations to search
|
|
||||||
LOCATIONS="$HOME/.config $HOME/.scripts"
|
|
||||||
|
|
||||||
# Find the files
|
# Find the files
|
||||||
FILES="$(find -L $LOCATIONS -maxdepth 3 -type f | sort)"
|
FILES="$(find . \( $EXCLUDE_STRING \) -prune -o -printf '%P\n')"
|
||||||
HOME="$(find -L $HOME -maxdepth 1 -type f | sort)"
|
|
||||||
|
|
||||||
# If no name provided
|
# If no name provided
|
||||||
if [ -z "$1" ]; then
|
if [ -z "$1" ]; then
|
||||||
SELECTED="$(printf "%s\n%s" "$FILES" "$HOME" \
|
SELECTED="$(printf "%s\n%s" "$FILES" "$INCLUDES" \
|
||||||
| uniq | rofi -dmenu -p "Select file to edit")"
|
| uniq | rofi -dmenu -p "Select file to edit")"
|
||||||
|
|
||||||
# Else try to search for that file
|
# Else try to search for that file
|
||||||
else
|
else
|
||||||
SELECTED="$(printf "%s\n%s" "$FILES" "$HOME" | grep "$1" | head -n 1)"
|
SELECTED="$(printf "%s\n%s" "$FILES" "$INCLUDES" | grep "$1" | head -n 1)"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
# Start editor with selected file (if any)
|
# Exit if nothing selected
|
||||||
[ -n "$SELECTED" ] && $EDITOR "$SELECTED"
|
if [ -z "$SELECTED" ]; then
|
||||||
|
exit
|
||||||
|
fi
|
||||||
|
|
||||||
|
# Start editor with selected file
|
||||||
|
if [ -z "$BACKGROUND" ]; then
|
||||||
|
$EDITOR "$SELECTED"
|
||||||
|
else
|
||||||
|
$EDITOR "$SELECTED" > /dev/null 2>&1 &
|
||||||
|
fi
|
||||||
|
|||||||
Reference in New Issue
Block a user