Skip to content

Instantly share code, notes, and snippets.

@giftig
Created August 25, 2017 17:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save giftig/ebcd8ee643826a2e1abde0583f2137be to your computer and use it in GitHub Desktop.
Save giftig/ebcd8ee643826a2e1abde0583f2137be to your computer and use it in GitHub Desktop.
#!/bin/bash
QF_TYPE='files'
ACK_FLAGS='--scala --python'
while [[ "$1" != '' ]]; do
case "$1" in
-d|--def|--definition)
shift
QF_TYPE='def'
;;
-i|--import)
shift
QF_TYPE='import'
;;
-c|--class|--trait)
shift
QF_TYPE='class'
;;
-l)
shift
ACK_FLAGS="$ACK_FLAGS -l"
;;
-1)
shift
ACK_FLAGS="$ACK_FLAGS -1"
;;
-*)
echo "Unexpected flag $1" 2>&1
exit 1
;;
*)
if [[ "$ARG" != '' ]]; then
echo 'Only one argument is accepted' 2>&1
exit 2
fi
ARG="$1"
shift
;;
esac
done
quickfind_files() {
ack -g $ACK_FLAGS "^.*$1.*$"
}
quickfind_def() {
ack $ACK_FLAGS "def $1[\[\(: ]"
}
quickfind_class() {
ack $ACK_FLAGS '(class|trait|object|type) '"$1"'([\[\(\{ ]|$)'
}
quickfind_import() {
ack $ACK_FLAGS "import .*[\.\{, ]$1"'([\}, ]|$)'
}
"quickfind_$QF_TYPE" "$ARG"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment