Created
August 25, 2017 17:05
-
-
Save giftig/ebcd8ee643826a2e1abde0583f2137be to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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