Skip to content

Instantly share code, notes, and snippets.

@fpinzn
Last active August 29, 2015 14:01
Show Gist options
  • Save fpinzn/43e5fbd9b6fda672e471 to your computer and use it in GitHub Desktop.
Save fpinzn/43e5fbd9b6fda672e471 to your computer and use it in GitHub Desktop.
#!/bin/bash
set -eo pipefail
# This should be a cd to a env var with the root of the notes directory
nhome=~/versioned/Notes/nValt
file=".note.searching.$RANDOM"
#Search the files contents
pushd $nhome
ag "$@" > $nhome/$file
#Search the file names
ls | ag "$@" >> $nhome/$file
#Return the names of the files with occurences uniquely
notes=`awk -F ":" '{print $1}' $nhome/$file | uniq`
#Search again but this time use stdout
ag --color-path '35;55' --color-line-number '34;55' --color-match '36;8;4' "$@"
echo -e "\nMatching Filenames:"
ls | ag --color-path '35;55' --color-line-number '34;55' --color-match '36;8;4' "$@"
echo "----"
popd &> /dev/null
selection=`select-options $notes`
if [ -n "$selection" ]; then
vim $nhome/$file
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment