You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
78 lines
1.4 KiB
78 lines
1.4 KiB
5 years ago
|
#!/bin/sh
|
||
|
|
||
|
# Script that searches config files and scripts
|
||
|
|
||
5 years ago
|
# User-config---------------------------
|
||
|
|
||
|
# Define editor to open file in and if it should fork
|
||
4 years ago
|
EDITOR="aliases emacs"
|
||
|
BACKGROUND=""
|
||
5 years ago
|
|
||
|
# List of directories to exclude
|
||
|
EXCLUDES="
|
||
5 years ago
|
code
|
||
|
documents
|
||
5 years ago
|
dotfiles
|
||
5 years ago
|
downloads
|
||
5 years ago
|
pictures
|
||
|
.cache
|
||
|
.clangd
|
||
|
.config/chromium
|
||
4 years ago
|
.config/emacs/elpa
|
||
5 years ago
|
.config/ElectronChrome
|
||
|
.config/vim/pack/plugins
|
||
|
.electron-gyp
|
||
|
.emacs.d/elpa
|
||
|
.gradle
|
||
|
.jd
|
||
|
.local/share
|
||
4 years ago
|
.mozilla/firefox/dotfiles.profile/storage
|
||
5 years ago
|
.node-gyp
|
||
|
.npm
|
||
|
.nvm
|
||
|
.wine
|
||
|
"
|
||
|
|
||
|
# List of files to include
|
||
|
INCLUDES="
|
||
5 years ago
|
documents/vm/backup/backup.sh
|
||
|
documents/vm/commands.org
|
||
5 years ago
|
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%???}
|
||
5 years ago
|
|
||
|
# Find the files
|
||
5 years ago
|
FILES="$( (find . \( $EXCLUDE_STRING \) -prune -o -type f -printf '%P\n'; echo "$INCLUDES") \
|
||
5 years ago
|
| grep -vx "" | sort)"
|
||
5 years ago
|
|
||
|
# If no name provided
|
||
|
if [ -z "$1" ]; then
|
||
5 years ago
|
SELECTED="$(printf "%s" "$FILES" | rofi -dmenu -p "Select file to edit")"
|
||
5 years ago
|
|
||
|
# Else try to search for that file
|
||
|
else
|
||
5 years ago
|
SELECTED="$(printf "%s" "$FILES" | grep "$1" | head -n 1)"
|
||
5 years ago
|
fi
|
||
|
|
||
|
# Exit if nothing selected
|
||
|
if [ -z "$SELECTED" ]; then
|
||
|
exit
|
||
5 years ago
|
fi
|
||
|
|
||
5 years ago
|
# Start editor with selected file
|
||
|
if [ -z "$BACKGROUND" ]; then
|
||
|
$EDITOR "$SELECTED"
|
||
|
else
|
||
|
$EDITOR "$SELECTED" > /dev/null 2>&1 &
|
||
|
fi
|